Skip to content

Commit

Permalink
implement test which checks if states of objectives were set correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Vakmeth committed Dec 8, 2023
1 parent 01ff925 commit c5c97c4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
9 changes: 3 additions & 6 deletions frontend/src/app/shared/services/overview.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -20,19 +19,17 @@ 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', () => {
expect(service).toBeTruthy();
});

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();
});
Expand Down
55 changes: 55 additions & 0 deletions frontend/src/app/shared/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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[],
Expand All @@ -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',
Expand Down

0 comments on commit c5c97c4

Please sign in to comment.