Skip to content

Commit

Permalink
fix(fe:FSADT1-1569): trim search keywords (#1294)
Browse files Browse the repository at this point in the history
* fix: trim search keywords

* chore: update stub
  • Loading branch information
fterra-encora authored Nov 1, 2024
1 parent 85f6d86 commit 626a165
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
25 changes: 25 additions & 0 deletions frontend/cypress/e2e/pages/SearchPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,31 @@ describe("Search Page", () => {
});
});

describe("when user fills in the search box with extra spaces", () => {
beforeEach(() => {
cy.fillFormEntry("#search-box", " hello world ", { skipBlur: true });
});

it("trims the entered string before making the API call", () => {
cy.wait("@predictiveSearch").then((interception) => {
expect(interception.request.query.keyword).to.eq("hello world");
});
});

describe("and clicks the Search button", () => {
beforeEach(() => {
cy.wait("@predictiveSearch");
cy.get("#search-button").click();
});
it("trims the entered string before making the API call", () => {
cy.wait("@fullSearch").then((interception) => {
const { query } = interception.request;
expect(query.keyword).to.eq("hello world");
});
});
});
});

describe("Search with no keywords", () => {
beforeEach(() => {
cy.get("#search-button").click();
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/pages/SearchPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const pageNumber = ref(1);
const totalItems = ref(0);
const pageSize = ref(10);
const searchKeyword = ref("");
const rawSearchKeyword = ref("");
const searchKeyword = computed(() => rawSearchKeyword.value.trim().replaceAll(/ +/g, " "));
const lastSearchKeyword = ref("");
// empty is valid
Expand Down Expand Up @@ -219,7 +221,7 @@ onMounted(() => {
tip=""
placeholder="Search by client number, name or acronym"
size="lg"
v-model="searchKeyword"
v-model="rawSearchKeyword"
:contents="searchResultToCodeNameValueList(content)"
:validations="validations"
:validations-on-change="validationsOnChange"
Expand Down
4 changes: 2 additions & 2 deletions frontend/stub/mappings/client_search.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"method": "GET",
"queryParameters": {
"keyword": {
"matches": "empty"
"matches": ".*empty.*"
}
}
},
Expand Down Expand Up @@ -96,7 +96,7 @@
"method": "GET",
"queryParameters": {
"keyword": {
"matches": "empty"
"matches": ".*empty.*"
},
"page": {
"matches": "^[0-5]$"
Expand Down

0 comments on commit 626a165

Please sign in to comment.