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