Skip to content

Commit 49623dd

Browse files
iobuhovgjulivan
authored andcommitted
fix: update types
1 parent 08c32d7 commit 49623dd

File tree

2 files changed

+78
-75
lines changed

2 files changed

+78
-75
lines changed

packages/pluggableWidgets/datagrid-number-filter-web/src/components/__tests__/DatagridNumberFilter.spec.tsx

Lines changed: 77 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import "@testing-library/jest-dom";
2-
import { FilterAPIv2 } from "@mendix/widget-plugin-filtering/context";
2+
import { FilterAPI } from "@mendix/widget-plugin-filtering/context";
33
import { requirePlugin } from "@mendix/widget-plugin-external-events/plugin";
44
import {
55
HeaderFiltersStore,
6-
HeaderFiltersStoreProps
6+
HeaderFiltersStoreSpec
77
} from "@mendix/widget-plugin-filtering/stores/generic/HeaderFiltersStore";
88
import {
99
actionValue,
@@ -20,11 +20,7 @@ import DatagridNumberFilter from "../../DatagridNumberFilter";
2020
import { Big } from "big.js";
2121
import { DatagridNumberFilterContainerProps } from "../../../typings/DatagridNumberFilterProps";
2222
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";
2824

2925
const commonProps: DatagridNumberFilterContainerProps = {
3026
class: "filter-custom-class",
@@ -36,13 +32,17 @@ const commonProps: DatagridNumberFilterContainerProps = {
3632
delay: 1000
3733
};
3834

39-
const headerFilterStoreInfo: StaticInfo = {
40-
name: commonProps.name,
41-
filtersChannelName: "datagrid1"
42-
};
43-
4435
jest.useFakeTimers();
4536

37+
const mockSpec = (spec: Partial<HeaderFiltersStoreSpec>): HeaderFiltersStoreSpec => ({
38+
filterList: [],
39+
filterChannelName: "datagrid1",
40+
headerInitFilter: [],
41+
sharedInitFilter: [],
42+
customFilterHost: {} as FilterObserver,
43+
...spec
44+
});
45+
4646
beforeEach(() => {
4747
jest.spyOn(console, "warn").mockImplementation(() => {
4848
// noop
@@ -60,23 +60,23 @@ describe("Number Filter", () => {
6060

6161
describe("with single attribute", () => {
6262
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>(
8080
headerFilterStore.context
8181
);
8282
});
@@ -194,39 +194,40 @@ describe("Number Filter", () => {
194194

195195
describe("with multiple attributes", () => {
196196
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>(
230231
headerFilterStore.context
231232
);
232233
});
@@ -296,13 +297,14 @@ describe("Number Filter", () => {
296297

297298
describe("with wrong attribute's type", () => {
298299
beforeAll(() => {
299-
const props: HeaderFiltersStoreProps = {
300+
const spec = mockSpec({
300301
filterList: [
301302
{ filter: new ListAttributeValueBuilder().withType("Boolean").withFilterable(true).build() }
302303
]
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>(
306308
headerFilterStore.context
307309
);
308310
});
@@ -320,7 +322,7 @@ describe("Number Filter", () => {
320322

321323
describe("with wrong multiple attributes' types", () => {
322324
beforeAll(() => {
323-
const props: HeaderFiltersStoreProps = {
325+
const spec = mockSpec({
324326
filterList: [
325327
{
326328
filter: new ListAttributeValueBuilder()
@@ -337,9 +339,10 @@ describe("Number Filter", () => {
337339
.build()
338340
}
339341
]
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>(
343346
headerFilterStore.context
344347
);
345348
});
@@ -370,7 +373,7 @@ describe("Number Filter", () => {
370373

371374
describe("with multiple instances", () => {
372375
beforeEach(() => {
373-
const props: HeaderFiltersStoreProps = {
376+
const spec = mockSpec({
374377
filterList: [
375378
{
376379
filter: new ListAttributeValueBuilder()
@@ -385,9 +388,9 @@ describe("Number Filter", () => {
385388
.build()
386389
}
387390
]
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>(
391394
headerFilterStore.context
392395
);
393396
});

packages/pluggableWidgets/datagrid-number-filter-web/src/hocs/withNumberFilterAPI.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function withNumberFilterAPI<P extends object>(
66
Component: (props: P & Number_FilterAPIv2) => React.ReactElement
77
): (props: P) => React.ReactElement {
88
return function FilterAPIProvider(props) {
9-
const api = useNumberFilterAPI("");
9+
const api = useNumberFilterAPI();
1010

1111
if (api.hasError) {
1212
return <Alert bootstrapStyle="danger">{api.error.message}</Alert>;

0 commit comments

Comments
 (0)