From 2eca4caa5dc39235ca6f943857903b5d90d19362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 7 Feb 2019 13:58:24 +0100 Subject: [PATCH] added reducers tests --- .../features/dashboard/state/reducers.test.ts | 54 ++++++++++++++++++- public/app/types/dashboard.ts | 3 +- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/public/app/features/dashboard/state/reducers.test.ts b/public/app/features/dashboard/state/reducers.test.ts index b96666019ba..800ba27e800 100644 --- a/public/app/features/dashboard/state/reducers.test.ts +++ b/public/app/features/dashboard/state/reducers.test.ts @@ -1,6 +1,13 @@ -import { loadDashboardPermissions } from './actions'; -import { OrgRole, PermissionLevel, DashboardState } from 'app/types'; +import { + loadDashboardPermissions, + dashboardInitFetching, + dashboardInitCompleted, + dashboardInitFailed, + dashboardInitSlow, +} from './actions'; +import { OrgRole, PermissionLevel, DashboardState, DashboardInitPhase } from 'app/types'; import { initialState, dashboardReducer } from './reducers'; +import { DashboardModel } from './DashboardModel'; describe('dashboard reducer', () => { describe('loadDashboardPermissions', () => { @@ -18,4 +25,47 @@ describe('dashboard reducer', () => { expect(state.permissions.length).toBe(2); }); }); + + 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'})); + }); + + 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); + }); + }); }); diff --git a/public/app/types/dashboard.ts b/public/app/types/dashboard.ts index 9bcf258cf76..d81f9e2bcba 100644 --- a/public/app/types/dashboard.ts +++ b/public/app/types/dashboard.ts @@ -1,6 +1,7 @@ import { DashboardAcl } from './acl'; export interface MutableDashboard { + title: string; meta: DashboardMeta; destroy: () => void; } @@ -27,7 +28,7 @@ export interface DashboardMeta { focusPanelId?: boolean; isStarred?: boolean; showSettings?: boolean; - expires: string; + expires?: string; isSnapshot?: boolean; folderTitle?: string; folderUrl?: string;