Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fe): validate search on press enter #1250

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions frontend/cypress/e2e/pages/SearchPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,24 @@ describe("Search Page", () => {
});
});

describe("when user fills in the search box with less than 3 characters", () => {
beforeEach(() => {
cy.fillFormEntry("#search-box", "12", { skipBlur: true });
});

describe("and hits enter on the search box", () => {
beforeEach(() => {
cy.fillFormEntry("#search-box", "{enter}", { skipBlur: true });
});
it("shows error message and makes no API call", () => {
cy.contains("The search terms must contain at least 3 characters");

cy.wait(500); // This time has to be greater than the debouncing time
cy.wrap(fullSearchCounter).its("count").should("eq", 0);
});
});
});

describe("Search with no keywords", () => {
beforeEach(() => {
cy.get("#search-button").click();
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/pages/SearchPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import "@carbon/web-components/es/components/select/index";
import "@carbon/web-components/es/components/tag/index";

import { useFetchTo } from "@/composables/useFetch";
import { useEventBus } from "@vueuse/core";

import type { ClientSearchResult, CodeNameType } from "@/dto/CommonTypesDto";
import { adminEmail, getObfuscatedEmailLink, toTitleCase } from "@/services/ForestClientService";
import summit from "@carbon/pictograms/es/summit";
Expand All @@ -25,6 +27,8 @@ import {
optional,
} from "@/helpers/validators/GlobalValidators";

const revalidateBus = useEventBus<string[] | undefined>("revalidate-bus");

const summitSvg = useSvg(summit);

const userhasAuthority = ["CLIENT_VIEWER", "CLIENT_EDITOR", "CLIENT_ADMIN", "CLIENT_SUSPEND"].some(authority => ForestClientUserSession.authorities.includes(authority));
Expand Down Expand Up @@ -53,12 +57,14 @@ const fullSearchUri = computed(

const {
response: searchResponse,
fetch,
fetch: fetchSearch,
loading: loadingSearch,
error: searchError,
} = useFetchTo(fullSearchUri, tableData, { skip: true });

const search = (skipResetPage = false) => {
revalidateBus.emit();

if (!valid.value) {
return;
}
Expand All @@ -69,7 +75,7 @@ const search = (skipResetPage = false) => {
if (!skipResetPage) {
pageNumber.value = 1;
}
fetch();
fetchSearch();
};

watch(searchResponse, () => {
Expand Down
Loading