Skip to content

Commit

Permalink
Merge pull request #199 from Eastern-Research-Group/feature/458_docum…
Browse files Browse the repository at this point in the history
…ent-search-tests

Feature/458 document search tests
  • Loading branch information
cschwinderg authored Jan 10, 2025
2 parents 28ccc84 + 05c6a62 commit 097b367
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 47 deletions.
22 changes: 16 additions & 6 deletions app/client/src/routes/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -712,13 +712,13 @@ function FilterFieldInputs({
<div className="grid-gap-2 grid-row">
{fieldsJsx.map(([field, key, size]) => (
<div
className={`flex-align-self-end ${
className={
size === 'large'
? 'width-full'
: size === 'medium'
? 'desktop:grid-col-8 tablet:grid-col-6'
: 'desktop:grid-col-4 tablet:grid-col-6'
}`}
}
key={key}
>
{field}
Expand Down Expand Up @@ -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,
};
};
Expand Down
17 changes: 16 additions & 1 deletion app/cypress/e2e/home.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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=<YOUR_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) => {
Expand Down Expand Up @@ -172,4 +176,15 @@ describe('Home Page', () => {
cy.findByText('Loading...').should('not.exist');
cy.findByText('No options').should('exist');
});

it('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');
});
});
47 changes: 27 additions & 20 deletions app/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ declare global {
* @example cy.dataCy('greeting')
*/
selectProfile(profile: string): Chainable<Element>;
selectOption(id: string, option: string, selectViaKeys?: boolean): Chainable<Element>;
selectOption(
id: string,
option: string,
selectViaKeys?: boolean,
): Chainable<Element>;
clipboardValue(value: string): Chainable<Element>;
selectCopyBox(id: string, value: string): Chainable<Element>;
}
Expand All @@ -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.
Expand All @@ -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);
});
4 changes: 1 addition & 3 deletions app/server/app/content/config/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
20 changes: 7 additions & 13 deletions app/server/app/routes/attains.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,19 +755,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(
Expand Down
19 changes: 15 additions & 4 deletions app/server/tests/api.attains.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
});
});

Expand Down Expand Up @@ -327,16 +327,16 @@ 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)
.expect(400)
.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.`,
});
});

Expand Down Expand Up @@ -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');
});
});

0 comments on commit 097b367

Please sign in to comment.