Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/511 overview service test #678

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 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 { State } from '../types/enums/State';
import { overViewEntity1, quarter } from '../testData';
import { dashboard } from '../testData';

const httpClient = {
get: jest.fn(),
Expand All @@ -20,12 +19,19 @@ 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('string')),
);
done();
});
});
});
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
Loading