1
+ import { h } from 'preact' ;
1
2
import {
2
- PluginBaseComponent ,
3
- PluginBaseProps ,
4
3
PluginManager ,
5
4
PluginPosition ,
6
5
PluginRenderer ,
7
6
} from '../../src/plugin' ;
8
- import { createContext , h } from 'preact' ;
9
7
import { mount } from 'enzyme' ;
10
- import { Config } from '../../src/config' ;
8
+ import { Config , ConfigContext } from '../../src/config' ;
9
+ import { useConfig } from '../../src/hooks/useConfig' ;
11
10
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
+ }
16
16
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!' ) ;
21
21
}
22
22
23
23
it ( 'should add and remove plugins' , ( ) => {
@@ -28,13 +28,13 @@ describe('Plugin', () => {
28
28
manager . add ( {
29
29
id : 'dummy' ,
30
30
position : PluginPosition . Header ,
31
- component : DummyPlugin . prototype ,
31
+ component : DummyPlugin ,
32
32
} ) ;
33
33
34
34
manager . add ( {
35
35
id : 'dummy2' ,
36
36
position : PluginPosition . Header ,
37
- component : DummyPlugin . prototype ,
37
+ component : DummyPlugin ,
38
38
} ) ;
39
39
40
40
expect ( manager . list ( ) ) . toHaveLength ( 2 ) ;
@@ -137,48 +137,48 @@ describe('Plugin', () => {
137
137
expect ( plugin . component ) . toBe ( component ) ;
138
138
expect ( plugin . position ) . toBe ( PluginPosition . Header ) ;
139
139
140
- expect ( manager . get ( 'doesnexist' ) ) . toBeNull ( ) ;
140
+ expect ( manager . get ( 'doesnexist' ) ) . toBeUndefined ( ) ;
141
141
} ) ;
142
142
143
143
it ( 'should render the plugins' , async ( ) => {
144
- const configContext = createContext ( null ) ;
145
- const config = Config . fromUserConfig ( {
144
+ const config = new Config ( ) . update ( {
146
145
data : [ [ 1 , 2 , 3 ] ] ,
147
- } ) ;
146
+ } ) as DummyConfig ;
147
+
148
+ config . dummy = {
149
+ text : 'dummyplugin' ,
150
+ } ;
148
151
149
152
config . plugin . add ( {
150
153
id : 'dummyheader' ,
151
154
position : PluginPosition . Header ,
152
155
component : DummyPlugin ,
153
- props : { text : 'dummyheader' } ,
154
156
} ) ;
155
157
156
158
config . plugin . add ( {
157
159
id : 'dummyfooter' ,
158
160
position : PluginPosition . Footer ,
159
161
component : DummyPlugin ,
160
- props : { text : 'dummyfooter' } ,
161
162
} ) ;
162
163
163
164
const renderer = mount (
164
- < configContext . Provider value = { config } >
165
+ < ConfigContext . Provider value = { config } >
165
166
< PluginRenderer position = { PluginPosition . Header } />
166
167
< PluginRenderer position = { PluginPosition . Footer } />
167
- </ configContext . Provider > ,
168
+ </ ConfigContext . Provider > ,
168
169
) ;
169
170
170
171
expect ( renderer . html ( ) ) . toMatchSnapshot ( ) ;
171
172
} ) ;
172
173
173
174
it ( 'should create a userConfig with custom plugin' , ( ) => {
174
- const config = Config . fromUserConfig ( {
175
+ const config = new Config ( ) . update ( {
175
176
data : [ [ 1 , 2 , 3 ] ] ,
176
177
plugins : [
177
178
{
178
179
id : 'dummyheader' ,
179
180
position : PluginPosition . Header ,
180
181
component : DummyPlugin ,
181
- props : { text : 'dummyheader' } ,
182
182
} ,
183
183
] ,
184
184
} ) ;
0 commit comments