mirror of
https://github.com/LukeHagar/unicorn-utterances.git
synced 2025-12-06 12:57:44 +00:00
test: add test behavior to back button
This commit is contained in:
@@ -9,12 +9,21 @@ import "jest-location-mock";
|
|||||||
|
|
||||||
global.plausible = null;
|
global.plausible = null;
|
||||||
|
|
||||||
|
let history = [];
|
||||||
|
|
||||||
window.history.pushState = (data, unused, url) => {
|
window.history.pushState = (data, unused, url) => {
|
||||||
window.location.assign(url);
|
window.location.assign(url);
|
||||||
|
history.push(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.history.replaceState = (data, unused, url) => {
|
window.history.replaceState = (data, unused, url) => {
|
||||||
window.location.assign(url);
|
window.location.assign(url);
|
||||||
|
history[history.length - 1] = url;
|
||||||
|
};
|
||||||
|
|
||||||
|
window.history.back = () => {
|
||||||
|
history.pop();
|
||||||
|
window.location.assign(history[history.length - 1]);
|
||||||
};
|
};
|
||||||
|
|
||||||
global.IntersectionObserver = class IntersectionObserver {
|
global.IntersectionObserver = class IntersectionObserver {
|
||||||
|
|||||||
@@ -1129,5 +1129,35 @@ describe("Search page", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.todo("Back button should show last query");
|
test("Back button should show last query", async () => {
|
||||||
|
mockFetch(() => ({
|
||||||
|
posts: [],
|
||||||
|
totalPosts: 0,
|
||||||
|
totalCollections: 0,
|
||||||
|
collections: [],
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { getByTestId, getByText, getByLabelText, queryByText } = render(
|
||||||
|
<SearchPage unicornProfilePicMap={[]} />,
|
||||||
|
);
|
||||||
|
|
||||||
|
const searchInput = getByLabelText("Search");
|
||||||
|
await user.type(searchInput, "blog");
|
||||||
|
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(getByText("No results found...")).toBeInTheDocument(),
|
||||||
|
);
|
||||||
|
|
||||||
|
await user.type(searchInput, "other");
|
||||||
|
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(window.location.search).toBe("?searchQuery=blogother"),
|
||||||
|
);
|
||||||
|
|
||||||
|
history.back();
|
||||||
|
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(window.location.search).toBe("?searchQuery=blog"),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user