-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrapper React Component replacing Banner.
Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net>
- Loading branch information
Mikhail Aheichyk
committed
Aug 18, 2023
1 parent
220c551
commit 743a391
Showing
9 changed files
with
626 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; | ||
testEnvironment: 'jsdom', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ComponentType, PropsWithChildren } from 'react'; | ||
|
||
/** | ||
* Wrapper lifecycle events | ||
*/ | ||
export enum WrapperLifecycle { | ||
/** | ||
* An event to request the wrapper. It is sent by Element to get the wrapper provided by the module if any. | ||
*/ | ||
Wrapper = 'wrapper' | ||
} | ||
|
||
/** | ||
* Opts object that is populated with a Wrapper. | ||
*/ | ||
export type WrapperOpts = { | ||
/** | ||
* A Wrapper React Component to be rendered around the Matrix Chat. | ||
*/ | ||
Wrapper: ComponentType<PropsWithChildren<{}>>; | ||
}; | ||
|
||
/** | ||
* Helper type that documents how to implement a wrapper listener. | ||
*/ | ||
export type WrapperListener = (opts: WrapperOpts) => void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2023 Mikhail Aheichyk | ||
Copyright 2023 Nordeck IT + Consulting GmbH. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { RuntimeModule } from '../../src/RuntimeModule'; | ||
import { WrapperLifecycle, WrapperListener, WrapperOpts } from '../../src/lifecycles/WrapperLifecycle'; | ||
|
||
describe('WrapperLifecycle', () => { | ||
let module: RuntimeModule; | ||
|
||
beforeAll(() => { | ||
module = new class extends RuntimeModule { | ||
constructor() { | ||
super(undefined as any); | ||
|
||
this.on(WrapperLifecycle.Wrapper, this.wrapperListener); | ||
} | ||
|
||
protected wrapperListener: WrapperListener = (wrapperOpts: WrapperOpts) => { | ||
wrapperOpts.Wrapper = ({ children }) => { | ||
return <><div>Header</div>{children}<div>Footer</div></>; | ||
}; | ||
}; | ||
}; | ||
}); | ||
|
||
it('should wrap a matrix client with header and footer', () => { | ||
const opts: WrapperOpts = { Wrapper: React.Fragment }; | ||
module.emit(WrapperLifecycle.Wrapper, opts); | ||
|
||
render(<opts.Wrapper><span>MatrixChat</span></opts.Wrapper>); | ||
screen.getByText(/Header/i); | ||
screen.getByText(/MatrixChat/i); | ||
screen.getByText(/Footer/i); | ||
}); | ||
}); | ||
|
Oops, something went wrong.