From e44f566eb553c0a204370267cfb5413a861bf416 Mon Sep 17 00:00:00 2001 From: Jon Maxwell Diebold Date: Thu, 9 Jan 2025 20:47:52 -0500 Subject: [PATCH 1/3] EQ-458 Added document text search tests --- app/client/src/routes/home.tsx | 9 ++++++--- app/cypress/e2e/home.cy.ts | 17 ++++++++++++++++- app/server/app/routes/attains.js | 20 +++++++------------- app/server/tests/api.attains.test.js | 19 +++++++++++++++---- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/app/client/src/routes/home.tsx b/app/client/src/routes/home.tsx index 654e336b..8d077da3 100644 --- a/app/client/src/routes/home.tsx +++ b/app/client/src/routes/home.tsx @@ -561,7 +561,10 @@ function FilterFieldInputs({ ? sourceState[sourceFieldConfig.id] : null; const selectProps = { - additionalOptions: 'additionalOptions' in fieldConfig ? fieldConfig.additionalOptions : [], + additionalOptions: + 'additionalOptions' in fieldConfig + ? fieldConfig.additionalOptions + : [], apiKey, apiUrl, contextFilters: getContextFilters( @@ -709,13 +712,13 @@ function FilterFieldInputs({
{fieldsJsx.map(([field, key, size]) => (
{field} diff --git a/app/cypress/e2e/home.cy.ts b/app/cypress/e2e/home.cy.ts index b3ece441..ad40953e 100644 --- a/app/cypress/e2e/home.cy.ts +++ b/app/cypress/e2e/home.cy.ts @@ -17,6 +17,7 @@ describe('Home Page', () => { it('All data profile option are select one by one and check Clear Search button is available ', () => { const profiles = [ + 'Actions Document Search', 'Actions', 'Assessment Units', 'Assessments', @@ -133,7 +134,10 @@ describe('Home Page', () => { 'columns=objectId&columns=region&columns=state&columns=organizationType&columns=organizationId&columns=organizationName&columns=waterType&columns=locationTypeCode&columns=locationText&columns=useClassName&columns=assessmentUnitId&columns=assessmentUnitName&columns=assessmentUnitStatus&columns=reportingCycle&columns=cycleId&columns=locationDescription&columns=sizeSource&columns=sourceScale&columns=waterSize&columns=waterSizeUnits'; const queryValue = `/api/attains/assessmentUnits?${columnsValue}&assessmentUnitStatus=R&state=TX&format=tsv&api_key=`; - cy.selectCopyBox('api-query-copy-box-container', `${serverUrl}${queryValue}`); + cy.selectCopyBox( + 'api-query-copy-box-container', + `${serverUrl}${queryValue}`, + ); cy.findAllByRole('button', { name: 'Clear Search' }).each( ($elem, index) => { @@ -172,4 +176,15 @@ describe('Home Page', () => { cy.findByText('Loading...').should('not.exist'); cy.findByText('No options').should('exist'); }); + + it.only('Document text search preview window displays with results', () => { + cy.selectProfile('Actions Document Search'); + cy.wait(500); + cy.findByRole('textbox', { + name: 'Search Text / Keyword', + }).type('water'); + cy.findByRole('button', { name: 'Preview' }).click(); + cy.wait(2000); + cy.findByRole('table').should('exist'); + }); }); diff --git a/app/server/app/routes/attains.js b/app/server/app/routes/attains.js index 34d11002..32b0227f 100644 --- a/app/server/app/routes/attains.js +++ b/app/server/app/routes/attains.js @@ -753,19 +753,13 @@ async function executeValuesQuery(profile, req, res) { } let values; - try { - values = await queryColumnValues( - res, - profile, - columns, - params, - req.activeSchema, - ); - } catch (err) { - return res.status(400).json({ - message: err.message, - }); - } + values = await queryColumnValues( + res, + profile, + columns, + params, + req.activeSchema, + ); return res.status(200).json(values); } catch (error) { log.error( diff --git a/app/server/tests/api.attains.test.js b/app/server/tests/api.attains.test.js index d16b1493..c587d613 100644 --- a/app/server/tests/api.attains.test.js +++ b/app/server/tests/api.attains.test.js @@ -158,7 +158,7 @@ describe('API Attains Tests', () => { .expect('Content-Type', /json/); expect(response.body).toEqual({ - message: 'The requested profile does not exist', + message: 'The api route does not exist.', }); }); @@ -327,7 +327,8 @@ describe('API Attains Tests', () => { }); test('POST /api/attains/assessments limit exceeded exception', async () => { - const body = { text: '', limit: 120 }; + const limit = 520; + const body = { text: '', limit }; const response = await supertest(app) .post(`/api/attains/assessments/values/assessmentUnitId`) .send(body) @@ -335,8 +336,7 @@ describe('API Attains Tests', () => { .expect('Content-Type', /json/); expect(response.body).toEqual({ - error: - 'Error: The provided limit (120) exceeds the maximum 100 allowable limit.', + error: `Error: The provided limit (${limit}) exceeds the maximum 500 allowable limit.`, }); }); @@ -397,4 +397,15 @@ describe('API Attains Tests', () => { expect(Array.isArray(response.body)).toBe(true); }); + + test('GET /api/attains/actionDocuments query returns ranked results', async () => { + const response = await supertest(app) + .get( + '/api/attains/actionDocuments?columns=objectId&documentQuery=test&limit=10', + ) + .expect(200); + + expect(Array.isArray(response.body.data)).toBe(true); + expect(response.body.data.pop()).toHaveProperty('rankPercent'); + }); }); From 4ba17c4589c1ec40051aa075cca9c64303c6872a Mon Sep 17 00:00:00 2001 From: Jon Maxwell Diebold Date: Thu, 9 Jan 2025 22:28:33 -0500 Subject: [PATCH 2/3] EQ-458 Fixed issue of default options not being searchable --- app/client/src/routes/home.tsx | 18 +++++++-- app/cypress/support/commands.ts | 47 +++++++++++++---------- app/server/app/content/config/fields.json | 4 +- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/app/client/src/routes/home.tsx b/app/client/src/routes/home.tsx index 8d077da3..21ee0961 100644 --- a/app/client/src/routes/home.tsx +++ b/app/client/src/routes/home.tsx @@ -1504,11 +1504,21 @@ function filterDynamicOptions({ const label = secondaryValue || value; return { label, value }; }); + if (!lastLoadedOption) { + (additionalOptions ?? []) + .concat(defaultOption ? [defaultOption] : []) + .forEach((option) => { + if ( + !inputValue || + (typeof option.label === 'string' && + option.label.toLowerCase().includes(inputValue.toLowerCase())) + ) { + options.unshift(option); + } + }); + } return { - options: - !lastLoadedOption && defaultOption // only include default option in first page - ? [defaultOption, ...additionalOptions, ...options] - : options, + options, hasMore: options.length >= limit, }; }; diff --git a/app/cypress/support/commands.ts b/app/cypress/support/commands.ts index 7b2cc4e0..4c759c41 100644 --- a/app/cypress/support/commands.ts +++ b/app/cypress/support/commands.ts @@ -34,7 +34,11 @@ declare global { * @example cy.dataCy('greeting') */ selectProfile(profile: string): Chainable; - selectOption(id: string, option: string, selectViaKeys?: boolean): Chainable; + selectOption( + id: string, + option: string, + selectViaKeys?: boolean, + ): Chainable; clipboardValue(value: string): Chainable; selectCopyBox(id: string, value: string): Chainable; } @@ -61,24 +65,28 @@ Cypress.Commands.add('selectProfile', (profile: string) => { * @param option - option to select */ -Cypress.Commands.add('selectOption', (id: string, option: string, selectViaKeys: boolean = false) => { - // NOTE: There is a cypress and or react-select bug where the select menu - // does not re-fetch the data when cypress first types something in. - // To work around this I just added a slight delay before typing the - // last character of the provided option. - cy.get(`#${id}`).type(option.slice(0, -1)); - cy.wait(1000); - cy.get(`#${id}`).type(option.slice(-1)); +Cypress.Commands.add( + 'selectOption', + (id: string, option: string, selectViaKeys: boolean = false) => { + // NOTE: There is a cypress and or react-select bug where the select menu + // does not re-fetch the data when cypress first types something in. + // To work around this I just added a slight delay before typing the + // last character of the provided option. + cy.get(`#${id}`).type(option.slice(0, -1)); + cy.wait(1000); + cy.get(`#${id}`).type(option.slice(-1)); - cy.findByText('Loading...').should('not.exist'); - - if(selectViaKeys) { - cy.get(`#${id}`).type('{downArrow}{enter}'); - } else { - cy.get(`#react-select-instance-${id.replace('input-', '')}-option-0`) - .click({ force: true }); + cy.findByText('Loading...').should('not.exist'); + + if (selectViaKeys) { + cy.get(`#${id}`).type('{downArrow}{enter}'); + } else { + cy.get( + `#react-select-instance-${id.replace('input-', '')}-option-0`, + ).click({ force: true }); } -}); + }, +); /** * This read the value from windows clipboard. @@ -102,7 +110,6 @@ Cypress.Commands.add('clipboardValue', (value: string) => { */ Cypress.Commands.add('selectCopyBox', (id: string, value: string) => { - cy.findByTestId(id) - .should('exist') - cy.findByText(value); + cy.findByTestId(id).should('exist'); + cy.findByText(value); }); diff --git a/app/server/app/content/config/fields.json b/app/server/app/content/config/fields.json index baf8a1b8..1b4e37b4 100644 --- a/app/server/app/content/config/fields.json +++ b/app/server/app/content/config/fields.json @@ -398,9 +398,7 @@ "key": "reportingCycle", "label": "Reporting Cycle", "type": "select", - "additionalOptions": [ - { "value": -1, "label": "Any" } - ], + "additionalOptions": [{ "value": -1, "label": "Any" }], "default": { "value": "", "label": "Latest" }, "direction": "desc", "contextFields": ["organizationId", "region", "state"] From 05c6a62b8cf3082c4f4bccfd4be7083f38c68941 Mon Sep 17 00:00:00 2001 From: Caleb Schwind <46329268+cschwinderg@users.noreply.github.com> Date: Fri, 10 Jan 2025 12:08:55 -0500 Subject: [PATCH 3/3] EQ-458 Removed only flag from one of the tests. --- app/cypress/e2e/home.cy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/cypress/e2e/home.cy.ts b/app/cypress/e2e/home.cy.ts index ad40953e..aac9eb7a 100644 --- a/app/cypress/e2e/home.cy.ts +++ b/app/cypress/e2e/home.cy.ts @@ -177,7 +177,7 @@ describe('Home Page', () => { cy.findByText('No options').should('exist'); }); - it.only('Document text search preview window displays with results', () => { + it('Document text search preview window displays with results', () => { cy.selectProfile('Actions Document Search'); cy.wait(500); cy.findByRole('textbox', {