From 84dd79003e60e0642b56ff2252957008da788687 Mon Sep 17 00:00:00 2001 From: megli2 Date: Fri, 8 Dec 2023 10:34:10 +0100 Subject: [PATCH 1/3] begin with writing tests --- frontend/src/app/shared/services/overview.service.spec.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/shared/services/overview.service.spec.ts b/frontend/src/app/shared/services/overview.service.spec.ts index ec99a7031a..05ccdb222b 100644 --- a/frontend/src/app/shared/services/overview.service.spec.ts +++ b/frontend/src/app/shared/services/overview.service.spec.ts @@ -4,8 +4,7 @@ import { OverviewService } from './overview.service'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { of } from 'rxjs'; import { HttpClient } from '@angular/common/http'; -import { State } from '../types/enums/State'; -import { overViewEntity1, quarter } from '../testData'; +import { overViewEntity1 } from '../testData'; const httpClient = { get: jest.fn(), @@ -28,4 +27,6 @@ describe('OverviewService', () => { it('should be created', () => { expect(service).toBeTruthy(); }); + + it('should set state of objectives correctly', () => {}); }); From 01ff9258404760087ec616a9f4f4ce881aeb8212 Mon Sep 17 00:00:00 2001 From: megli2 Date: Fri, 8 Dec 2023 10:53:26 +0100 Subject: [PATCH 2/3] implement test to check if state of objectives is set correctly --- .../src/app/shared/services/overview.service.spec.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/shared/services/overview.service.spec.ts b/frontend/src/app/shared/services/overview.service.spec.ts index 05ccdb222b..448bc85549 100644 --- a/frontend/src/app/shared/services/overview.service.spec.ts +++ b/frontend/src/app/shared/services/overview.service.spec.ts @@ -5,6 +5,7 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { of } from 'rxjs'; import { HttpClient } from '@angular/common/http'; import { overViewEntity1 } from '../testData'; +import { State } from '../types/enums/State'; const httpClient = { get: jest.fn(), @@ -28,5 +29,12 @@ describe('OverviewService', () => { expect(service).toBeTruthy(); }); - it('should set state of objectives correctly', () => {}); + it('should set state of objectives correctly', (done) => { + service.getOverview().subscribe((dashboard) => { + dashboard.overviews.forEach((overview) => + overview.objectives.forEach((objective) => expect(typeof objective.state).toBe(State)), + ); + done(); + }); + }); }); From c5c97c41abd7131eb88758f0a6f79fa2cd5cfc6f Mon Sep 17 00:00:00 2001 From: megli2 Date: Fri, 8 Dec 2023 12:02:41 +0100 Subject: [PATCH 3/3] implement test which checks if states of objectives were set correctly --- .../shared/services/overview.service.spec.ts | 9 +-- frontend/src/app/shared/testData.ts | 55 +++++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/shared/services/overview.service.spec.ts b/frontend/src/app/shared/services/overview.service.spec.ts index 448bc85549..3a8c83b35d 100644 --- a/frontend/src/app/shared/services/overview.service.spec.ts +++ b/frontend/src/app/shared/services/overview.service.spec.ts @@ -4,8 +4,7 @@ import { OverviewService } from './overview.service'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { of } from 'rxjs'; import { HttpClient } from '@angular/common/http'; -import { overViewEntity1 } from '../testData'; -import { State } from '../types/enums/State'; +import { dashboard } from '../testData'; const httpClient = { get: jest.fn(), @@ -20,9 +19,6 @@ describe('OverviewService', () => { providers: [{ provide: HttpClient, useValue: httpClient }], }).compileComponents(); service = TestBed.inject(OverviewService); - httpClient.get.mockReturnValue( - of([{ ...overViewEntity1, objectives: { ...overViewEntity1.objectives[0], state: 'DRAFT' } }]), - ); }); it('should be created', () => { @@ -30,9 +26,10 @@ describe('OverviewService', () => { }); it('should set state of objectives correctly', (done) => { + jest.spyOn(httpClient, 'get').mockReturnValue(of(dashboard)); service.getOverview().subscribe((dashboard) => { dashboard.overviews.forEach((overview) => - overview.objectives.forEach((objective) => expect(typeof objective.state).toBe(State)), + overview.objectives.forEach((objective) => expect(typeof objective.state).toBe('string')), ); done(); }); diff --git a/frontend/src/app/shared/testData.ts b/frontend/src/app/shared/testData.ts index 3146cb7eb2..a61fbaaa62 100644 --- a/frontend/src/app/shared/testData.ts +++ b/frontend/src/app/shared/testData.ts @@ -19,6 +19,7 @@ import { Team } from './types/model/Team'; import { Action } from './types/model/Action'; import { OrganisationState } from './types/enums/OrganisationState'; import { Organisation } from './types/model/Organisation'; +import { Dashboard } from './types/model/Dashboard'; export const organisationActive = { id: 1, @@ -241,6 +242,43 @@ export const objectiveMin: ObjectiveMin = { quarter: quarterMin, keyResults: [keyResultMetricMin, keyResultOrdinalMin] as KeyresultMin[], } as ObjectiveMin; + +export const objectiveResponse1: any = { + id: 101, + version: 1, + title: 'Increase Environment Engagement', + state: 'ONGOING', + quarter: quarterMin, + keyResults: [keyResultMetricMin, keyResultOrdinalMin] as KeyresultMin[], +}; + +export const objectiveResponse2: any = { + id: 102, + version: 1, + title: 'Increase Social Engagement', + state: 'DRAFT', + quarter: quarterMin, + keyResults: [keyResultMetricMin, keyResultOrdinalMin] as KeyresultMin[], +}; + +export const objectiveResponse3: any = { + id: 103, + version: 1, + title: 'Increase Member Engagement', + state: 'NOTSUCCESSFUL', + quarter: quarterMin, + keyResults: [keyResultMetricMin, keyResultOrdinalMin] as KeyresultMin[], +}; + +export const objectiveResponse4: any = { + id: 104, + version: 1, + title: 'Increase Company Engagement', + state: 'SUCCESSFUL', + quarter: quarterMin, + keyResults: [keyResultMetricMin, keyResultOrdinalMin] as KeyresultMin[], +}; + export const overViewEntity1: OverviewEntity = { team: teamMin1, objectives: [objectiveMin, objectiveMin, objectiveMin] as ObjectiveMin[], @@ -253,6 +291,23 @@ export const overViewEntity2: OverviewEntity = { writable: true, }; +export const overViewEntityResponse1: any = { + team: team1, + objectives: [objectiveResponse1, objectiveResponse2], + writable: true, +}; + +export const overViewEntityResponse2: any = { + team: team2, + objectives: [objectiveResponse3, objectiveResponse4], + writable: false, +}; + +export const dashboard: Dashboard = { + overviews: [overViewEntityResponse1, overViewEntityResponse2], + adminAccess: true, +}; + export const quarter: Quarter = { id: 1, label: '23.02.2025',