mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-06 11:11:23 +00:00
@@ -1,12 +1,13 @@
|
|||||||
import { shallow } from "enzyme";
|
import { shallow } from "enzyme";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { collection } from "../TestUtils";
|
import { collection, container } from "../TestUtils";
|
||||||
import { MaterializedViewComponent } from "./MaterializedViewComponent";
|
import { MaterializedViewComponent } from "./MaterializedViewComponent";
|
||||||
import { MaterializedViewSourceComponent } from "./MaterializedViewSourceComponent";
|
import { MaterializedViewSourceComponent } from "./MaterializedViewSourceComponent";
|
||||||
import { MaterializedViewTargetComponent } from "./MaterializedViewTargetComponent";
|
import { MaterializedViewTargetComponent } from "./MaterializedViewTargetComponent";
|
||||||
|
|
||||||
describe("MaterializedViewComponent", () => {
|
describe("MaterializedViewComponent", () => {
|
||||||
let testCollection: typeof collection;
|
let testCollection: typeof collection;
|
||||||
|
let testExplorer: typeof container;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
testCollection = { ...collection };
|
testCollection = { ...collection };
|
||||||
@@ -18,7 +19,7 @@ describe("MaterializedViewComponent", () => {
|
|||||||
{ id: "view2", _rid: "rid2" },
|
{ id: "view2", _rid: "rid2" },
|
||||||
]);
|
]);
|
||||||
testCollection.materializedViewDefinition(null);
|
testCollection.materializedViewDefinition(null);
|
||||||
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} />);
|
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} explorer={testExplorer} />);
|
||||||
expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(true);
|
expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(true);
|
||||||
expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(false);
|
expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(false);
|
||||||
});
|
});
|
||||||
@@ -30,7 +31,7 @@ describe("MaterializedViewComponent", () => {
|
|||||||
sourceCollectionId: "source1",
|
sourceCollectionId: "source1",
|
||||||
sourceCollectionRid: "rid123",
|
sourceCollectionRid: "rid123",
|
||||||
});
|
});
|
||||||
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} />);
|
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} explorer={testExplorer} />);
|
||||||
expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(false);
|
expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(false);
|
||||||
expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(true);
|
expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -38,7 +39,7 @@ describe("MaterializedViewComponent", () => {
|
|||||||
it("renders neither component when both are missing", () => {
|
it("renders neither component when both are missing", () => {
|
||||||
testCollection.materializedViews(null);
|
testCollection.materializedViews(null);
|
||||||
testCollection.materializedViewDefinition(null);
|
testCollection.materializedViewDefinition(null);
|
||||||
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} />);
|
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} explorer={testExplorer} />);
|
||||||
expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(false);
|
expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(false);
|
||||||
expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(false);
|
expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,37 +1,34 @@
|
|||||||
import { PrimaryButton } from "@fluentui/react";
|
import { PrimaryButton } from "@fluentui/react";
|
||||||
import { shallow } from "enzyme";
|
import { shallow } from "enzyme";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { collection } from "../TestUtils";
|
import { collection, container } from "../TestUtils";
|
||||||
import {
|
import { MaterializedViewSourceComponent } from "./MaterializedViewSourceComponent";
|
||||||
MaterializedViewSourceComponent,
|
|
||||||
MaterializedViewSourceComponentProps,
|
|
||||||
} from "./MaterializedViewSourceComponent";
|
|
||||||
|
|
||||||
describe("MaterializedViewSourceComponent", () => {
|
describe("MaterializedViewSourceComponent", () => {
|
||||||
const baseProps: MaterializedViewSourceComponentProps = {
|
let testCollection: typeof collection;
|
||||||
collection: {
|
let testExplorer: typeof container;
|
||||||
...collection,
|
|
||||||
materializedViews: jest.fn(() => collection.materializedViews()),
|
beforeEach(() => {
|
||||||
},
|
testCollection = { ...collection };
|
||||||
};
|
});
|
||||||
|
|
||||||
it("renders without crashing", () => {
|
it("renders without crashing", () => {
|
||||||
const wrapper = shallow(<MaterializedViewSourceComponent {...baseProps} />);
|
const wrapper = shallow(<MaterializedViewSourceComponent collection={testCollection} explorer={testExplorer} />);
|
||||||
expect(wrapper.exists()).toBe(true);
|
expect(wrapper.exists()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders the PrimaryButton", () => {
|
it("renders the PrimaryButton", () => {
|
||||||
const wrapper = shallow(<MaterializedViewSourceComponent {...baseProps} />);
|
const wrapper = shallow(<MaterializedViewSourceComponent collection={testCollection} explorer={testExplorer} />);
|
||||||
expect(wrapper.find(PrimaryButton).exists()).toBe(true);
|
expect(wrapper.find(PrimaryButton).exists()).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("updates when new materialized views are provided", () => {
|
it("updates when new materialized views are provided", () => {
|
||||||
const wrapper = shallow(<MaterializedViewSourceComponent {...baseProps} />);
|
const wrapper = shallow(<MaterializedViewSourceComponent collection={testCollection} explorer={testExplorer} />);
|
||||||
|
|
||||||
// Simulating an update by modifying the observable directly
|
// 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();
|
wrapper.update();
|
||||||
|
|
||||||
expect(wrapper.find(PrimaryButton).exists()).toBe(true);
|
expect(wrapper.find(PrimaryButton).exists()).toBe(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user