Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
s-rubenstein committed Dec 13, 2024
1 parent 1816c1f commit 729b3f5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
4 changes: 2 additions & 2 deletions cypress/component/DataSearch/dataset_search_filters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ describe('Data Library Filters', () => {
const filterHandlerStub = cy.stub();
const props = { datasets, filters: { ...defaultFilters(datasets), participantCountMin: 2, participantCountMax: 5 }, filterHandler: filterHandlerStub, isFiltered: () => {}};
mount(<DatasetFilterList {...props} />);
cy.get('#participantCountMax-range-input').type('3').trigger('change');
cy.get('#participantCountMax-range-input').type('3');
filterHandlerStub.calledWith('participantCountMax', 53);
cy.get('#participantCountMin-range-input').type('3').trigger('change');
cy.get('#participantCountMin-range-input').type('3');
filterHandlerStub.calledWith('participantCountMin', 23);
});
});
55 changes: 27 additions & 28 deletions cypress/component/DataSearch/dataset_search_table.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable no-undef */
import { makeDatasetTerm } from '../test-utils'
import {React} from 'react';
import {mount} from 'cypress/react';
import DatasetSearchTable from '../../../src/components/data_search/DatasetSearchTable';
import {TerraDataRepo} from '../../../src/libs/ajax/TerraDataRepo';

const datasets = [
{
makeDatasetTerm({
datasetId: 123456,
datasetIdentifier: `DUOS-123456`,
datasetName: 'Some Dataset 1',
Expand All @@ -15,7 +16,18 @@ const datasets = [
studyId: 1,
dataCustodianEmail: ['Some Data Custodian Email 1'],
}
}
}),
makeDatasetTerm({
datasetId: 123456,
datasetIdentifier: `DUOS-123456`,
datasetName: 'Some Dataset 1',
participantCount: 50,
study: {
studyName: 'Some Study 1',
studyId: 1,
dataCustodianEmail: ['Some Data Custodian Email 1'],
}
})
];

const props = {
Expand All @@ -34,13 +46,13 @@ describe('Dataset Search Table tests', () => {
});

it('When no datasets are selected the footer does not appear', () => {
cy.contains('1 dataset selected from 1 study').should('not.exist');
cy.contains('selected from 1 study').should('not.exist');
});


it('When a dataset is selected the footer appears', () => {
cy.get('#header-checkbox').click();
cy.contains('1 dataset selected from 1 study');
cy.contains(`${datasets.length} datasets selected from 1 study`);
});
});

Expand All @@ -65,13 +77,19 @@ describe('Dataset Search Table tests', () => {
it('When a participant count filter is applied the query is updated', () => {
cy.intercept(
{method: 'POST', url: '**/search/index'}, (req) => {
return handler(req, '{"range":{"participantCount":{"gte":null,"lte":50}}}');
return handler(req, '{"range":{"participantCount":{"gte":30,"lte":50}}}');
}).as('searchIndex');
mount(<DatasetSearchTable {...props} />);
// first clear the default value (100), without clearing first, type('50') would result in input of 10050
const range = cy.get('#participantCountMax-range-input');
range.clear();
range.type('50');
// first clear the default value (50), without clearing first, type('3') would result in input of 503
const minRange = cy.get('#participantCountMin-range-input');
minRange.clear();
// Just type 3 because after being cleared it defaults to 0
minRange.type('3');
// first clear the default value (100), without clearing first, type('5') would result in input of 1005
const maxRange = cy.get('#participantCountMax-range-input');
maxRange.clear();
// Just type 5 because after being cleared it defaults to 0
maxRange.type('5')
cy.tick(150);
// this api call should have had a request that contained the searchText
let count = 0;
Expand All @@ -84,24 +102,5 @@ describe('Dataset Search Table tests', () => {
});

});

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('searchIndex');
mount(<DatasetSearchTable {...props} />);
cy.get('#participantCountMin-range-input').type('test');
cy.tick(150);
let count = 0;
cy.wait('@searchIndex').then((response) => {
expect(response.response.body[0]).to.equal('filtered');
count++;
});
cy.get('@searchIndex').then(() => {
expect(count).to.equal(1);
});
});

});
});
10 changes: 5 additions & 5 deletions src/components/data_search/DatasetFilterList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const FilterItemHeader = (props: FilterItemHeaderProps) => {
interface FilterItemListProps {
category: string;
filter: string[];
filterHandler: (category: string, filter: string) => void;
filterHandler: (category: string, filter: string | number) => void;
isFiltered: (filter: string, category: string) => boolean;
filterNameFn: (filter: string) => string;
filterDisplayFn?: (filter: string) => React.ReactNode;
Expand Down Expand Up @@ -64,7 +64,7 @@ interface FilterItemRangeProps {
max?: number;
minCategory: string;
maxCategory: string;
filterHandler: (category: string, filter: string) => void;
filterHandler: (category: string, filter: string | number) => void;
}

export const FilterItemRange = (props: FilterItemRangeProps) => {
Expand All @@ -77,21 +77,21 @@ export const FilterItemRange = (props: FilterItemRangeProps) => {
helperText={'minimum'}
FormHelperTextProps={{style: { transform: 'scale(1.5)' }}}
inputProps={inputProps}
onChange={(event) => filterHandler(minCategory, event.target.value)}/>
onChange={(event) => filterHandler(minCategory, Number(event.target.value))}/>
<Box padding={'0rem 1rem 1rem'}> - </Box>
<TextField type={'number'} value={max} id={maxCategory + '-range-input'}
size='small' margin='dense' variant='outlined'
helperText={'maximum'}
FormHelperTextProps={{style: { transform: 'scale(1.5)' }}}
inputProps={inputProps}
onChange={(event) => filterHandler(maxCategory, event.target.value)}/>
onChange={(event) => filterHandler(maxCategory, Number(event.target.value))}/>
</Box>
);
};

interface DatasetFilterListProps {
datasets: DatasetTerm[];
filterHandler: (category: string, filter: string) => void;
filterHandler: (category: string, filter: string | number) => void;
isFiltered: (filter: string, category: string) => boolean;
filters: FiltersTypes
onClear: () => void;
Expand Down

0 comments on commit 729b3f5

Please sign in to comment.