mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 15:06:55 +00:00
[Query Copilot] Hide error message bar when request is successful (#1542)
Co-authored-by: Predrag Klepic <v-prklepic@microsoft.com>
This commit is contained in:
parent
10037d844e
commit
42e11d5160
@ -188,6 +188,7 @@ export const QueryCopilotTab: React.FC<QueryCopilotTabProps> = ({
|
|||||||
query += generateSQLQueryResponse.sql;
|
query += generateSQLQueryResponse.sql;
|
||||||
setQuery(query);
|
setQuery(query);
|
||||||
setGeneratedQuery(generateSQLQueryResponse.sql);
|
setGeneratedQuery(generateSQLQueryResponse.sql);
|
||||||
|
setShowErrorMessageBar(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
handleError(JSON.stringify(generateSQLQueryResponse), "copilotInternalServerError");
|
handleError(JSON.stringify(generateSQLQueryResponse), "copilotInternalServerError");
|
||||||
@ -231,6 +232,7 @@ export const QueryCopilotTab: React.FC<QueryCopilotTabProps> = ({
|
|||||||
|
|
||||||
setQueryResults(queryResults);
|
setQueryResults(queryResults);
|
||||||
setErrorMessage("");
|
setErrorMessage("");
|
||||||
|
setShowErrorMessageBar(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = getErrorMessage(error);
|
const errorMessage = getErrorMessage(error);
|
||||||
setErrorMessage(errorMessage);
|
setErrorMessage(errorMessage);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { DefaultButton, IconButton } from "@fluentui/react";
|
||||||
import { shallow } from "enzyme";
|
import { shallow } from "enzyme";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { SamplePrompts, SamplePromptsProps } from "./SamplePrompts";
|
import { SamplePrompts, SamplePromptsProps } from "./SamplePrompts";
|
||||||
@ -10,6 +11,7 @@ describe("Sample Prompts snapshot test", () => {
|
|||||||
setIsSamplePromptsOpen: setIsSamplePromptsOpenMock,
|
setIsSamplePromptsOpen: setIsSamplePromptsOpenMock,
|
||||||
setTextBox: setTextBoxMock,
|
setTextBox: setTextBoxMock,
|
||||||
};
|
};
|
||||||
|
beforeEach(() => jest.clearAllMocks());
|
||||||
|
|
||||||
it("should render properly if isSamplePromptsOpen is true", () => {
|
it("should render properly if isSamplePromptsOpen is true", () => {
|
||||||
const wrapper = shallow(<SamplePrompts sampleProps={sampleProps} />);
|
const wrapper = shallow(<SamplePrompts sampleProps={sampleProps} />);
|
||||||
@ -24,4 +26,66 @@ describe("Sample Prompts snapshot test", () => {
|
|||||||
|
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should call setTextBox and setIsSamplePromptsOpen(false) when a button is clicked", () => {
|
||||||
|
const wrapper = shallow(<SamplePrompts sampleProps={sampleProps} />);
|
||||||
|
|
||||||
|
wrapper.find(DefaultButton).at(0).simulate("click");
|
||||||
|
expect(setTextBoxMock).toHaveBeenCalledWith("Show me products less than 100 dolars");
|
||||||
|
expect(setIsSamplePromptsOpenMock).toHaveBeenCalledWith(false);
|
||||||
|
|
||||||
|
wrapper.find(DefaultButton).at(3).simulate("click");
|
||||||
|
expect(setTextBoxMock).toHaveBeenCalledWith(
|
||||||
|
"Write a query to return all records in this table created in the last thirty days"
|
||||||
|
);
|
||||||
|
expect(setIsSamplePromptsOpenMock).toHaveBeenCalledWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call setIsSamplePromptsOpen(false) when the close button is clicked", () => {
|
||||||
|
const wrapper = shallow(<SamplePrompts sampleProps={sampleProps} />);
|
||||||
|
|
||||||
|
wrapper.find(IconButton).first().simulate("click");
|
||||||
|
|
||||||
|
expect(setIsSamplePromptsOpenMock).toHaveBeenCalledWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call setTextBox and setIsSamplePromptsOpen(false) when a simple prompt button is clicked", () => {
|
||||||
|
const wrapper = shallow(<SamplePrompts sampleProps={sampleProps} />);
|
||||||
|
|
||||||
|
wrapper.find(DefaultButton).at(0).simulate("click");
|
||||||
|
expect(setTextBoxMock).toHaveBeenCalledWith("Show me products less than 100 dolars");
|
||||||
|
expect(setIsSamplePromptsOpenMock).toHaveBeenCalledWith(false);
|
||||||
|
|
||||||
|
wrapper.find(DefaultButton).at(1).simulate("click");
|
||||||
|
expect(setTextBoxMock).toHaveBeenCalledWith("Show schema");
|
||||||
|
expect(setIsSamplePromptsOpenMock).toHaveBeenCalledWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call setTextBox and setIsSamplePromptsOpen(false) when an intermediate prompt button is clicked", () => {
|
||||||
|
const wrapper = shallow(<SamplePrompts sampleProps={sampleProps} />);
|
||||||
|
|
||||||
|
wrapper.find(DefaultButton).at(2).simulate("click");
|
||||||
|
expect(setTextBoxMock).toHaveBeenCalledWith(
|
||||||
|
"Show items with a description that contains a number between 0 and 99 inclusive."
|
||||||
|
);
|
||||||
|
expect(setIsSamplePromptsOpenMock).toHaveBeenCalledWith(false);
|
||||||
|
|
||||||
|
wrapper.find(DefaultButton).at(3).simulate("click");
|
||||||
|
expect(setTextBoxMock).toHaveBeenCalledWith(
|
||||||
|
"Write a query to return all records in this table created in the last thirty days"
|
||||||
|
);
|
||||||
|
expect(setIsSamplePromptsOpenMock).toHaveBeenCalledWith(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call setTextBox and setIsSamplePromptsOpen(false) when a complex prompt button is clicked", () => {
|
||||||
|
const wrapper = shallow(<SamplePrompts sampleProps={sampleProps} />);
|
||||||
|
|
||||||
|
wrapper.find(DefaultButton).at(4).simulate("click");
|
||||||
|
expect(setTextBoxMock).toHaveBeenCalledWith("Show all the products that customer Bob has reviewed.");
|
||||||
|
expect(setIsSamplePromptsOpenMock).toHaveBeenCalledWith(false);
|
||||||
|
|
||||||
|
wrapper.find(DefaultButton).at(5).simulate("click");
|
||||||
|
expect(setTextBoxMock).toHaveBeenCalledWith("Which computers are more than 300 dollars and less than 400 dollars?");
|
||||||
|
expect(setIsSamplePromptsOpenMock).toHaveBeenCalledWith(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user