grafana/public/app/features/library-panels/components/LibraryPanelsSearch/reducer.test.ts
Hugo Häggmark c6d4d14a89
LibraryPanels: Adds folder filter to manage library panel page (#33560)
* LibraryPanels: Adds folder filter

* Refactor: Adds folder filter to library search

* Refactor: splits huge function into smaller functions

* LibraryPanels: Adds Panels Page to Manage Folder tabs (#33618)

* Chore: adds tests to LibraryPanelsSearch

* Refactor: Adds reducer and tests

* Chore: changes GrafanaThemeV2

* Refactor: pulls everything behind the feature toggle

* Chore: removes clear icon from FolderFilter

* Chore: adds filter to SortPicker

* Refactor: using useAsync instead
2021-05-04 13:59:40 +02:00

77 lines
2.4 KiB
TypeScript

import { reducerTester } from '../../../../../test/core/redux/reducerTester';
import {
folderFilterChanged,
initialLibraryPanelsSearchState,
libraryPanelsSearchReducer,
LibraryPanelsSearchState,
panelFilterChanged,
searchChanged,
sortChanged,
} from './reducer';
describe('libraryPanelsSearchReducer', () => {
describe('when searchChanged is dispatched', () => {
it('then state should be correct', () => {
reducerTester<LibraryPanelsSearchState>()
.givenReducer(libraryPanelsSearchReducer, {
...initialLibraryPanelsSearchState,
})
.whenActionIsDispatched(searchChanged('searching for'))
.thenStateShouldEqual({
...initialLibraryPanelsSearchState,
searchQuery: 'searching for',
});
});
});
describe('when sortChanged is dispatched', () => {
it('then state should be correct', () => {
reducerTester<LibraryPanelsSearchState>()
.givenReducer(libraryPanelsSearchReducer, {
...initialLibraryPanelsSearchState,
})
.whenActionIsDispatched(sortChanged({ label: 'Ascending', value: 'asc' }))
.thenStateShouldEqual({
...initialLibraryPanelsSearchState,
sortDirection: 'asc',
});
});
});
describe('when panelFilterChanged is dispatched', () => {
it('then state should be correct', () => {
const plugins: any = [
{ id: 'graph', name: 'Graph' },
{ id: 'timeseries', name: 'Time Series' },
];
reducerTester<LibraryPanelsSearchState>()
.givenReducer(libraryPanelsSearchReducer, {
...initialLibraryPanelsSearchState,
})
.whenActionIsDispatched(panelFilterChanged(plugins))
.thenStateShouldEqual({
...initialLibraryPanelsSearchState,
panelFilter: ['graph', 'timeseries'],
});
});
});
describe('when folderFilterChanged is dispatched', () => {
it('then state should be correct', () => {
const folders: any = [
{ id: 0, name: 'General' },
{ id: 1, name: 'Folder' },
];
reducerTester<LibraryPanelsSearchState>()
.givenReducer(libraryPanelsSearchReducer, {
...initialLibraryPanelsSearchState,
})
.whenActionIsDispatched(folderFilterChanged(folders))
.thenStateShouldEqual({
...initialLibraryPanelsSearchState,
folderFilter: ['0', '1'],
});
});
});
});