forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: table search filter (openedx#683)
- Loading branch information
1 parent
1ee80b6
commit ce9db57
Showing
4 changed files
with
165 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/files-and-videos/generic/table-components/utils.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { getCurrentViewRange, getFilters, removeFilter } from './utils'; | ||
|
||
describe('getCurrentViewRange', () => { | ||
const intl = { | ||
formatMessage: (name, { fileCount, rowCount }) => ( | ||
`Showing ${fileCount} of ${rowCount}` | ||
), | ||
}; | ||
|
||
it('should return with intials row count', () => { | ||
const data = { | ||
filterRowCount: 25, | ||
initialRowCount: 25, | ||
fileCount: 12, | ||
intl, | ||
}; | ||
const expected = 'Showing 12 of 25'; | ||
const actual = getCurrentViewRange(data); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should return with filter row count', () => { | ||
const data = { | ||
filterRowCount: 12, | ||
initialRowCount: 25, | ||
fileCount: 12, | ||
intl, | ||
}; | ||
const expected = 'Showing 12 of 12'; | ||
const actual = getCurrentViewRange(data); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('getFilters', () => { | ||
it('should return filter when columns is empty', () => { | ||
const state = { filters: [{ id: 'test', value: ['unknown'] }] }; | ||
const columns = []; | ||
const expected = [{ name: 'unknown', value: 'unknown' }]; | ||
const actual = getFilters(state, columns); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should return filtern for specific column', () => { | ||
const state = { filters: [{ id: 'validColumn', value: ['filter1'] }] }; | ||
const columns = [{ | ||
id: 'validColumn', | ||
filterChoices: [ | ||
{ name: 'Filter 1', value: 'filter1' }, | ||
{ name: 'Filter 2', value: 'filter2' }, | ||
], | ||
}]; | ||
const expected = [{ name: 'Filter 1', value: 'filter1' }]; | ||
const acutal = getFilters(state, columns); | ||
|
||
expect(acutal).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('removeFilter', () => { | ||
const setAllFilters = jest.fn(); | ||
const setFilter = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('state filter.value is an array', () => { | ||
it('should call setAllFilters', () => { | ||
const state = { | ||
filters: [ | ||
{ id: 'test', value: ['filter1'] }, | ||
], | ||
}; | ||
const filter = 'filter1'; | ||
removeFilter(filter, setFilter, setAllFilters, state); | ||
|
||
expect(setAllFilters).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call setFilter', () => { | ||
const state = { | ||
filters: [ | ||
{ id: 'test', value: ['filter1', 'filter2'] }, | ||
], | ||
}; | ||
const filter = 'filter1'; | ||
removeFilter(filter, setFilter, setAllFilters, state); | ||
|
||
expect(setFilter).toHaveBeenCalled(); | ||
}); | ||
}); | ||
describe('state filter.value is not an array', () => { | ||
it('should call setAllFilters', () => { | ||
const state = { | ||
filters: [ | ||
{ id: 'test', value: 'filter1' }, | ||
], | ||
}; | ||
const filter = 'filter1'; | ||
removeFilter(filter, setFilter, setAllFilters, state); | ||
|
||
expect(setAllFilters).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |