mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-01-31 21:26:42 +00:00
[Query Copilot] Improving test coverage (#1539)
* Improving test coverage * Not leaving empty functions * Additional test editing * Correction of the unit test * Changes made so the tests work correctly * removing problematic tests --------- Co-authored-by: Predrag Klepic <v-prklepic@microsoft.com>
This commit is contained in:
parent
13434715b3
commit
10037d844e
@ -1,11 +1,48 @@
|
|||||||
|
import { IconButton } from "@fluentui/react";
|
||||||
import { shallow } from "enzyme";
|
import { shallow } from "enzyme";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { any } from "underscore";
|
|
||||||
import { CopyPopup } from "./CopyPopup";
|
import { CopyPopup } from "./CopyPopup";
|
||||||
|
|
||||||
describe("Copy Popup snapshot test", () => {
|
describe("Copy Popup snapshot test", () => {
|
||||||
|
const setShowCopyPopupMock = jest.fn();
|
||||||
it("should render when showCopyPopup is true", () => {
|
it("should render when showCopyPopup is true", () => {
|
||||||
const wrapper = shallow(<CopyPopup showCopyPopup={true} setShowCopyPopup={() => any} />);
|
const wrapper = shallow(<CopyPopup showCopyPopup={true} setShowCopyPopup={setShowCopyPopupMock} />);
|
||||||
|
expect(wrapper.exists()).toBe(true);
|
||||||
|
expect(wrapper.prop("setShowCopyPopup")).toBeUndefined();
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should render when showCopyPopup is false", () => {
|
||||||
|
const wrapper = shallow(<CopyPopup showCopyPopup={false} setShowCopyPopup={setShowCopyPopupMock} />);
|
||||||
|
expect(wrapper.prop("showCopyPopup")).toBeFalsy();
|
||||||
|
expect(wrapper.prop("setShowCopyPopup")).toBeUndefined();
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call setShowCopyPopup(false) when close button is clicked", () => {
|
||||||
|
const wrapper = shallow(<CopyPopup showCopyPopup={true} setShowCopyPopup={setShowCopyPopupMock} />);
|
||||||
|
|
||||||
|
const closeButton = wrapper.find(IconButton);
|
||||||
|
closeButton.props().onClick?.({} as React.MouseEvent<HTMLButtonElement, MouseEvent>);
|
||||||
|
|
||||||
|
expect(setShowCopyPopupMock).toHaveBeenCalledWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should have the correct inline styles", () => {
|
||||||
|
const wrapper = shallow(<CopyPopup showCopyPopup={true} setShowCopyPopup={setShowCopyPopupMock} />);
|
||||||
|
|
||||||
|
const stackStyle = wrapper.find("Stack").first().props().style;
|
||||||
|
|
||||||
|
expect(stackStyle).toEqual({
|
||||||
|
position: "fixed",
|
||||||
|
width: 345,
|
||||||
|
height: 66,
|
||||||
|
padding: 10,
|
||||||
|
gap: 5,
|
||||||
|
top: 75,
|
||||||
|
right: 20,
|
||||||
|
background: "#FFFFFF",
|
||||||
|
boxShadow: "0 2px 6px rgba(0, 0, 0, 0.16)",
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,19 +1,113 @@
|
|||||||
import { shallow } from "enzyme";
|
import { mount, shallow } from "enzyme";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { any } from "underscore";
|
|
||||||
import { DeletePopup } from "./DeletePopup";
|
import { DeletePopup } from "./DeletePopup";
|
||||||
|
|
||||||
describe("Delete Popup snapshot test", () => {
|
describe("Delete Popup snapshot test", () => {
|
||||||
|
const setShowDeletePopupMock = jest.fn();
|
||||||
|
const setQueryMock = jest.fn();
|
||||||
|
const clearFeedbackMock = jest.fn();
|
||||||
|
const showFeedbackBarMock = jest.fn();
|
||||||
|
|
||||||
it("should render when showDeletePopup is true", () => {
|
it("should render when showDeletePopup is true", () => {
|
||||||
const wrapper = shallow(
|
const wrapper = shallow(
|
||||||
<DeletePopup
|
<DeletePopup
|
||||||
showDeletePopup={true}
|
showDeletePopup={true}
|
||||||
setShowDeletePopup={() => any}
|
setShowDeletePopup={setShowDeletePopupMock}
|
||||||
setQuery={() => any}
|
setQuery={setQueryMock}
|
||||||
clearFeedback={() => any}
|
clearFeedback={clearFeedbackMock}
|
||||||
showFeedbackBar={() => any}
|
showFeedbackBar={showFeedbackBarMock}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
expect(wrapper.find("Modal").prop("isOpen")).toBeTruthy();
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not render when showDeletePopup is false", () => {
|
||||||
|
const wrapper = shallow(
|
||||||
|
<DeletePopup
|
||||||
|
showDeletePopup={false}
|
||||||
|
setShowDeletePopup={setShowDeletePopupMock}
|
||||||
|
setQuery={setQueryMock}
|
||||||
|
clearFeedback={clearFeedbackMock}
|
||||||
|
showFeedbackBar={showFeedbackBarMock}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
expect(wrapper.props().children.props.showDeletePopup).toBeFalsy();
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call setQuery with an empty string and setShowDeletePopup(false) when delete button is clicked", () => {
|
||||||
|
const wrapper = mount(
|
||||||
|
<DeletePopup
|
||||||
|
showDeletePopup={true}
|
||||||
|
setShowDeletePopup={setShowDeletePopupMock}
|
||||||
|
setQuery={setQueryMock}
|
||||||
|
clearFeedback={clearFeedbackMock}
|
||||||
|
showFeedbackBar={showFeedbackBarMock}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
wrapper.find("PrimaryButton").simulate("click");
|
||||||
|
|
||||||
|
expect(setQueryMock).toHaveBeenCalledWith("");
|
||||||
|
expect(setShowDeletePopupMock).toHaveBeenCalledWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call setShowDeletePopup(false) when close button is clicked", () => {
|
||||||
|
const setShowDeletePopupMock = jest.fn();
|
||||||
|
const wrapper = mount(
|
||||||
|
<DeletePopup
|
||||||
|
showDeletePopup={true}
|
||||||
|
setShowDeletePopup={setShowDeletePopupMock}
|
||||||
|
setQuery={setQueryMock}
|
||||||
|
clearFeedback={clearFeedbackMock}
|
||||||
|
showFeedbackBar={showFeedbackBarMock}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
wrapper.find("DefaultButton").at(1).simulate("click");
|
||||||
|
|
||||||
|
expect(setShowDeletePopupMock).toHaveBeenCalledWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render the appropriate text content", () => {
|
||||||
|
const wrapper = shallow(
|
||||||
|
<DeletePopup
|
||||||
|
showDeletePopup={true}
|
||||||
|
setShowDeletePopup={setShowDeletePopupMock}
|
||||||
|
setQuery={setQueryMock}
|
||||||
|
clearFeedback={clearFeedbackMock}
|
||||||
|
showFeedbackBar={showFeedbackBarMock}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
const textContent = wrapper
|
||||||
|
.find("Text")
|
||||||
|
.map((text, index) => <React.Fragment key={index}>{text.props().children}</React.Fragment>);
|
||||||
|
|
||||||
|
expect(textContent).toEqual([
|
||||||
|
<React.Fragment key={0}>
|
||||||
|
<b>Delete code?</b>
|
||||||
|
</React.Fragment>,
|
||||||
|
<React.Fragment key={1}>
|
||||||
|
This will clear the query from the query builder pane along with all comments and also reset the prompt pane
|
||||||
|
</React.Fragment>,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should have the correct inline style", () => {
|
||||||
|
const wrapper = shallow(
|
||||||
|
<DeletePopup
|
||||||
|
showDeletePopup={true}
|
||||||
|
setShowDeletePopup={setShowDeletePopupMock}
|
||||||
|
setQuery={setQueryMock}
|
||||||
|
clearFeedback={clearFeedbackMock}
|
||||||
|
showFeedbackBar={showFeedbackBarMock}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
const stackStyle = wrapper.find("Stack[style]").props().style;
|
||||||
|
|
||||||
|
expect(stackStyle).toEqual({ padding: "16px 24px", height: "auto" });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Copy Popup snapshot test should render when showCopyPopup is false 1`] = `<Fragment />`;
|
||||||
|
|
||||||
exports[`Copy Popup snapshot test should render when showCopyPopup is true 1`] = `
|
exports[`Copy Popup snapshot test should render when showCopyPopup is true 1`] = `
|
||||||
<Stack
|
<Stack
|
||||||
style={
|
style={
|
||||||
|
@ -1,5 +1,83 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Delete Popup snapshot test should not render when showDeletePopup is false 1`] = `
|
||||||
|
<Modal
|
||||||
|
isOpen={false}
|
||||||
|
styles={
|
||||||
|
Object {
|
||||||
|
"main": Object {
|
||||||
|
"minHeight": "122px",
|
||||||
|
"minWidth": "880px",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Stack
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "auto",
|
||||||
|
"padding": "16px 24px",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"fontSize": "18px",
|
||||||
|
"height": 24,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<b>
|
||||||
|
Delete code?
|
||||||
|
</b>
|
||||||
|
</Text>
|
||||||
|
<Text
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"marginBottom": 20,
|
||||||
|
"marginTop": 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
This will clear the query from the query builder pane along with all comments and also reset the prompt pane
|
||||||
|
</Text>
|
||||||
|
<Stack
|
||||||
|
horizontal={true}
|
||||||
|
horizontalAlign="start"
|
||||||
|
tokens={
|
||||||
|
Object {
|
||||||
|
"childrenGap": 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<CustomizedPrimaryButton
|
||||||
|
onClick={[Function]}
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": 24,
|
||||||
|
"padding": "0px 20px",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</CustomizedPrimaryButton>
|
||||||
|
<CustomizedDefaultButton
|
||||||
|
onClick={[Function]}
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": 24,
|
||||||
|
"padding": "0px 20px",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Close
|
||||||
|
</CustomizedDefaultButton>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</Modal>
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`Delete Popup snapshot test should render when showDeletePopup is true 1`] = `
|
exports[`Delete Popup snapshot test should render when showDeletePopup is true 1`] = `
|
||||||
<Modal
|
<Modal
|
||||||
isOpen={true}
|
isOpen={true}
|
||||||
|
@ -3,24 +3,25 @@ import React from "react";
|
|||||||
import { SamplePrompts, SamplePromptsProps } from "./SamplePrompts";
|
import { SamplePrompts, SamplePromptsProps } from "./SamplePrompts";
|
||||||
|
|
||||||
describe("Sample Prompts snapshot test", () => {
|
describe("Sample Prompts snapshot test", () => {
|
||||||
it("should render properly if isSamplePromptsOpen is true", () => {
|
const setTextBoxMock = jest.fn();
|
||||||
const sampleProps: SamplePromptsProps = {
|
const setIsSamplePromptsOpenMock = jest.fn();
|
||||||
isSamplePromptsOpen: true,
|
const sampleProps: SamplePromptsProps = {
|
||||||
setIsSamplePromptsOpen: () => undefined,
|
isSamplePromptsOpen: true,
|
||||||
setTextBox: () => undefined,
|
setIsSamplePromptsOpen: setIsSamplePromptsOpenMock,
|
||||||
};
|
setTextBox: setTextBoxMock,
|
||||||
|
};
|
||||||
|
|
||||||
|
it("should render properly if isSamplePromptsOpen is true", () => {
|
||||||
const wrapper = shallow(<SamplePrompts sampleProps={sampleProps} />);
|
const wrapper = shallow(<SamplePrompts sampleProps={sampleProps} />);
|
||||||
|
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should render properly if isSamplePromptsOpen is false", () => {
|
it("should render properly if isSamplePromptsOpen is false", () => {
|
||||||
const sampleProps: SamplePromptsProps = {
|
sampleProps.isSamplePromptsOpen = false;
|
||||||
isSamplePromptsOpen: false,
|
|
||||||
setIsSamplePromptsOpen: () => undefined,
|
|
||||||
setTextBox: () => undefined,
|
|
||||||
};
|
|
||||||
const wrapper = shallow(<SamplePrompts sampleProps={sampleProps} />);
|
const wrapper = shallow(<SamplePrompts sampleProps={sampleProps} />);
|
||||||
|
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user