mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-03-31 23:19:32 +01:00
[Query Copilot] Adding tests for the welcome modal (#1538)
This commit is contained in:
parent
3d5580865a
commit
676434cac5
@ -0,0 +1,122 @@
|
|||||||
|
import { Checkbox, ChoiceGroup, DefaultButton, IconButton, PrimaryButton, TextField } from "@fluentui/react";
|
||||||
|
import { QueryCopilotFeedbackModal } from "Explorer/QueryCopilot/Modal/QueryCopilotFeedbackModal";
|
||||||
|
import { submitFeedback } from "Explorer/QueryCopilot/QueryCopilotUtilities";
|
||||||
|
import { getUserEmail } from "Utils/UserUtils";
|
||||||
|
import { shallow } from "enzyme";
|
||||||
|
import { useQueryCopilot } from "hooks/useQueryCopilot";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
jest.mock("Utils/UserUtils");
|
||||||
|
(getUserEmail as jest.Mock).mockResolvedValue("test@email.com");
|
||||||
|
|
||||||
|
jest.mock("Explorer/QueryCopilot/QueryCopilotUtilities");
|
||||||
|
submitFeedback as jest.Mock;
|
||||||
|
|
||||||
|
describe("Query Copilot Feedback Modal snapshot test", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
it("shoud render and match snapshot", () => {
|
||||||
|
useQueryCopilot.getState().openFeedbackModal("test query", false, "test prompt");
|
||||||
|
|
||||||
|
const wrapper = shallow(<QueryCopilotFeedbackModal />);
|
||||||
|
|
||||||
|
expect(wrapper.props().isOpen).toBeTruthy();
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should close on cancel click", () => {
|
||||||
|
const wrapper = shallow(<QueryCopilotFeedbackModal />);
|
||||||
|
|
||||||
|
const cancelButton = wrapper.find(IconButton);
|
||||||
|
cancelButton.simulate("click");
|
||||||
|
wrapper.setProps({});
|
||||||
|
|
||||||
|
expect(wrapper.props().isOpen).toBeFalsy();
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should get user unput", () => {
|
||||||
|
const wrapper = shallow(<QueryCopilotFeedbackModal />);
|
||||||
|
const testUserInput = "test user input";
|
||||||
|
|
||||||
|
const userInput = wrapper.find(TextField).first();
|
||||||
|
userInput.simulate("change", {}, testUserInput);
|
||||||
|
|
||||||
|
expect(wrapper.find(TextField).first().props().value).toEqual(testUserInput);
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should record user contact choice no", () => {
|
||||||
|
const wrapper = shallow(<QueryCopilotFeedbackModal />);
|
||||||
|
const contactAllowed = wrapper.find(ChoiceGroup);
|
||||||
|
|
||||||
|
contactAllowed.simulate("change", {}, { key: "no" });
|
||||||
|
|
||||||
|
expect(getUserEmail).toHaveBeenCalledTimes(3);
|
||||||
|
expect(wrapper.find(ChoiceGroup).props().selectedKey).toEqual("no");
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should record user contact choice yes", () => {
|
||||||
|
const wrapper = shallow(<QueryCopilotFeedbackModal />);
|
||||||
|
const contactAllowed = wrapper.find(ChoiceGroup);
|
||||||
|
|
||||||
|
contactAllowed.simulate("change", {}, { key: "yes" });
|
||||||
|
|
||||||
|
expect(getUserEmail).toHaveBeenCalledTimes(4);
|
||||||
|
expect(wrapper.find(ChoiceGroup).props().selectedKey).toEqual("yes");
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not render dont show again button", () => {
|
||||||
|
const wrapper = shallow(<QueryCopilotFeedbackModal />);
|
||||||
|
|
||||||
|
const dontShowAgain = wrapper.find(Checkbox);
|
||||||
|
|
||||||
|
expect(dontShowAgain).toHaveLength(0);
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render dont show again button and check it ", () => {
|
||||||
|
useQueryCopilot.getState().openFeedbackModal("test query", true, "test prompt");
|
||||||
|
const wrapper = shallow(<QueryCopilotFeedbackModal />);
|
||||||
|
|
||||||
|
const dontShowAgain = wrapper.find(Checkbox);
|
||||||
|
dontShowAgain.simulate("change", {}, true);
|
||||||
|
|
||||||
|
expect(wrapper.find(Checkbox)).toHaveLength(1);
|
||||||
|
expect(wrapper.find(Checkbox).first().props().checked).toBeTruthy();
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should cancel submission", () => {
|
||||||
|
const wrapper = shallow(<QueryCopilotFeedbackModal />);
|
||||||
|
|
||||||
|
const cancelButton = wrapper.find(DefaultButton);
|
||||||
|
cancelButton.simulate("click");
|
||||||
|
wrapper.setProps({});
|
||||||
|
|
||||||
|
expect(wrapper.props().isOpen).toBeFalsy();
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should submit submission", () => {
|
||||||
|
const wrapper = shallow(<QueryCopilotFeedbackModal />);
|
||||||
|
|
||||||
|
const submitButton = wrapper.find(PrimaryButton);
|
||||||
|
submitButton.simulate("click");
|
||||||
|
wrapper.setProps({});
|
||||||
|
|
||||||
|
expect(submitFeedback).toHaveBeenCalledTimes(1);
|
||||||
|
expect(submitFeedback).toHaveBeenCalledWith({
|
||||||
|
likeQuery: false,
|
||||||
|
generatedQuery: "",
|
||||||
|
userPrompt: "",
|
||||||
|
description: "",
|
||||||
|
contact: getUserEmail(),
|
||||||
|
});
|
||||||
|
expect(wrapper.props().isOpen).toBeFalsy();
|
||||||
|
expect(wrapper).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
@ -13,7 +13,7 @@ import {
|
|||||||
import { submitFeedback } from "Explorer/QueryCopilot/QueryCopilotUtilities";
|
import { submitFeedback } from "Explorer/QueryCopilot/QueryCopilotUtilities";
|
||||||
import { useQueryCopilot } from "hooks/useQueryCopilot";
|
import { useQueryCopilot } from "hooks/useQueryCopilot";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { getUserEmail } from "../../Utils/UserUtils";
|
import { getUserEmail } from "../../../Utils/UserUtils";
|
||||||
|
|
||||||
export const QueryCopilotFeedbackModal: React.FC = (): JSX.Element => {
|
export const QueryCopilotFeedbackModal: React.FC = (): JSX.Element => {
|
||||||
const {
|
const {
|
||||||
@ -28,6 +28,7 @@ export const QueryCopilotFeedbackModal: React.FC = (): JSX.Element => {
|
|||||||
const [description, setDescription] = React.useState<string>("");
|
const [description, setDescription] = React.useState<string>("");
|
||||||
const [doNotShowAgainChecked, setDoNotShowAgainChecked] = React.useState<boolean>(false);
|
const [doNotShowAgainChecked, setDoNotShowAgainChecked] = React.useState<boolean>(false);
|
||||||
const [contact, setContact] = React.useState<string>(getUserEmail());
|
const [contact, setContact] = React.useState<string>(getUserEmail());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal isOpen={showFeedbackModal}>
|
<Modal isOpen={showFeedbackModal}>
|
||||||
<Stack style={{ padding: 24 }}>
|
<Stack style={{ padding: 24 }}>
|
@ -3,7 +3,7 @@ import { withHooks } from "jest-react-hooks-shallow";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { WelcomeModal } from "./WelcomeModal";
|
import { WelcomeModal } from "./WelcomeModal";
|
||||||
|
|
||||||
describe("Query Copilot Carousel snapshot test", () => {
|
describe("Query Copilot Welcome Modal snapshot test", () => {
|
||||||
it("should render when isOpen is true", () => {
|
it("should render when isOpen is true", () => {
|
||||||
withHooks(() => {
|
withHooks(() => {
|
||||||
const spy = jest.spyOn(localStorage, "setItem");
|
const spy = jest.spyOn(localStorage, "setItem");
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`Query Copilot Carousel snapshot test should render when isOpen is true 1`] = `
|
exports[`Query Copilot Welcome Modal snapshot test should render when isOpen is true 1`] = `
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Modal
|
<Modal
|
||||||
isBlocking={false}
|
isBlocking={false}
|
||||||
|
@ -17,7 +17,7 @@ import "../externals/jquery.typeahead.min.css";
|
|||||||
import "../externals/jquery.typeahead.min.js";
|
import "../externals/jquery.typeahead.min.js";
|
||||||
// Image Dependencies
|
// Image Dependencies
|
||||||
import { QueryCopilotCarousel } from "Explorer/QueryCopilot/CopilotCarousel";
|
import { QueryCopilotCarousel } from "Explorer/QueryCopilot/CopilotCarousel";
|
||||||
import { QueryCopilotFeedbackModal } from "Explorer/QueryCopilot/QueryCopilotFeedbackModal";
|
import { QueryCopilotFeedbackModal } from "Explorer/QueryCopilot/Modal/QueryCopilotFeedbackModal";
|
||||||
import { useQueryCopilot } from "hooks/useQueryCopilot";
|
import { useQueryCopilot } from "hooks/useQueryCopilot";
|
||||||
import "../images/CosmosDB_rgb_ui_lighttheme.ico";
|
import "../images/CosmosDB_rgb_ui_lighttheme.ico";
|
||||||
import hdeConnectImage from "../images/HdeConnectCosmosDB.svg";
|
import hdeConnectImage from "../images/HdeConnectCosmosDB.svg";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user