grafana/public/app/core/reducers/navModel.test.ts
Giordano Ricci c68d7f1e35
Correlations: Add CorrelationSettings Page (#53821)
* GrafanaUI: add option to close DeleteButton on confirm click

* add datasource readOnly info to frontend settings

* move isTruthy utility type guard

* add generic non-visualization table component

* Add correlations settings page

* add missing readOnly in mock

* Fix typo

* avoid reloading correlations after add/remove

* use DeepPartial from rhf

* validate source data source

* fix validation logic

* fix navmodel test

* add missing readonly property

* remove unused styles

* handle multiple clicks on elements

* better UX for loading states

* fix remove handler

* add glue icon
2022-08-26 11:27:28 +01:00

86 lines
3.1 KiB
TypeScript

import { NavIndex } from '@grafana/data';
import { reducerTester } from '../../../test/core/redux/reducerTester';
import { navIndexReducer, updateNavIndex, updateConfigurationSubtitle } from './navModel';
describe('navModelReducer', () => {
describe('when updateNavIndex is dispatched', () => {
it('then state should be correct', () => {
reducerTester<NavIndex>()
.givenReducer(navIndexReducer, {})
.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',
},
],
},
},
});
});
});
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' };
const correlations = { id: 'correlations', text: 'Correlations' };
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 },
correlations: { ...correlations, parentItem: originalCfg },
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 },
correlations: { ...correlations, parentItem: newCfg },
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);
});
});
});