Skip to content

Commit

Permalink
pr feedback: simplify anyFiltersSelected and rename response alias in…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
raejohanek committed Nov 26, 2024
1 parent 455abe3 commit ff293e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
12 changes: 6 additions & 6 deletions cypress/component/DataSearch/dataset_search_table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,31 @@ describe('Dataset Search Table tests', () => {
cy.intercept(
{method: 'POST', url: '**/search/index'}, (req) => {
return handler(req, '{"range":{"participantCount":{"gte":null,"lte":50}}}');
}).as('searchIndex1');
}).as('searchIndex');
mount(<DatasetSearchTable {...props} />);
// first clear the default value (100), without clearing first, type('50') would result in input of 10050
cy.get('#participantCountMax-range-input').clear().type('50');
cy.tick(150);
// this api call should have had a request that contained the searchText
cy.wait('@searchIndex1').then((response) => {
cy.wait('@searchIndex').then((response) => {
expect(response.response.body[0]).to.equal('filtered');
});
cy.get('@searchIndex1.all').should('have.length', 1);
cy.get('@searchIndex.all').should('have.length', 1);

});

it('When an invalid participant count filter is applied the query represents the default value', () => {
cy.intercept({method: 'POST', url: '**/search/index'}, (req) => {
// when non-numeric input is entered, the default value (in this case, 100) is used
return handler(req, '{"range":{"participantCount":{"gte":100,"lte":null}}}');
}).as('searchIndex2');
}).as('searchIndex');
mount(<DatasetSearchTable {...props} />);
cy.get('#participantCountMin-range-input').type('test');
cy.tick(150);
cy.wait('@searchIndex2').then((response) => {
cy.wait('@searchIndex').then((response) => {
expect(response.response.body[0]).to.equal('filtered');
});
cy.get('@searchIndex2.all').should('have.length', 1);
cy.get('@searchIndex.all').should('have.length', 1);
});

});
Expand Down
11 changes: 3 additions & 8 deletions src/components/data_search/DatasetSearchTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,10 @@ export const DatasetSearchTable = (props) => {

const isFilteredArray = (filter, category) => (filters[category]).indexOf(filter) > -1;

const anyFiltersSelected = (filters) => {
return Object.values(filters).some((filter) => {
if (isArray(filter)) {
return filter.length > 0;
} else {
return filter !== null;
}
const anyFiltersSelected = (filters) =>
Object.values(filters).some(filter => {
return isArray(filter) ? filter.length > 0 : filter !== null;
});
};

const getExportableDatasets = async (datasets) => {
// Note the dataset identifier is in each sub-table row.
Expand Down

0 comments on commit ff293e5

Please sign in to comment.