mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-07 11:36:47 +00:00
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
import { shallow, ShallowWrapper } from "enzyme";
|
|
import React from "react";
|
|
import * as ViewModels from "../../../Contracts/ViewModels";
|
|
import Explorer from "../../Explorer";
|
|
import { NewVertexPanel } from "./NewVertexPanel";
|
|
|
|
describe("New Vertex Panel", () => {
|
|
let fakeExplorer: Explorer;
|
|
let wrapper: ShallowWrapper;
|
|
|
|
beforeEach(() => {
|
|
fakeExplorer = new Explorer();
|
|
});
|
|
|
|
it("should render default property", () => {
|
|
const props = {
|
|
explorer: fakeExplorer,
|
|
partitionKeyPropertyProp: "",
|
|
onSubmit: (): void => undefined,
|
|
openNotificationConsole: (): void => undefined,
|
|
};
|
|
wrapper = shallow(<NewVertexPanel {...props} />);
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
it("should render button in footer", () => {
|
|
const button = wrapper.find("PrimaryButton").first();
|
|
expect(button).toBeDefined();
|
|
});
|
|
|
|
it("should render form", () => {
|
|
const form = wrapper.find("form").first();
|
|
expect(form).toBeDefined();
|
|
});
|
|
|
|
it("should call form submit method", () => {
|
|
const onSubmitSpy = jest.fn();
|
|
|
|
const newWrapper = shallow(
|
|
<NewVertexPanel
|
|
explorer={fakeExplorer}
|
|
partitionKeyPropertyProp={undefined}
|
|
openNotificationConsole={(): void => undefined}
|
|
onSubmit={onSubmitSpy}
|
|
/>
|
|
);
|
|
//eslint-disable-next-line
|
|
newWrapper.find("form").simulate("submit", { preventDefault: () => {} });
|
|
|
|
expect(onSubmitSpy).toHaveBeenCalled();
|
|
});
|
|
|
|
it("should call error and success scenario method", () => {
|
|
const onSubmitSpy = jest.fn();
|
|
const onErrorSpy = jest.fn();
|
|
const onSuccessSpy = jest.fn();
|
|
const fakeNewVertexData: ViewModels.NewVertexData = {
|
|
label: "",
|
|
properties: [],
|
|
};
|
|
|
|
const result = onSubmitSpy(fakeNewVertexData, onErrorSpy, onSuccessSpy);
|
|
|
|
const newWrapper = shallow(
|
|
<NewVertexPanel
|
|
explorer={fakeExplorer}
|
|
partitionKeyPropertyProp={undefined}
|
|
openNotificationConsole={(): void => undefined}
|
|
onSubmit={onSubmitSpy}
|
|
/>
|
|
);
|
|
//eslint-disable-next-line
|
|
newWrapper.find("form").simulate("submit", { preventDefault: () => {} });
|
|
|
|
expect(result).toBeUndefined();
|
|
expect(onSubmitSpy).toHaveBeenCalledWith(fakeNewVertexData, onErrorSpy, onSuccessSpy);
|
|
});
|
|
});
|