2022-04-22 08:33:13 -05:00
|
|
|
import { NavIndex } from '@grafana/data';
|
|
|
|
|
2020-01-13 01:03:22 -06:00
|
|
|
import { reducerTester } from '../../../test/core/redux/reducerTester';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2020-08-07 02:00:44 -05:00
|
|
|
import { navIndexReducer, updateNavIndex, updateConfigurationSubtitle } from './navModel';
|
2020-01-13 01:03:22 -06:00
|
|
|
|
2020-08-07 02:00:44 -05:00
|
|
|
describe('navModelReducer', () => {
|
2020-01-13 01:03:22 -06:00
|
|
|
describe('when updateNavIndex is dispatched', () => {
|
|
|
|
it('then state should be correct', () => {
|
2020-01-28 02:13:56 -06:00
|
|
|
reducerTester<NavIndex>()
|
2020-08-07 02:00:44 -05:00
|
|
|
.givenReducer(navIndexReducer, {})
|
2020-01-13 01:03:22 -06:00
|
|
|
.whenActionIsDispatched(
|
|
|
|
updateNavIndex({
|
|
|
|
id: 'parent',
|
|
|
|
text: 'Some Text',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
id: 'child',
|
|
|
|
text: 'Child',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.thenStateShouldEqual({
|
|
|
|
child: {
|
|
|
|
id: 'child',
|
|
|
|
text: 'Child',
|
|
|
|
parentItem: {
|
|
|
|
id: 'parent',
|
|
|
|
text: 'Some Text',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
id: 'child',
|
|
|
|
text: 'Child',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-08-07 02:00:44 -05:00
|
|
|
|
|
|
|
describe('when updateConfigurationSubtitle is dispatched', () => {
|
|
|
|
it('then state should be correct', () => {
|
|
|
|
const originalCfg = { id: 'cfg', subTitle: 'Organization: Org 1', text: 'Configuration' };
|
|
|
|
const datasources = { id: 'datasources', text: 'Data Sources' };
|
2022-08-26 05:27:28 -05:00
|
|
|
const correlations = { id: 'correlations', text: 'Correlations' };
|
2020-08-07 02:00:44 -05:00
|
|
|
const users = { id: 'users', text: 'Users' };
|
|
|
|
const teams = { id: 'teams', text: 'Teams' };
|
|
|
|
const plugins = { id: 'plugins', text: 'Plugins' };
|
|
|
|
const orgsettings = { id: 'org-settings', text: 'Preferences' };
|
|
|
|
const apikeys = { id: 'apikeys', text: 'API Keys' };
|
|
|
|
|
|
|
|
const initialState = {
|
|
|
|
cfg: { ...originalCfg, children: [datasources, users, teams, plugins, orgsettings, apikeys] },
|
|
|
|
datasources: { ...datasources, parentItem: originalCfg },
|
2022-08-26 05:27:28 -05:00
|
|
|
correlations: { ...correlations, parentItem: originalCfg },
|
2020-08-07 02:00:44 -05:00
|
|
|
users: { ...users, parentItem: originalCfg },
|
|
|
|
teams: { ...teams, parentItem: originalCfg },
|
|
|
|
plugins: { ...plugins, parentItem: originalCfg },
|
|
|
|
'org-settings': { ...orgsettings, parentItem: originalCfg },
|
|
|
|
apikeys: { ...apikeys, parentItem: originalCfg },
|
|
|
|
};
|
|
|
|
|
|
|
|
const newOrgName = 'Org 2';
|
|
|
|
const subTitle = `Organization: ${newOrgName}`;
|
|
|
|
const newCfg = { ...originalCfg, subTitle };
|
|
|
|
const expectedState = {
|
|
|
|
cfg: { ...newCfg, children: [datasources, users, teams, plugins, orgsettings, apikeys] },
|
|
|
|
datasources: { ...datasources, parentItem: newCfg },
|
2022-08-26 05:27:28 -05:00
|
|
|
correlations: { ...correlations, parentItem: newCfg },
|
2020-08-07 02:00:44 -05:00
|
|
|
users: { ...users, parentItem: newCfg },
|
|
|
|
teams: { ...teams, parentItem: newCfg },
|
|
|
|
plugins: { ...plugins, parentItem: newCfg },
|
|
|
|
'org-settings': { ...orgsettings, parentItem: newCfg },
|
|
|
|
apikeys: { ...apikeys, parentItem: newCfg },
|
|
|
|
};
|
|
|
|
|
|
|
|
reducerTester<NavIndex>()
|
|
|
|
.givenReducer(navIndexReducer, { ...initialState })
|
|
|
|
.whenActionIsDispatched(updateConfigurationSubtitle(newOrgName))
|
|
|
|
.thenStateShouldEqual(expectedState);
|
|
|
|
});
|
|
|
|
});
|
2020-01-13 01:03:22 -06:00
|
|
|
});
|