diff --git a/cypress/component/DataSearch/dataset_search_table.spec.js b/cypress/component/DataSearch/dataset_search_table.spec.js index ac4f41aea..c6cf7b5a5 100644 --- a/cypress/component/DataSearch/dataset_search_table.spec.js +++ b/cypress/component/DataSearch/dataset_search_table.spec.js @@ -44,22 +44,27 @@ describe('Dataset Search Table tests', () => { }); describe('Data library filter by participant count tests', () => { + let searchText; + let filtered; + beforeEach(() => { cy.initApplicationConfig(); cy.stub(TerraDataRepo, 'listSnapshotsByDatasetIds').returns({}); + filtered = false; }); - it('When a participant count filter is applied the query is updated', () => { - var filtered = false; - function handler(request) { - if (JSON.stringify(request.body).includes('{"range":{"participantCount":{"gte":null,"lte":"50"}}}')) { - filtered = true; - } - request.reply({statusCode: 200, body:[]}); + function handler(request) { + if (JSON.stringify(request.body).includes(searchText)) { + filtered = true; } + request.reply({statusCode: 200, body:[]}); + } + + it('When a participant count filter is applied the query is updated', () => { + searchText ='{"range":{"participantCount":{"gte":null,"lte":"50"}}}'; cy.intercept( - {method: 'POST', url: '**/api/dataset/search/index'}, handler).as('searchIndex'); + {method: 'POST', url: '**/api/dataset/search/index'}, handler); mount(); cy.get('#participantCountMax-range-input').clear().type('50'); cy.wait(1000).then(() => { @@ -67,5 +72,16 @@ describe('Dataset Search Table tests', () => { }); }); + it('When an invalid participant count filter is applied the query represents the default value', () => { + searchText = '{"range":{"participantCount":{"gte":100,"lte":null}}}'; + + cy.intercept({method: 'POST', url: '**/api/dataset/search/index'}, handler); + mount(); + cy.get('#participantCountMin-range-input').clear().type('test'); + cy.wait(1000).then(() => { + expect(filtered).to.be.true; + }); + }); + }); }); diff --git a/src/components/data_search/DatasetFilterList.jsx b/src/components/data_search/DatasetFilterList.jsx index 69ca7740a..64862e2c3 100644 --- a/src/components/data_search/DatasetFilterList.jsx +++ b/src/components/data_search/DatasetFilterList.jsx @@ -52,12 +52,12 @@ export const FilterItemRange = (props) => { filterHandler(minCategory, event.target.value === '' ? min : event.target.value)}/> + onChange={(event) => filterHandler(minCategory, isNaN(parseInt(event.target.value)) ? min : event.target.value)}/> - filterHandler(maxCategory, event.target.value === '' ? max : event.target.value)} + onChange={(event) => filterHandler(maxCategory, isNaN(parseInt(event.target.value)) ? max : event.target.value)} /> );