mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* TeamList: break out rows to its own component * TeamsState: Add total count * TeamList: Remove teamsCount prop * TeamList: Restructure code and use count from backend response * TeamList: calculate total pages using totalCount * TeamList: Rename to state to currentPage and the reducer to setCurrentPage * TeamList: remove wrapper functions * TeamList: rewrite as a functional component * TeamList: export components for test * TeamList: pass limit, page and query to backend * TeamList: Rename properties in state and create actions for page and query change * TeamList: Add flag to control if EmptyList banner should render
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') 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: 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;
|
|
});
|
|
});
|
|
});
|
|
});
|