Files
grafana/public/app/core/reducers/root.test.ts
Torkel Ödegaard 11de1dfe40 TopNav: Plugin page layouts / information architecture (#53174)
* Change nav structure when topnav is enable to do initial tests with new information architecture

* Support for nested sections

* Updated

* sentance case

* Progress on plugin challange

* Rewrite to functional component

* Progress

* Updates

* Progress

* Progress on things

* missing file

* Fixing issue with runtime, need to use setter way to set component exposed via runtime

* Move PageLayoutType to grafana/data

* Fixing breadcrumb issue, adding more tests

* reverted backend change

* fix recursive issue with cleanup
2022-09-05 14:56:08 +02:00

68 lines
2.0 KiB
TypeScript

import { reducerTester } from '../../../test/core/redux/reducerTester';
import { initialTeamsState, teamsLoaded } from '../../features/teams/state/reducers';
import { Team } from '../../types';
import { StoreState } from '../../types/store';
import { cleanUpAction } from '../actions/cleanUp';
import { createRootReducer } from './root';
jest.mock('@grafana/runtime', () => ({
...(jest.requireActual('@grafana/runtime') as unknown as object),
config: {
bootData: {
navTree: [],
user: {},
},
},
}));
describe('rootReducer', () => {
const rootReducer = createRootReducer();
describe('when called with any action except cleanUpAction', () => {
it('then it should not clean state', () => {
const teams = [{ id: 1 } as Team];
const state = {
teams: { ...initialTeamsState },
} as StoreState;
reducerTester<StoreState>()
.givenReducer(rootReducer, state)
.whenActionIsDispatched(teamsLoaded(teams))
.thenStatePredicateShouldEqual((resultingState) => {
expect(resultingState.teams).toEqual({
hasFetched: true,
searchQuery: '',
searchPage: 1,
teams,
});
return true;
});
});
});
describe('when called with cleanUpAction', () => {
it('then it should clean state', () => {
const teams = [{ id: 1 }] as Team[];
const state: StoreState = {
teams: {
hasFetched: true,
searchQuery: '',
searchPage: 1,
teams,
},
} as StoreState;
reducerTester<StoreState>()
.givenReducer(rootReducer, state, false, true)
.whenActionIsDispatched(
cleanUpAction({ cleanupAction: (storeState) => (storeState.teams = initialTeamsState) })
)
.thenStatePredicateShouldEqual((resultingState) => {
expect(resultingState.teams).toEqual({ ...initialTeamsState });
return true;
});
});
});
});