-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: makes Add filter button's display conditional (#1677)
* hides Add filter button in dashboard control bar if no allowed filters * adds related unit tests Co-authored-by: Jen Jones Arnesen <[email protected]>
- Loading branch information
1 parent
11e17cb
commit 8ce4b51
Showing
2 changed files
with
76 additions
and
1 deletion.
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
75 changes: 75 additions & 0 deletions
75
src/components/ItemFilter/__tests__/FilterSelector.spec.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,75 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import { Provider } from 'react-redux' | ||
import configureMockStore from 'redux-mock-store' | ||
|
||
import FilterSelector from '../FilterSelector' | ||
import useDimensions from '../../../modules/useDimensions' | ||
|
||
const mockStore = configureMockStore() | ||
|
||
jest.mock('../../../modules/useDimensions', () => jest.fn()) | ||
useDimensions.mockImplementation(() => ['Moomin', 'Snorkmaiden']) | ||
|
||
test('is null when no filters are restricted and no filters are allowed', () => { | ||
const store = {} | ||
|
||
const props = { | ||
allowedFilters: [], | ||
restrictFilters: true, | ||
} | ||
|
||
const { container } = render( | ||
<Provider store={mockStore(store)}> | ||
<FilterSelector {...props} /> | ||
</Provider> | ||
) | ||
expect(container.firstChild).toBeNull() | ||
}) | ||
|
||
test('is null when no filters are restricted and allowedFilters undefined', () => { | ||
const store = {} | ||
|
||
const props = { | ||
restrictFilters: true, | ||
} | ||
|
||
const { container } = render( | ||
<Provider store={mockStore(store)}> | ||
<FilterSelector {...props} /> | ||
</Provider> | ||
) | ||
expect(container.firstChild).toBeNull() | ||
}) | ||
|
||
test('shows button when filters are restricted and at least one filter is allowed', () => { | ||
const store = {} | ||
|
||
const props = { | ||
allowedFilters: ['Moomin'], | ||
restrictFilters: true, | ||
} | ||
|
||
render( | ||
<Provider store={mockStore(store)}> | ||
<FilterSelector {...props} /> | ||
</Provider> | ||
) | ||
expect(screen.getByRole('button')).toBeTruthy() | ||
}) | ||
|
||
test('shows button when filters are not restricted', () => { | ||
const store = {} | ||
|
||
const props = { | ||
allowedFilters: [], | ||
restrictFilters: false, | ||
} | ||
|
||
render( | ||
<Provider store={mockStore(store)}> | ||
<FilterSelector {...props} /> | ||
</Provider> | ||
) | ||
expect(screen.getByRole('button')).toBeTruthy() | ||
}) |