reducer.test.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { LoadingState } from '@grafana/data';
  2. import { reducerTester } from '../../../../../test/core/redux/reducerTester';
  3. import {
  4. deleteLibraryPanelModalReducer,
  5. DeleteLibraryPanelModalState,
  6. initialDeleteLibraryPanelModalState,
  7. searchCompleted,
  8. } from './reducer';
  9. describe('deleteLibraryPanelModalReducer', () => {
  10. describe('when created', () => {
  11. it('then initial state should be correct', () => {
  12. reducerTester<DeleteLibraryPanelModalState>()
  13. .givenReducer(deleteLibraryPanelModalReducer, initialDeleteLibraryPanelModalState)
  14. .whenActionIsDispatched({ type: 'noop' })
  15. .thenStateShouldEqual({
  16. loadingState: LoadingState.Loading,
  17. dashboardTitles: [],
  18. });
  19. });
  20. });
  21. describe('when searchCompleted is dispatched', () => {
  22. it('then state should be correct', () => {
  23. const dashboards: any[] = [{ title: 'A' }, { title: 'B' }];
  24. reducerTester<DeleteLibraryPanelModalState>()
  25. .givenReducer(deleteLibraryPanelModalReducer, initialDeleteLibraryPanelModalState)
  26. .whenActionIsDispatched(searchCompleted({ dashboards }))
  27. .thenStateShouldEqual({
  28. loadingState: LoadingState.Done,
  29. dashboardTitles: ['A', 'B'],
  30. });
  31. });
  32. });
  33. });