1
1
import "@testing-library/jest-dom" ;
2
- import { FilterAPIv2 } from "@mendix/widget-plugin-filtering/context" ;
2
+ import { FilterAPI } from "@mendix/widget-plugin-filtering/context" ;
3
3
import { requirePlugin } from "@mendix/widget-plugin-external-events/plugin" ;
4
4
import {
5
5
HeaderFiltersStore ,
6
- HeaderFiltersStoreProps
6
+ HeaderFiltersStoreSpec
7
7
} from "@mendix/widget-plugin-filtering/stores/generic/HeaderFiltersStore" ;
8
8
import {
9
9
actionValue ,
@@ -20,11 +20,7 @@ import DatagridNumberFilter from "../../DatagridNumberFilter";
20
20
import { Big } from "big.js" ;
21
21
import { DatagridNumberFilterContainerProps } from "../../../typings/DatagridNumberFilterProps" ;
22
22
import { resetIdCounter } from "downshift" ;
23
-
24
- interface StaticInfo {
25
- name : string ;
26
- filtersChannelName : string ;
27
- }
23
+ import { FilterObserver } from "@mendix/widget-plugin-filtering/typings/FilterObserver" ;
28
24
29
25
const commonProps : DatagridNumberFilterContainerProps = {
30
26
class : "filter-custom-class" ,
@@ -36,13 +32,17 @@ const commonProps: DatagridNumberFilterContainerProps = {
36
32
delay : 1000
37
33
} ;
38
34
39
- const headerFilterStoreInfo : StaticInfo = {
40
- name : commonProps . name ,
41
- filtersChannelName : "datagrid1"
42
- } ;
43
-
44
35
jest . useFakeTimers ( ) ;
45
36
37
+ const mockSpec = ( spec : Partial < HeaderFiltersStoreSpec > ) : HeaderFiltersStoreSpec => ( {
38
+ filterList : [ ] ,
39
+ filterChannelName : "datagrid1" ,
40
+ headerInitFilter : [ ] ,
41
+ sharedInitFilter : [ ] ,
42
+ customFilterHost : { } as FilterObserver ,
43
+ ...spec
44
+ } ) ;
45
+
46
46
beforeEach ( ( ) => {
47
47
jest . spyOn ( console , "warn" ) . mockImplementation ( ( ) => {
48
48
// noop
@@ -60,23 +60,23 @@ describe("Number Filter", () => {
60
60
61
61
describe ( "with single attribute" , ( ) => {
62
62
beforeEach ( ( ) => {
63
- const props : HeaderFiltersStoreProps = {
64
- filterList : [
65
- {
66
- filter : new ListAttributeValueBuilder ( )
67
- . withType ( "Long" )
68
- . withFormatter (
69
- value => ( value ? value . toString ( ) : "" ) ,
70
- ( value : string ) => ( { valid : true , value } )
71
- )
72
- . withFilterable ( true )
73
- . build ( )
74
- }
75
- ] ,
76
- parentChannelName : headerFilterStoreInfo . filtersChannelName
77
- } ;
78
- const headerFilterStore = new HeaderFiltersStore ( props , headerFilterStoreInfo , null ) ;
79
- ( window as any ) [ "com.mendix.widgets.web.filterable.filterContext.v2" ] = createContext < FilterAPIv2 > (
63
+ const headerFilterStore = new HeaderFiltersStore (
64
+ mockSpec ( {
65
+ filterList : [
66
+ {
67
+ filter : new ListAttributeValueBuilder ( )
68
+ . withType ( "Long" )
69
+ . withFormatter (
70
+ value => ( value ? value . toString ( ) : "" ) ,
71
+ ( value : string ) => ( { valid : true , value } )
72
+ )
73
+ . withFilterable ( true )
74
+ . build ( )
75
+ }
76
+ ]
77
+ } )
78
+ ) ;
79
+ ( window as any ) [ "com.mendix.widgets.web.filterable.filterContext.v2" ] = createContext < FilterAPI > (
80
80
headerFilterStore . context
81
81
) ;
82
82
} ) ;
@@ -194,39 +194,40 @@ describe("Number Filter", () => {
194
194
195
195
describe ( "with multiple attributes" , ( ) => {
196
196
beforeEach ( ( ) => {
197
- const props : HeaderFiltersStoreProps = {
198
- filterList : [
199
- {
200
- filter : new ListAttributeValueBuilder ( )
201
- . withId ( "attribute1" )
202
- . withType ( "Long" )
203
- . withFormatter (
204
- value => value ,
205
- ( ) => {
206
- // noop
207
- }
208
- )
209
- . withFilterable ( true )
210
- . build ( )
211
- } ,
212
- {
213
- filter : new ListAttributeValueBuilder ( )
214
- . withId ( "attribute2" )
215
- . withType ( "Decimal" )
216
- . withFormatter (
217
- value => value ,
218
- ( ) => {
219
- // noop
220
- }
221
- )
222
- . withFilterable ( true )
223
- . build ( )
224
- }
225
- ] ,
226
- parentChannelName : headerFilterStoreInfo . filtersChannelName
227
- } ;
228
- const headerFilterStore = new HeaderFiltersStore ( props , headerFilterStoreInfo , null ) ;
229
- ( window as any ) [ "com.mendix.widgets.web.filterable.filterContext.v2" ] = createContext < FilterAPIv2 > (
197
+ const headerFilterStore = new HeaderFiltersStore (
198
+ mockSpec ( {
199
+ filterList : [
200
+ {
201
+ filter : new ListAttributeValueBuilder ( )
202
+ . withId ( "attribute1" )
203
+ . withType ( "Long" )
204
+ . withFormatter (
205
+ value => value ,
206
+ ( ) => {
207
+ // noop
208
+ }
209
+ )
210
+ . withFilterable ( true )
211
+ . build ( )
212
+ } ,
213
+ {
214
+ filter : new ListAttributeValueBuilder ( )
215
+ . withId ( "attribute2" )
216
+ . withType ( "Decimal" )
217
+ . withFormatter (
218
+ value => value ,
219
+ ( ) => {
220
+ // noop
221
+ }
222
+ )
223
+ . withFilterable ( true )
224
+ . build ( )
225
+ }
226
+ ]
227
+ } )
228
+ ) ;
229
+
230
+ ( window as any ) [ "com.mendix.widgets.web.filterable.filterContext.v2" ] = createContext < FilterAPI > (
230
231
headerFilterStore . context
231
232
) ;
232
233
} ) ;
@@ -296,13 +297,14 @@ describe("Number Filter", () => {
296
297
297
298
describe ( "with wrong attribute's type" , ( ) => {
298
299
beforeAll ( ( ) => {
299
- const props : HeaderFiltersStoreProps = {
300
+ const spec = mockSpec ( {
300
301
filterList : [
301
302
{ filter : new ListAttributeValueBuilder ( ) . withType ( "Boolean" ) . withFilterable ( true ) . build ( ) }
302
303
]
303
- } ;
304
- const headerFilterStore = new HeaderFiltersStore ( props , headerFilterStoreInfo , null ) ;
305
- ( window as any ) [ "com.mendix.widgets.web.filterable.filterContext.v2" ] = createContext < FilterAPIv2 > (
304
+ } ) ;
305
+
306
+ const headerFilterStore = new HeaderFiltersStore ( spec ) ;
307
+ ( window as any ) [ "com.mendix.widgets.web.filterable.filterContext.v2" ] = createContext < FilterAPI > (
306
308
headerFilterStore . context
307
309
) ;
308
310
} ) ;
@@ -320,7 +322,7 @@ describe("Number Filter", () => {
320
322
321
323
describe ( "with wrong multiple attributes' types" , ( ) => {
322
324
beforeAll ( ( ) => {
323
- const props : HeaderFiltersStoreProps = {
325
+ const spec = mockSpec ( {
324
326
filterList : [
325
327
{
326
328
filter : new ListAttributeValueBuilder ( )
@@ -337,9 +339,10 @@ describe("Number Filter", () => {
337
339
. build ( )
338
340
}
339
341
]
340
- } ;
341
- const headerFilterStore = new HeaderFiltersStore ( props , headerFilterStoreInfo , null ) ;
342
- ( window as any ) [ "com.mendix.widgets.web.filterable.filterContext.v2" ] = createContext < FilterAPIv2 > (
342
+ } ) ;
343
+
344
+ const headerFilterStore = new HeaderFiltersStore ( spec ) ;
345
+ ( window as any ) [ "com.mendix.widgets.web.filterable.filterContext.v2" ] = createContext < FilterAPI > (
343
346
headerFilterStore . context
344
347
) ;
345
348
} ) ;
@@ -370,7 +373,7 @@ describe("Number Filter", () => {
370
373
371
374
describe ( "with multiple instances" , ( ) => {
372
375
beforeEach ( ( ) => {
373
- const props : HeaderFiltersStoreProps = {
376
+ const spec = mockSpec ( {
374
377
filterList : [
375
378
{
376
379
filter : new ListAttributeValueBuilder ( )
@@ -385,9 +388,9 @@ describe("Number Filter", () => {
385
388
. build ( )
386
389
}
387
390
]
388
- } ;
389
- const headerFilterStore = new HeaderFiltersStore ( props , headerFilterStoreInfo , null ) ;
390
- ( window as any ) [ "com.mendix.widgets.web.filterable.filterContext.v2" ] = createContext < FilterAPIv2 > (
391
+ } ) ;
392
+ const headerFilterStore = new HeaderFiltersStore ( spec ) ;
393
+ ( window as any ) [ "com.mendix.widgets.web.filterable.filterContext.v2" ] = createContext < FilterAPI > (
391
394
headerFilterStore . context
392
395
) ;
393
396
} ) ;
0 commit comments