mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-25 11:51:07 +00:00
47 lines
2.1 KiB
TypeScript
47 lines
2.1 KiB
TypeScript
import { shallow } from "enzyme";
|
|
import React from "react";
|
|
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 };
|
|
});
|
|
|
|
it("renders only the source component when materializedViewDefinition is missing", () => {
|
|
testCollection.materializedViews([
|
|
{ id: "view1", _rid: "rid1" },
|
|
{ id: "view2", _rid: "rid2" },
|
|
]);
|
|
testCollection.materializedViewDefinition(null);
|
|
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} explorer={testExplorer} />);
|
|
expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(true);
|
|
expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(false);
|
|
});
|
|
|
|
it("renders only the target component when materializedViews is missing", () => {
|
|
testCollection.materializedViews(null);
|
|
testCollection.materializedViewDefinition({
|
|
definition: "SELECT * FROM c WHERE c.id = 1",
|
|
sourceCollectionId: "source1",
|
|
sourceCollectionRid: "rid123",
|
|
});
|
|
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} explorer={testExplorer} />);
|
|
expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(false);
|
|
expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(true);
|
|
});
|
|
|
|
it("renders neither component when both are missing", () => {
|
|
testCollection.materializedViews(null);
|
|
testCollection.materializedViewDefinition(null);
|
|
const wrapper = shallow(<MaterializedViewComponent collection={testCollection} explorer={testExplorer} />);
|
|
expect(wrapper.find(MaterializedViewSourceComponent).exists()).toBe(false);
|
|
expect(wrapper.find(MaterializedViewTargetComponent).exists()).toBe(false);
|
|
});
|
|
});
|