Skip to content

Commit bcee8d3

Browse files
test(widget-plugin-grid): fix tests to follow more real world scenario using host
1 parent 4b539e4 commit bcee8d3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/shared/widget-plugin-grid/src/__tests__/DatasourceController.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
import { BaseControllerHost } from "@mendix/widget-plugin-mobx-kit/BaseControllerHost";
12
import { GateProvider } from "@mendix/widget-plugin-mobx-kit/GateProvider";
2-
import { ReactiveControllerHost } from "@mendix/widget-plugin-mobx-kit/main";
3+
// import { ReactiveControllerHost } from "@mendix/widget-plugin-mobx-kit/main";
34
import { list } from "@mendix/widget-plugin-test-utils";
45
import { ListValue } from "mendix";
56
import { DatasourceController } from "../query/DatasourceController";
67

8+
class TestControllerHost extends BaseControllerHost {}
9+
710
describe("DatasourceController loading states", () => {
811
let controller: DatasourceController;
912
let datasource: ListValue;
1013
let provider: GateProvider<{ datasource: ListValue }>;
1114

1215
beforeEach(() => {
13-
const host = { addController: jest.fn() } as unknown as ReactiveControllerHost;
16+
const host = new TestControllerHost();
1417
provider = new GateProvider({ datasource: list.loading() });
18+
host.setup();
1519
controller = new DatasourceController(host, { gate: provider.gate });
1620
});
1721

@@ -34,12 +38,13 @@ describe("DatasourceController loading states", () => {
3438
it("isRefreshing is true after refresh call", () => {
3539
provider.setProps({ datasource: list(0) });
3640
expect(provider.gate.props.datasource.status).toBe("available");
41+
controller.setup();
3742
controller.refresh();
3843
expect(controller.isRefreshing).toBe(true);
3944
provider.setProps({ datasource: list.loading() });
4045
expect(provider.gate.props.datasource.status).toBe("loading");
4146
expect(controller.isRefreshing).toBe(true);
42-
expect(controller.isFirstLoad).toBe(true);
47+
expect(controller.isFirstLoad).toBe(false);
4348
});
4449

4550
it("isFetchingNextBatch returns true after setLimit call", () => {
@@ -55,7 +60,7 @@ describe("DatasourceController loading states", () => {
5560
provider.setProps({ datasource });
5661
});
5762

58-
it("all loading states return false", () => {
63+
it("isFirstLoad returns true and loading states return false", () => {
5964
expect(controller.isFirstLoad).toBe(true);
6065
expect(controller.isRefreshing).toBe(false);
6166
expect(controller.isFetchingNextBatch).toBe(false);

0 commit comments

Comments
 (0)