Skip to content
Snippets Groups Projects
Unverified Commit 72d36b0f authored by Nick Fitzpatrick's avatar Nick Fitzpatrick Committed by GitHub
Browse files

Adjusting unit tests (#45643)

parent dcfdbec6
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,7 @@ interface SetupOpts {
recentItems?: RecentItem[];
defaultToRecentTab?: boolean;
initialValue?: { model: SampleModelType };
searchDelay?: number;
}
const TestPicker = ({ name }: { name: string }) => (
......@@ -84,13 +85,14 @@ const setup = ({
selectedItem = null,
recentItems = [],
recentFilter,
searchDelay = 0,
...rest
}: SetupOpts = {}) => {
mockGetBoundingClientRect();
mockScrollBy();
setupRecentViewsAndSelectionsEndpoints(recentItems);
fetchMock.get("path:/api/search", mockSearchResults);
fetchMock.get("path:/api/search", mockSearchResults, { delay: searchDelay });
fetchMock.get("path:/api/user/recipients", { data: [] });
......@@ -212,6 +214,26 @@ describe("EntityPickerModal", () => {
expect(onItemSelect).toHaveBeenCalledTimes(1);
});
it("should show a loading state while search is happening", async () => {
setup({
searchDelay: 2000,
});
await userEvent.type(
await screen.findByPlaceholderText("Search…"),
"My ",
{
delay: 50,
},
);
expect(await screen.findByRole("tablist")).toBeInTheDocument();
expect(
await screen.findByRole("tab", { name: /Search results/ }),
).toBeInTheDocument();
expect(await screen.findByText(/loading/i)).toBeInTheDocument();
});
it("should render a search bar by default and show confirmation button", async () => {
setup();
......
......@@ -424,7 +424,6 @@ describe("QuestionPickerModal", () => {
"true",
);
await screen.findByText(/loading/i);
await screen.findByText(/Didn't find anything/i);
});
......@@ -448,7 +447,6 @@ describe("QuestionPickerModal", () => {
"true",
);
await screen.findByText(/loading/i);
await screen.findByText(/Didn't find anything/i);
await userEvent.clear(searchInput);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment