From 7812ca49144fe7e48fe0cc780550c3927552a915 Mon Sep 17 00:00:00 2001 From: Nishtha Ahuja <45535788+nishthaAhujaa@users.noreply.github.com> Date: Mon, 17 Mar 2025 22:45:51 +0530 Subject: [PATCH] updated tests (#2077) Co-authored-by: nishthaAhujaa --- .../MaterializedViewComponent.test.tsx | 9 +++--- .../MaterializedViewSourceComponent.test.tsx | 29 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewComponent.test.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewComponent.test.tsx index 861761d21..9cddd2ab9 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewComponent.test.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewComponent.test.tsx @@ -1,12 +1,13 @@ import { shallow } from "enzyme"; import React from "react"; -import { collection } from "../TestUtils"; +import { collection, container } from "../TestUtils"; import { MaterializedViewComponent } from "./MaterializedViewComponent"; import { MaterializedViewSourceComponent } from "./MaterializedViewSourceComponent"; import { MaterializedViewTargetComponent } from "./MaterializedViewTargetComponent"; describe("MaterializedViewComponent", () => { let testCollection: typeof collection; + let testExplorer: typeof container; beforeEach(() => { testCollection = { ...collection }; @@ -18,7 +19,7 @@ describe("MaterializedViewComponent", () => { { id: "view2", _rid: "rid2" }, ]); testCollection.materializedViewDefinition(null); - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(true); expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(false); }); @@ -30,7 +31,7 @@ describe("MaterializedViewComponent", () => { sourceCollectionId: "source1", sourceCollectionRid: "rid123", }); - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(false); expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(true); }); @@ -38,7 +39,7 @@ describe("MaterializedViewComponent", () => { it("renders neither component when both are missing", () => { testCollection.materializedViews(null); testCollection.materializedViewDefinition(null); - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(false); expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(false); }); diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewSourceComponent.test.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewSourceComponent.test.tsx index ac8dda2c2..96b27e78b 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewSourceComponent.test.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/MaterializedViewSourceComponent.test.tsx @@ -1,37 +1,34 @@ import { PrimaryButton } from "@fluentui/react"; import { shallow } from "enzyme"; import React from "react"; -import { collection } from "../TestUtils"; -import { - MaterializedViewSourceComponent, - MaterializedViewSourceComponentProps, -} from "./MaterializedViewSourceComponent"; +import { collection, container } from "../TestUtils"; +import { MaterializedViewSourceComponent } from "./MaterializedViewSourceComponent"; describe("MaterializedViewSourceComponent", () => { - const baseProps: MaterializedViewSourceComponentProps = { - collection: { - ...collection, - materializedViews: jest.fn(() => collection.materializedViews()), - }, - }; + let testCollection: typeof collection; + let testExplorer: typeof container; + + beforeEach(() => { + testCollection = { ...collection }; + }); it("renders without crashing", () => { - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.exists()).toBe(true); }); it("renders the PrimaryButton", () => { - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.find(PrimaryButton).exists()).toBe(true); }); it("updates when new materialized views are provided", () => { - const wrapper = shallow(); + const wrapper = shallow(); // Simulating an update by modifying the observable directly - collection.materializedViews([{ id: "view3", _rid: "rid3" }]); + testCollection.materializedViews([{ id: "view3", _rid: "rid3" }]); - wrapper.setProps({ collection: { ...collection } }); + wrapper.setProps({ collection: testCollection }); wrapper.update(); expect(wrapper.find(PrimaryButton).exists()).toBe(true);