From 19100ec437315f3520b0c33cb2799d7856e763dc Mon Sep 17 00:00:00 2001 From: v-darkora <134300273+v-darkora@users.noreply.github.com> Date: Mon, 21 Aug 2023 16:29:00 +0200 Subject: [PATCH] [Query Copilot V2] Unit tests for V2 Copilot (#1580) * Add tests for V2 of copilot and fix query parameter feature flag * Fix merge changes --- .../V2/Bubbles/Sample/SampleBubble.test.tsx | 18 +- .../__snapshots__/SampleBubble.test.tsx.snap | 50 ++- .../QueryCopilot/V2/Footer/Footer.test.tsx | 76 +++- .../Footer/__snapshots__/Footer.test.tsx.snap | 417 +++++++++++++++++- .../QueryCopilot/V2/Header/Header.test.tsx | 9 +- .../Header/__snapshots__/Header.test.tsx.snap | 2 +- .../V2/Modal/WelcomeSidebarModal.test.tsx | 30 +- .../V2/Modal/WelcomeSidebarModal.tsx | 179 ++++---- .../WelcomeSidebarModal.test.tsx.snap | 244 +--------- .../V2/Sidebar/QueryCopilotSidebar.test.tsx | 48 +- .../V2/Sidebar/QueryCopilotSidebar.tsx | 61 ++- .../QueryCopilotSidebar.test.tsx.snap | 127 +++++- src/Platform/Hosted/extractFeatures.ts | 2 +- 13 files changed, 886 insertions(+), 377 deletions(-) diff --git a/src/Explorer/QueryCopilot/V2/Bubbles/Sample/SampleBubble.test.tsx b/src/Explorer/QueryCopilot/V2/Bubbles/Sample/SampleBubble.test.tsx index f32c152c2..976b612fe 100644 --- a/src/Explorer/QueryCopilot/V2/Bubbles/Sample/SampleBubble.test.tsx +++ b/src/Explorer/QueryCopilot/V2/Bubbles/Sample/SampleBubble.test.tsx @@ -1,10 +1,26 @@ +import { Text } from "@fluentui/react"; import { shallow } from "enzyme"; +import { useQueryCopilot } from "hooks/useQueryCopilot"; import React from "react"; import { SampleBubble } from "./SampleBubble"; describe("Sample Bubble snapshot test", () => { - it("should render ", () => { + it("should render", () => { const wrapper = shallow(); + + const sampleInputs = wrapper.find(Text); + + expect(sampleInputs.length).toEqual(2); + expect(useQueryCopilot.getState().userPrompt).toEqual(""); + expect(wrapper).toMatchSnapshot(); + }); + it("should render and be clicked", () => { + const wrapper = shallow(); + + const firstSampleInput = wrapper.find(Text).first(); + firstSampleInput.simulate("click", {}, ""); + + expect(useQueryCopilot.getState().userPrompt).toEqual(expect.any(String)); expect(wrapper).toMatchSnapshot(); }); }); diff --git a/src/Explorer/QueryCopilot/V2/Bubbles/Sample/__snapshots__/SampleBubble.test.tsx.snap b/src/Explorer/QueryCopilot/V2/Bubbles/Sample/__snapshots__/SampleBubble.test.tsx.snap index be3917fc4..fafd0c638 100644 --- a/src/Explorer/QueryCopilot/V2/Bubbles/Sample/__snapshots__/SampleBubble.test.tsx.snap +++ b/src/Explorer/QueryCopilot/V2/Bubbles/Sample/__snapshots__/SampleBubble.test.tsx.snap @@ -1,6 +1,54 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Sample Bubble snapshot test should render 1`] = ` +exports[`Sample Bubble snapshot test should render 1`] = ` + + + Write a query to return last 10 records in the database + + + Write a query to return all records in this table created in the last thirty days which also have the record owner as "Contoso" + + +`; + +exports[`Sample Bubble snapshot test should render and be clicked 1`] = ` { - it("should render ", () => { + const initialStoreState = useQueryCopilot.getState(); + beforeEach(() => { + useQueryCopilot.setState(initialStoreState, true); + }); + + it("should open sample prompts on button click", () => { const wrapper = shallow(