2019-02-07 06:58:24 -06:00
|
|
|
import {
|
|
|
|
dashboardInitCompleted,
|
|
|
|
dashboardInitFailed,
|
2020-01-28 02:13:56 -06:00
|
|
|
dashboardInitFetching,
|
2019-02-07 06:58:24 -06:00
|
|
|
dashboardInitSlow,
|
2020-01-28 02:13:56 -06:00
|
|
|
loadDashboardPermissions,
|
2021-02-11 06:45:25 -06:00
|
|
|
dashboardReducer,
|
|
|
|
initialState,
|
2020-02-09 02:45:50 -06:00
|
|
|
} from './reducers';
|
2020-01-28 02:13:56 -06:00
|
|
|
import { DashboardInitPhase, DashboardState, OrgRole, PermissionLevel } from 'app/types';
|
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(() => {
|
2019-02-05 08:58:09 -06:00
|
|
|
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 () => {
|
2020-01-28 02:13:56 -06:00
|
|
|
expect(state.permissions?.length).toBe(2);
|
2018-09-14 01:25:35 -05:00
|
|
|
});
|
|
|
|
});
|
2019-02-07 06:58:24 -06:00
|
|
|
|
|
|
|
describe('dashboardInitCompleted', () => {
|
|
|
|
let state: DashboardState;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = dashboardReducer(initialState, dashboardInitFetching());
|
|
|
|
state = dashboardReducer(state, dashboardInitSlow());
|
2020-02-10 07:23:54 -06:00
|
|
|
state = dashboardReducer(
|
|
|
|
state,
|
|
|
|
dashboardInitCompleted(
|
|
|
|
new DashboardModel({
|
|
|
|
title: 'My dashboard',
|
|
|
|
panels: [{ id: 1 }, { id: 2 }],
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
2019-02-07 06:58:24 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should set model', async () => {
|
2020-02-09 02:45:50 -06:00
|
|
|
expect(state.getModel()!.title).toBe('My dashboard');
|
2019-02-07 06:58:24 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should set reset isInitSlow', async () => {
|
|
|
|
expect(state.isInitSlow).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('dashboardInitFailed', () => {
|
|
|
|
let state: DashboardState;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = dashboardReducer(initialState, dashboardInitFetching());
|
2019-02-13 04:14:53 -06:00
|
|
|
state = dashboardReducer(state, dashboardInitFailed({ message: 'Oh no', error: 'sad' }));
|
2019-02-07 06:58:24 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should set model', async () => {
|
2020-02-09 02:45:50 -06:00
|
|
|
expect(state.getModel()?.title).toBe('Dashboard init failed');
|
2019-02-07 06:58:24 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should set reset isInitSlow', async () => {
|
|
|
|
expect(state.isInitSlow).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set initError', async () => {
|
2020-01-28 02:13:56 -06:00
|
|
|
expect(state.initError?.message).toBe('Oh no');
|
2019-02-07 06:58:24 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should set phase failed', async () => {
|
|
|
|
expect(state.initPhase).toBe(DashboardInitPhase.Failed);
|
|
|
|
});
|
|
|
|
});
|
2018-09-14 01:25:35 -05:00
|
|
|
});
|