Skip to content

Commit a9c7dd4

Browse files
committed
chore: plugin manager tests
1 parent 24add15 commit a9c7dd4

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Plugin should render the plugins 1`] = `"<b>dummyheader</b><b>dummyfooter</b>"`;
3+
exports[`Plugin should render the plugins 1`] = `"<b>dummyplugin</b><b>dummyplugin</b>"`;

tests/jest/plugin.test.tsx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1+
import { h } from 'preact';
12
import {
2-
PluginBaseComponent,
3-
PluginBaseProps,
43
PluginManager,
54
PluginPosition,
65
PluginRenderer,
76
} from '../../src/plugin';
8-
import { createContext, h } from 'preact';
97
import { mount } from 'enzyme';
10-
import { Config } from '../../src/config';
8+
import { Config, ConfigContext } from '../../src/config';
9+
import { useConfig } from '../../src/hooks/useConfig';
1110

12-
describe('Plugin', () => {
13-
interface DummyPluginProps extends PluginBaseProps<DummyPlugin> {
14-
text?: string;
15-
}
11+
interface DummyConfig extends Config {
12+
dummy: {
13+
text: string;
14+
};
15+
}
1616

17-
class DummyPlugin extends PluginBaseComponent<DummyPluginProps> {
18-
render() {
19-
return h('b', {}, this.props.text || 'hello!');
20-
}
17+
describe('Plugin', () => {
18+
function DummyPlugin<T extends DummyConfig>() {
19+
const config = useConfig() as T;
20+
return h('b', {}, config.dummy.text || 'hello!');
2121
}
2222

2323
it('should add and remove plugins', () => {
@@ -28,13 +28,13 @@ describe('Plugin', () => {
2828
manager.add({
2929
id: 'dummy',
3030
position: PluginPosition.Header,
31-
component: DummyPlugin.prototype,
31+
component: DummyPlugin,
3232
});
3333

3434
manager.add({
3535
id: 'dummy2',
3636
position: PluginPosition.Header,
37-
component: DummyPlugin.prototype,
37+
component: DummyPlugin,
3838
});
3939

4040
expect(manager.list()).toHaveLength(2);
@@ -137,48 +137,48 @@ describe('Plugin', () => {
137137
expect(plugin.component).toBe(component);
138138
expect(plugin.position).toBe(PluginPosition.Header);
139139

140-
expect(manager.get('doesnexist')).toBeNull();
140+
expect(manager.get('doesnexist')).toBeUndefined();
141141
});
142142

143143
it('should render the plugins', async () => {
144-
const configContext = createContext(null);
145-
const config = Config.fromUserConfig({
144+
const config = new Config().update({
146145
data: [[1, 2, 3]],
147-
});
146+
}) as DummyConfig;
147+
148+
config.dummy = {
149+
text: 'dummyplugin',
150+
};
148151

149152
config.plugin.add({
150153
id: 'dummyheader',
151154
position: PluginPosition.Header,
152155
component: DummyPlugin,
153-
props: { text: 'dummyheader' },
154156
});
155157

156158
config.plugin.add({
157159
id: 'dummyfooter',
158160
position: PluginPosition.Footer,
159161
component: DummyPlugin,
160-
props: { text: 'dummyfooter' },
161162
});
162163

163164
const renderer = mount(
164-
<configContext.Provider value={config}>
165+
<ConfigContext.Provider value={config}>
165166
<PluginRenderer position={PluginPosition.Header} />
166167
<PluginRenderer position={PluginPosition.Footer} />
167-
</configContext.Provider>,
168+
</ConfigContext.Provider>,
168169
);
169170

170171
expect(renderer.html()).toMatchSnapshot();
171172
});
172173

173174
it('should create a userConfig with custom plugin', () => {
174-
const config = Config.fromUserConfig({
175+
const config = new Config().update({
175176
data: [[1, 2, 3]],
176177
plugins: [
177178
{
178179
id: 'dummyheader',
179180
position: PluginPosition.Header,
180181
component: DummyPlugin,
181-
props: { text: 'dummyheader' },
182182
},
183183
],
184184
});

0 commit comments

Comments
 (0)