Skip to content

Commit

Permalink
explorer: Failed query notices don't disappear
Browse files Browse the repository at this point in the history
Resolves #1716
  • Loading branch information
ascartabelli committed May 9, 2024
1 parent f1eff07 commit 140965a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions explorer/src/lib/components/__tests__/Navbar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ global.ResizeObserver = vi.fn().mockImplementation(() => ({
unobserve: vi.fn(),
}));

/** @param {HTMLElement} container */
const getNotificationElement = (container) =>
container.querySelector(".dusk-navbar__menu--search-notification");

/** @param {HTMLElement} container */
async function showSearchNotification(container) {
const form = /** @type {HTMLFormElement} */ (container.querySelector("form"));
const searchInput = /** @type {HTMLInputElement} */ (
form.querySelector("input[type='text']")
);

searchInput.value = "foobar"; // invalid search

await fireEvent.submit(form);
}

describe("Navbar", () => {
/** @type {(navigation: import("@sveltejs/kit").AfterNavigate) => void} */
let afterNavigateCallback;
Expand Down Expand Up @@ -61,4 +77,39 @@ describe("Navbar", () => {
expect(menu).toHaveClass("dusk-navbar__menu--hidden");
expect(btnMenuToggle).toHaveAttribute("aria-expanded", "false");
});

it("should hide the search notification when its close button is clicked", async () => {
const { container } = render(Navbar);

expect(getNotificationElement(container)).toBeNull();

await showSearchNotification(container);

expect(getNotificationElement(container)).toBeInTheDocument();

const btnClose = /** @type {HTMLButtonElement} */ (
container.querySelector(".search-notification__header-action")
);

await fireEvent.click(btnClose);

expect(getNotificationElement(container)).toBeNull();
});

it("should hide the search notification after a navigation event", async () => {
const { container } = render(Navbar);

expect(getNotificationElement(container)).toBeNull();

await showSearchNotification(container);

expect(getNotificationElement(container)).toBeInTheDocument();

await act(() => {
// @ts-expect-error we don't care for navigation details
afterNavigateCallback();
});

expect(getNotificationElement(container)).toBeNull();
});
});
1 change: 1 addition & 0 deletions explorer/src/lib/components/navbar/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
afterNavigate(() => {
hidden = true;
showSearchNotification = false;
});
</script>
Expand Down

0 comments on commit 140965a

Please sign in to comment.