mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 09:33:34 -06:00
* fix any's in tests * fix more any's in tests * more test type fixes * fixing any's in tests part 3 * more test type fixes * fixing test any's p5 * some tidy up * fix template_srv
74 lines
2.1 KiB
TypeScript
74 lines
2.1 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'),
|
|
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: teams, page: 1, noTeams: false, perPage: 30, totalCount: 1 }))
|
|
.thenStatePredicateShouldEqual((resultingState) => {
|
|
expect(resultingState.teams).toEqual({
|
|
hasFetched: true,
|
|
noTeams: false,
|
|
perPage: 30,
|
|
totalPages: 1,
|
|
query: '',
|
|
page: 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,
|
|
query: '',
|
|
page: 1,
|
|
noTeams: false,
|
|
totalPages: 1,
|
|
perPage: 30,
|
|
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;
|
|
});
|
|
});
|
|
});
|
|
});
|