Skip to content

Commit 7812ca4

Browse files
updated tests (#2077)
Co-authored-by: nishthaAhujaa
1 parent bc4f18b commit 7812ca4

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewComponent.test.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { shallow } from "enzyme";
22
import React from "react";
3-
import { collection } from "../TestUtils";
3+
import { collection, container } from "../TestUtils";
44
import { MaterializedViewComponent } from "./MaterializedViewComponent";
55
import { MaterializedViewSourceComponent } from "./MaterializedViewSourceComponent";
66
import { MaterializedViewTargetComponent } from "./MaterializedViewTargetComponent";
77

88
describe("MaterializedViewComponent", () => {
99
let testCollection: typeof collection;
10+
let testExplorer: typeof container;
1011

1112
beforeEach(() => {
1213
testCollection = { ...collection };
@@ -18,7 +19,7 @@ describe("MaterializedViewComponent", () => {
1819
{ id: "view2", _rid: "rid2" },
1920
]);
2021
testCollection.materializedViewDefinition(null);
21-
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} />);
22+
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} explorer={testExplorer} />);
2223
expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(true);
2324
expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(false);
2425
});
@@ -30,15 +31,15 @@ describe("MaterializedViewComponent", () => {
3031
sourceCollectionId: "source1",
3132
sourceCollectionRid: "rid123",
3233
});
33-
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} />);
34+
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} explorer={testExplorer} />);
3435
expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(false);
3536
expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(true);
3637
});
3738

3839
it("renders neither component when both are missing", () => {
3940
testCollection.materializedViews(null);
4041
testCollection.materializedViewDefinition(null);
41-
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} />);
42+
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} explorer={testExplorer} />);
4243
expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(false);
4344
expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(false);
4445
});

src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewSourceComponent.test.tsx

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
11
import { PrimaryButton } from "@fluentui/react";
22
import { shallow } from "enzyme";
33
import React from "react";
4-
import { collection } from "../TestUtils";
5-
import {
6-
MaterializedViewSourceComponent,
7-
MaterializedViewSourceComponentProps,
8-
} from "./MaterializedViewSourceComponent";
4+
import { collection, container } from "../TestUtils";
5+
import { MaterializedViewSourceComponent } from "./MaterializedViewSourceComponent";
96

107
describe("MaterializedViewSourceComponent", () => {
11-
const baseProps: MaterializedViewSourceComponentProps = {
12-
collection: {
13-
...collection,
14-
materializedViews: jest.fn(() => collection.materializedViews()),
15-
},
16-
};
8+
let testCollection: typeof collection;
9+
let testExplorer: typeof container;
10+
11+
beforeEach(() => {
12+
testCollection = { ...collection };
13+
});
1714

1815
it("renders without crashing", () => {
19-
const wrapper = shallow(<MaterializedViewSourceComponent {...baseProps} />);
16+
const wrapper = shallow(<MaterializedViewSourceComponent collection={testCollection} explorer={testExplorer} />);
2017
expect(wrapper.exists()).toBe(true);
2118
});
2219

2320
it("renders the PrimaryButton", () => {
24-
const wrapper = shallow(<MaterializedViewSourceComponent {...baseProps} />);
21+
const wrapper = shallow(<MaterializedViewSourceComponent collection={testCollection} explorer={testExplorer} />);
2522
expect(wrapper.find(PrimaryButton).exists()).toBe(true);
2623
});
2724

2825
it("updates when new materialized views are provided", () => {
29-
const wrapper = shallow(<MaterializedViewSourceComponent {...baseProps} />);
26+
const wrapper = shallow(<MaterializedViewSourceComponent collection={testCollection} explorer={testExplorer} />);
3027

3128
// Simulating an update by modifying the observable directly
32-
collection.materializedViews([{ id: "view3", _rid: "rid3" }]);
29+
testCollection.materializedViews([{ id: "view3", _rid: "rid3" }]);
3330

34-
wrapper.setProps({ collection: { ...collection } });
31+
wrapper.setProps({ collection: testCollection });
3532
wrapper.update();
3633

3734
expect(wrapper.find(PrimaryButton).exists()).toBe(true);

0 commit comments

Comments
 (0)