reducer.test.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { reducerTester } from '../../../../../test/core/redux/reducerTester';
  2. import {
  3. folderFilterChanged,
  4. initialLibraryPanelsSearchState,
  5. libraryPanelsSearchReducer,
  6. LibraryPanelsSearchState,
  7. panelFilterChanged,
  8. searchChanged,
  9. sortChanged,
  10. } from './reducer';
  11. describe('libraryPanelsSearchReducer', () => {
  12. describe('when searchChanged is dispatched', () => {
  13. it('then state should be correct', () => {
  14. reducerTester<LibraryPanelsSearchState>()
  15. .givenReducer(libraryPanelsSearchReducer, {
  16. ...initialLibraryPanelsSearchState,
  17. })
  18. .whenActionIsDispatched(searchChanged('searching for'))
  19. .thenStateShouldEqual({
  20. ...initialLibraryPanelsSearchState,
  21. searchQuery: 'searching for',
  22. });
  23. });
  24. });
  25. describe('when sortChanged is dispatched', () => {
  26. it('then state should be correct', () => {
  27. reducerTester<LibraryPanelsSearchState>()
  28. .givenReducer(libraryPanelsSearchReducer, {
  29. ...initialLibraryPanelsSearchState,
  30. })
  31. .whenActionIsDispatched(sortChanged({ label: 'Ascending', value: 'asc' }))
  32. .thenStateShouldEqual({
  33. ...initialLibraryPanelsSearchState,
  34. sortDirection: 'asc',
  35. });
  36. });
  37. });
  38. describe('when panelFilterChanged is dispatched', () => {
  39. it('then state should be correct', () => {
  40. const plugins: any = [
  41. { id: 'graph', name: 'Graph' },
  42. { id: 'timeseries', name: 'Time Series' },
  43. ];
  44. reducerTester<LibraryPanelsSearchState>()
  45. .givenReducer(libraryPanelsSearchReducer, {
  46. ...initialLibraryPanelsSearchState,
  47. })
  48. .whenActionIsDispatched(panelFilterChanged(plugins))
  49. .thenStateShouldEqual({
  50. ...initialLibraryPanelsSearchState,
  51. panelFilter: ['graph', 'timeseries'],
  52. });
  53. });
  54. });
  55. describe('when folderFilterChanged is dispatched', () => {
  56. it('then state should be correct', () => {
  57. const folders: any = [
  58. { id: 0, name: 'General' },
  59. { id: 1, name: 'Folder' },
  60. ];
  61. reducerTester<LibraryPanelsSearchState>()
  62. .givenReducer(libraryPanelsSearchReducer, {
  63. ...initialLibraryPanelsSearchState,
  64. })
  65. .whenActionIsDispatched(folderFilterChanged(folders))
  66. .thenStateShouldEqual({
  67. ...initialLibraryPanelsSearchState,
  68. folderFilter: ['0', '1'],
  69. });
  70. });
  71. });
  72. });