grafana/public/app/features/dashboard/state/reducers.test.ts

72 lines
2.2 KiB
TypeScript
Raw Normal View History

2019-02-07 06:58:24 -06:00
import {
loadDashboardPermissions,
dashboardInitFetching,
dashboardInitCompleted,
dashboardInitFailed,
dashboardInitSlow,
} from './actions';
import { OrgRole, PermissionLevel, DashboardState, DashboardInitPhase } from 'app/types';
2018-10-25 09:56:49 -05:00
import { initialState, dashboardReducer } from './reducers';
2019-02-07 06:58:24 -06:00
import { DashboardModel } from './DashboardModel';
2018-09-14 01:25:35 -05:00
describe('dashboard reducer', () => {
describe('loadDashboardPermissions', () => {
let state: DashboardState;
beforeEach(() => {
const action = loadDashboardPermissions([
{ id: 2, dashboardId: 1, role: OrgRole.Viewer, permission: PermissionLevel.View },
{ id: 3, dashboardId: 1, role: OrgRole.Editor, permission: PermissionLevel.Edit },
]);
2018-10-25 09:56:49 -05:00
state = dashboardReducer(initialState, action);
2018-09-14 01:25:35 -05:00
});
it('should add permissions to state', async () => {
expect(state.permissions.length).toBe(2);
});
});
2019-02-07 06:58:24 -06:00
describe('dashboardInitCompleted', () => {
let state: DashboardState;
beforeEach(() => {
state = dashboardReducer(initialState, dashboardInitFetching());
state = dashboardReducer(state, dashboardInitSlow());
state = dashboardReducer(state, dashboardInitCompleted(new DashboardModel({ title: 'My dashboard' })));
});
it('should set model', async () => {
expect(state.model.title).toBe('My dashboard');
});
it('should set reset isInitSlow', async () => {
expect(state.isInitSlow).toBe(false);
});
});
describe('dashboardInitFailed', () => {
let state: DashboardState;
beforeEach(() => {
state = dashboardReducer(initialState, dashboardInitFetching());
state = dashboardReducer(state, dashboardInitFailed({ message: 'Oh no', error: 'sad' }));
2019-02-07 06:58:24 -06:00
});
it('should set model', async () => {
expect(state.model.title).toBe('Dashboard init failed');
});
it('should set reset isInitSlow', async () => {
expect(state.isInitSlow).toBe(false);
});
it('should set initError', async () => {
expect(state.initError.message).toBe('Oh no');
});
it('should set phase failed', async () => {
expect(state.initPhase).toBe(DashboardInitPhase.Failed);
});
});
2018-09-14 01:25:35 -05:00
});