Skip to content

Commit

Permalink
Clear search and taxnomoies on confirm, Add unit tests for newly added
Browse files Browse the repository at this point in the history
actions
  • Loading branch information
hanbyul-here committed Jun 28, 2024
1 parent b518fb9 commit d177321
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
40 changes: 40 additions & 0 deletions app/scripts/components/common/catalog/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { CatalogActions, onCatalogAction } from './utils';
describe('onCatalogAction', () => {
let setSearchMock;
let setTaxonomiesMock;
let search;
let taxonomies;

beforeEach(() => {
setSearchMock = jest.fn();
setTaxonomiesMock = jest.fn();
search = 'air';

Check failure on line 13 in app/scripts/components/common/catalog/utils.test.ts

View workflow job for this annotation

GitHub Actions / lint

'search' is assigned a value but never used
taxonomies = {
Topics: ['air-quality', 'climate'],
Sectors: ['electricity', 'energy']
Expand All @@ -28,6 +30,29 @@ describe('onCatalogAction', () => {
expect(setTaxonomiesMock).toHaveBeenCalledWith({});
});

it('should clear only taxonomies on CLEAR_TAXONOMY action', () => {
onCatalogAction(
CatalogActions.CLEAR_TAXONOMY,
null,
taxonomies,
setSearchMock,
setTaxonomiesMock
);

expect(setTaxonomiesMock).toHaveBeenCalledWith({});
});

it('should clear only search on CLEAR_SEARCH action', () => {
onCatalogAction(
CatalogActions.CLEAR_SEARCH,
null,
taxonomies,
setSearchMock,
setTaxonomiesMock
);

expect(setSearchMock).toHaveBeenCalledWith('');
});
it('should set search value on SEARCH action', () => {
const searchValue = 'climate';
onCatalogAction(
Expand Down Expand Up @@ -56,6 +81,21 @@ describe('onCatalogAction', () => {
);
});

it('should overwrite the existing taxonomy value with TAXONOMY action', () => {
const value = { key: 'Topics', value: 'climate' };
onCatalogAction(
CatalogActions.TAXONOMY,
value,
taxonomies,
setSearchMock,
setTaxonomiesMock
);

expect(setTaxonomiesMock).toHaveBeenCalledWith(
set({ ...taxonomies }, value.key, value.value)
);
});

it('should remove value from Topics taxonomy on TAXONOMY_MULTISELECT action', () => {
const value = { key: 'Topics', value: 'climate' };
onCatalogAction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ModalFooterRender from './footer';
import CatalogContent from '$components/common/catalog/catalog-content';
import { DATASETS_PATH } from '$utils/routes';
import { useCatalogView } from '$components/common/catalog/controls/hooks/use-catalog-view';
import { CatalogActions } from '$components/common/catalog/utils';

const DatasetModal = styled(Modal)`
z-index: ${themeVal('zIndices.modal')};
Expand Down Expand Up @@ -92,8 +93,10 @@ export function DatasetSelectorModal(props: DatasetSelectorModalProps) {
setTimelineDatasets(
reconcileDatasets(selectedIds, datasetLayers, timelineDatasets)
);
onAction(CatalogActions.CLEAR_SEARCH);
onAction(CatalogActions.CLEAR_TAXONOMY);
close();
}, [close, selectedIds, timelineDatasets, setTimelineDatasets]);
}, [close, selectedIds, timelineDatasets, setTimelineDatasets, onAction]);

return (
<DatasetModal
Expand Down

0 comments on commit d177321

Please sign in to comment.