Skip to content

Commit

Permalink
Feedback: add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
raejohanek committed Nov 22, 2024
1 parent 8dd3cc4 commit d03c0bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
32 changes: 24 additions & 8 deletions cypress/component/DataSearch/dataset_search_table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,44 @@ 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(<DatasetSearchTable {...props} />);
cy.get('#participantCountMax-range-input').clear().type('50');
cy.wait(1000).then(() => {
expect(filtered).to.be.true;
});
});

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(<DatasetSearchTable {...props} />);
cy.get('#participantCountMin-range-input').clear().type('test');
cy.wait(1000).then(() => {
expect(filtered).to.be.true;
});
});

});
});
4 changes: 2 additions & 2 deletions src/components/data_search/DatasetFilterList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ export const FilterItemRange = (props) => {
<TextField id={minCategory + '-range-input'} size='small' margin='dense' variant='outlined' defaultValue={min}
helperText={'minimum'}
FormHelperTextProps={{style: { transform: 'scale(1.5)' }}}
onChange={(event) => filterHandler(minCategory, event.target.value === '' ? min : event.target.value)}/>
onChange={(event) => filterHandler(minCategory, isNaN(parseInt(event.target.value)) ? min : event.target.value)}/>
<Box padding={'0rem 1rem 1rem'}> - </Box>
<TextField id={maxCategory + '-range-input'} size='small' margin='dense' variant='outlined' defaultValue={max}
helperText={'maximum'}
FormHelperTextProps={{style: {transform: 'scale(1.5)'}}}
onChange={(event) => filterHandler(maxCategory, event.target.value === '' ? max : event.target.value)}
onChange={(event) => filterHandler(maxCategory, isNaN(parseInt(event.target.value)) ? max : event.target.value)}
/>
</Box>
);
Expand Down

0 comments on commit d03c0bf

Please sign in to comment.