Skip to content

Commit

Permalink
fix(fe): validate search on press enter (#1250)
Browse files Browse the repository at this point in the history
fix: allow validation on press enter
  • Loading branch information
fterra-encora authored Oct 18, 2024
1 parent 554faf4 commit a691f4d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
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

0 comments on commit a691f4d

Please sign in to comment.