navModel.test.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { NavIndex } from '@grafana/data';
  2. import { reducerTester } from '../../../test/core/redux/reducerTester';
  3. import { navIndexReducer, updateNavIndex, updateConfigurationSubtitle } from './navModel';
  4. describe('navModelReducer', () => {
  5. describe('when updateNavIndex is dispatched', () => {
  6. it('then state should be correct', () => {
  7. reducerTester<NavIndex>()
  8. .givenReducer(navIndexReducer, {})
  9. .whenActionIsDispatched(
  10. updateNavIndex({
  11. id: 'parent',
  12. text: 'Some Text',
  13. children: [
  14. {
  15. id: 'child',
  16. text: 'Child',
  17. },
  18. ],
  19. })
  20. )
  21. .thenStateShouldEqual({
  22. child: {
  23. id: 'child',
  24. text: 'Child',
  25. parentItem: {
  26. id: 'parent',
  27. text: 'Some Text',
  28. children: [
  29. {
  30. id: 'child',
  31. text: 'Child',
  32. },
  33. ],
  34. },
  35. },
  36. });
  37. });
  38. });
  39. describe('when updateConfigurationSubtitle is dispatched', () => {
  40. it('then state should be correct', () => {
  41. const originalCfg = { id: 'cfg', subTitle: 'Organization: Org 1', text: 'Configuration' };
  42. const datasources = { id: 'datasources', text: 'Data Sources' };
  43. const users = { id: 'users', text: 'Users' };
  44. const teams = { id: 'teams', text: 'Teams' };
  45. const plugins = { id: 'plugins', text: 'Plugins' };
  46. const orgsettings = { id: 'org-settings', text: 'Preferences' };
  47. const apikeys = { id: 'apikeys', text: 'API Keys' };
  48. const initialState = {
  49. cfg: { ...originalCfg, children: [datasources, users, teams, plugins, orgsettings, apikeys] },
  50. datasources: { ...datasources, parentItem: originalCfg },
  51. users: { ...users, parentItem: originalCfg },
  52. teams: { ...teams, parentItem: originalCfg },
  53. plugins: { ...plugins, parentItem: originalCfg },
  54. 'org-settings': { ...orgsettings, parentItem: originalCfg },
  55. apikeys: { ...apikeys, parentItem: originalCfg },
  56. };
  57. const newOrgName = 'Org 2';
  58. const subTitle = `Organization: ${newOrgName}`;
  59. const newCfg = { ...originalCfg, subTitle };
  60. const expectedState = {
  61. cfg: { ...newCfg, children: [datasources, users, teams, plugins, orgsettings, apikeys] },
  62. datasources: { ...datasources, parentItem: newCfg },
  63. users: { ...users, parentItem: newCfg },
  64. teams: { ...teams, parentItem: newCfg },
  65. plugins: { ...plugins, parentItem: newCfg },
  66. 'org-settings': { ...orgsettings, parentItem: newCfg },
  67. apikeys: { ...apikeys, parentItem: newCfg },
  68. };
  69. reducerTester<NavIndex>()
  70. .givenReducer(navIndexReducer, { ...initialState })
  71. .whenActionIsDispatched(updateConfigurationSubtitle(newOrgName))
  72. .thenStateShouldEqual(expectedState);
  73. });
  74. });
  75. });