394 search block empty field search on enter (#401)

Co-authored-by: Camille Moussu <cmoussu@linagora.com>
This commit is contained in:
Camille Moussu
2025-12-11 18:35:59 +01:00
committed by GitHub
parent a4b4f6d11c
commit f863bb8194
2 changed files with 51 additions and 6 deletions
@@ -182,10 +182,7 @@ describe("EventSearchBar", () => {
fireEvent.click(searchButton);
// Click tune icon
const tuneButtons = screen.getAllByRole("button");
const tuneButton = tuneButtons.find((btn) =>
btn.querySelector('[data-testid="TuneIcon"]')
);
const tuneButton = screen.getByTestId("TuneIcon");
if (tuneButton) fireEvent.click(tuneButton);
await waitFor(() => {
@@ -232,4 +229,38 @@ describe("EventSearchBar", () => {
});
});
});
it("should not trigger search on Enter key when search is empty", async () => {
const searchSpy = jest.spyOn(searchThunk, "searchEventsAsync");
renderWithProviders(<SearchBar />, preloadedState);
const searchButton = screen.getByRole("button");
fireEvent.click(searchButton);
const searchInput = screen.getByPlaceholderText("common.search");
fireEvent.keyDown(searchInput, { key: "Enter" });
await waitFor(() => {
expect(searchSpy).not.toHaveBeenCalled();
});
});
it("should not trigger search when filter keywords is empty", async () => {
const searchSpy = jest.spyOn(searchThunk, "searchEventsAsync");
renderWithProviders(<SearchBar />, preloadedState);
const searchButton = screen.getByRole("button");
fireEvent.click(searchButton);
// Click tune icon
const tuneButton = screen.getByTestId("TuneIcon");
if (tuneButton) fireEvent.click(tuneButton);
fireEvent.click(screen.getByText("common.search"));
await waitFor(() => {
expect(searchSpy).not.toHaveBeenCalled();
});
});
});