[Query Copilot] Query Copilot button dropdown and shortcut (#1582)

* Copilot dropdown implementation

* additional changes

* added unit test for key event

* Additional test changes

---------

Co-authored-by: Predrag Klepic <v-prklepic@microsoft.com>
This commit is contained in:
Predrag Klepic
2023-08-21 16:17:06 +02:00
committed by GitHub
parent 986dbe7d54
commit ebd40cb9b0
2 changed files with 73 additions and 9 deletions

View File

@@ -0,0 +1,34 @@
import { fireEvent, render } from "@testing-library/react";
import QueryTabComponent, { IQueryTabComponentProps } from "Explorer/Tabs/QueryTab/QueryTabComponent";
import { useQueryCopilot } from "hooks/useQueryCopilot";
import React from "react";
jest.mock("Explorer/Controls/Editor/EditorReact");
describe("QueryTabComponent", () => {
const mockStore = useQueryCopilot.getState();
beforeEach(() => {
mockStore.showCopilotSidebar = false;
mockStore.setShowCopilotSidebar = jest.fn();
});
beforeEach(() => jest.clearAllMocks());
it("should launch Copilot when ALT+C is pressed", () => {
const propsMock: Readonly<IQueryTabComponentProps> = ({
collection: { databaseId: "CopilotSampleDb" },
onTabAccessor: () => jest.fn(),
isExecutionError: false,
tabId: "mockTabId",
tabsBaseInstance: {
updateNavbarWithTabsButtons: () => jest.fn(),
},
} as unknown) as IQueryTabComponentProps;
const { container } = render(<QueryTabComponent {...propsMock} />);
const launchCopilotButton = container.querySelector(".queryEditorWatermarkText");
fireEvent.keyDown(launchCopilotButton, { key: "c", altKey: true });
expect(mockStore.setShowCopilotSidebar).toHaveBeenCalledWith(true);
});
});