From 8973b3a35de46148f46fd4048b90f673910aba0b Mon Sep 17 00:00:00 2001 From: Sabrina Date: Mon, 9 Sep 2024 15:26:50 +0100 Subject: [PATCH 1/2] Extend condition to service capacity on workplace summary --- .../test-utils/MockEstablishmentService.ts | 49 +++++++++++++++++ .../workplace-summary.component.html | 6 +- .../workplace-summary.component.spec.ts | 55 +++++++++++++++++-- 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/core/test-utils/MockEstablishmentService.ts b/frontend/src/app/core/test-utils/MockEstablishmentService.ts index 96d857e834..97f7238ded 100644 --- a/frontend/src/app/core/test-utils/MockEstablishmentService.ts +++ b/frontend/src/app/core/test-utils/MockEstablishmentService.ts @@ -409,3 +409,52 @@ export class MockEstablishmentServiceCheckCQCDetails extends MockEstablishmentSe return this.cqcDetailsBanner; } } + +@Injectable() +export class MockEstablishmentServiceCapacity extends MockEstablishmentService { + private questionsAvailable; + + public static factory(hasQuestions = false) { + return (httpClient: HttpClient) => { + const service = new MockEstablishmentServiceCapacity(httpClient); + service.questionsAvailable = hasQuestions; + return service; + }; + } + + public getCapacity(establishmentId: any, all: boolean): Observable { + if (this.questionsAvailable) { + return of({ + allServiceCapacities: [ + { + service: 'Main Service: Some kind of service', + questions: [ + { question: 'How many places do you have at the moment?', questionId: 101, seq: 1 }, + { question: 'Number of those places being used?', questionId: 107, seq: 2 }, + ], + }, + { + service: 'Adult: Residential care', + questions: [ + { question: 'How many beds do you have?', questionId: 102, seq: 1 }, + { question: 'How many of those beds are being used?', questionId: 105, seq: 2 }, + ], + }, + { + service: 'Domiciliary: Home services', + questions: [{ question: 'Number of people receiving care at the moment', questionId: 109, seq: 1 }], + }, + { + service: 'Extra Care: Housing services', + questions: [{ question: 'Number of people using the service at the moment', questionId: 111, seq: 1 }], + }, + ], + mainService: { id: 100, name: 'Some kind of service' }, + }); + } else { + return of({ + allServiceCapacities: [], + }); + } + } +} diff --git a/frontend/src/app/shared/components/new-workplace-summary/workplace-summary.component.html b/frontend/src/app/shared/components/new-workplace-summary/workplace-summary.component.html index 9285722705..7cfb278fca 100644 --- a/frontend/src/app/shared/components/new-workplace-summary/workplace-summary.component.html +++ b/frontend/src/app/shared/components/new-workplace-summary/workplace-summary.component.html @@ -218,7 +218,11 @@

Services

> -
+
Service capacity
diff --git a/frontend/src/app/shared/components/new-workplace-summary/workplace-summary.component.spec.ts b/frontend/src/app/shared/components/new-workplace-summary/workplace-summary.component.spec.ts index 56fdc4c2f9..c0889cd027 100644 --- a/frontend/src/app/shared/components/new-workplace-summary/workplace-summary.component.spec.ts +++ b/frontend/src/app/shared/components/new-workplace-summary/workplace-summary.component.spec.ts @@ -10,7 +10,10 @@ import { EstablishmentService } from '@core/services/establishment.service'; import { PermissionsService } from '@core/services/permissions/permissions.service'; import { UserService } from '@core/services/user.service'; import { MockCqcStatusChangeService } from '@core/test-utils/MockCqcStatusChangeService'; -import { establishmentWithShareWith, MockEstablishmentService } from '@core/test-utils/MockEstablishmentService'; +import { + establishmentWithShareWith, + MockEstablishmentServiceCapacity, +} from '@core/test-utils/MockEstablishmentService'; import { MockPermissionsService } from '@core/test-utils/MockPermissionsService'; import { SharedModule } from '@shared/shared.module'; import { fireEvent, render, within } from '@testing-library/angular'; @@ -18,7 +21,11 @@ import { fireEvent, render, within } from '@testing-library/angular'; import { NewWorkplaceSummaryComponent } from './workplace-summary.component'; describe('NewWorkplaceSummaryComponent', () => { - const setup = async (shareWith = null, permissions = ['canEditEstablishment'] as PermissionType[]) => { + const setup = async ( + shareWith = null, + permissions = ['canEditEstablishment'] as PermissionType[], + hasQuestions = true, + ) => { const { fixture, getByText, queryByText, getByTestId, queryByTestId } = await render(NewWorkplaceSummaryComponent, { imports: [SharedModule, RouterModule, RouterTestingModule, HttpClientTestingModule, ReactiveFormsModule], providers: [ @@ -29,7 +36,7 @@ describe('NewWorkplaceSummaryComponent', () => { }, { provide: EstablishmentService, - useClass: MockEstablishmentService, + useFactory: MockEstablishmentServiceCapacity.factory(hasQuestions), }, { provide: CqcStatusChangeService, @@ -616,11 +623,35 @@ describe('NewWorkplaceSummaryComponent', () => { }); describe('Service capacity', () => { - it('should show dash and have Add information button on when capacities is an empty array', async () => { + it('should not show if there are no allServiceCapacities and showAddWorkplaceDetailsBanner is false', async () => { + const { component, fixture, queryByTestId } = await setup(null, ['canEditEstablishment'], false); + + component.workplace.showAddWorkplaceDetailsBanner = false; + + fixture.detectChanges(); + + const serviceCapacityRow = queryByTestId('serviceCapacity'); + + expect(serviceCapacityRow).toBeFalsy(); + }); + + it('should not show if there are no allServiceCapacities and showAddWorkplaceDetailsBanner is false', async () => { + const { component, fixture, queryByTestId } = await setup(null, ['canEditEstablishment'], false); + + component.workplace.showAddWorkplaceDetailsBanner = false; + + fixture.detectChanges(); + + const serviceCapacityRow = queryByTestId('serviceCapacity'); + + expect(serviceCapacityRow).toBeFalsy(); + }); + + it('should show dash and have Add information button if there are allServiceCapacities and showAddWorkplaceDetailsBanner is false', async () => { const { component, fixture } = await setup(); - component.workplace.capacities = []; - component.canEditEstablishment = true; + component.workplace.showAddWorkplaceDetailsBanner = false; + fixture.detectChanges(); const serviceCapacityRow = within(document.body).queryByTestId('serviceCapacity'); @@ -631,6 +662,18 @@ describe('NewWorkplaceSummaryComponent', () => { expect(within(serviceCapacityRow).queryByText('-')).toBeTruthy(); }); + it('should not show if there are allServiceCapacities and showAddWorkplaceDetailsBanner is true', async () => { + const { component, fixture, queryByTestId } = await setup(); + + component.workplace.showAddWorkplaceDetailsBanner = true; + + fixture.detectChanges(); + + const serviceCapacityRow = queryByTestId('serviceCapacity'); + + expect(serviceCapacityRow).toBeFalsy(); + }); + it('should show service capacity and have Change link when capacity array is not emtpy', async () => { const { component, fixture } = await setup(); From e2df7572dc507f530e3880f72673c3b0a2ea6763 Mon Sep 17 00:00:00 2001 From: Sabrina Date: Tue, 10 Sep 2024 11:35:32 +0100 Subject: [PATCH 2/2] Remove test duplication --- .../test-utils/MockEstablishmentService.ts | 45 +++---------------- .../workplace-summary.component.spec.ts | 9 ++-- 2 files changed, 11 insertions(+), 43 deletions(-) diff --git a/frontend/src/app/core/test-utils/MockEstablishmentService.ts b/frontend/src/app/core/test-utils/MockEstablishmentService.ts index 97f7238ded..c94eaf948a 100644 --- a/frontend/src/app/core/test-utils/MockEstablishmentService.ts +++ b/frontend/src/app/core/test-utils/MockEstablishmentService.ts @@ -411,50 +411,17 @@ export class MockEstablishmentServiceCheckCQCDetails extends MockEstablishmentSe } @Injectable() -export class MockEstablishmentServiceCapacity extends MockEstablishmentService { - private questionsAvailable; - - public static factory(hasQuestions = false) { +export class MockEstablishmentServiceWithNoCapacities extends MockEstablishmentService { + public static factory() { return (httpClient: HttpClient) => { - const service = new MockEstablishmentServiceCapacity(httpClient); - service.questionsAvailable = hasQuestions; + const service = new MockEstablishmentServiceWithNoCapacities(httpClient); return service; }; } public getCapacity(establishmentId: any, all: boolean): Observable { - if (this.questionsAvailable) { - return of({ - allServiceCapacities: [ - { - service: 'Main Service: Some kind of service', - questions: [ - { question: 'How many places do you have at the moment?', questionId: 101, seq: 1 }, - { question: 'Number of those places being used?', questionId: 107, seq: 2 }, - ], - }, - { - service: 'Adult: Residential care', - questions: [ - { question: 'How many beds do you have?', questionId: 102, seq: 1 }, - { question: 'How many of those beds are being used?', questionId: 105, seq: 2 }, - ], - }, - { - service: 'Domiciliary: Home services', - questions: [{ question: 'Number of people receiving care at the moment', questionId: 109, seq: 1 }], - }, - { - service: 'Extra Care: Housing services', - questions: [{ question: 'Number of people using the service at the moment', questionId: 111, seq: 1 }], - }, - ], - mainService: { id: 100, name: 'Some kind of service' }, - }); - } else { - return of({ - allServiceCapacities: [], - }); - } + return of({ + allServiceCapacities: [], + }); } } diff --git a/frontend/src/app/shared/components/new-workplace-summary/workplace-summary.component.spec.ts b/frontend/src/app/shared/components/new-workplace-summary/workplace-summary.component.spec.ts index c0889cd027..8d08c2ba99 100644 --- a/frontend/src/app/shared/components/new-workplace-summary/workplace-summary.component.spec.ts +++ b/frontend/src/app/shared/components/new-workplace-summary/workplace-summary.component.spec.ts @@ -12,7 +12,8 @@ import { UserService } from '@core/services/user.service'; import { MockCqcStatusChangeService } from '@core/test-utils/MockCqcStatusChangeService'; import { establishmentWithShareWith, - MockEstablishmentServiceCapacity, + MockEstablishmentService, + MockEstablishmentServiceWithNoCapacities, } from '@core/test-utils/MockEstablishmentService'; import { MockPermissionsService } from '@core/test-utils/MockPermissionsService'; import { SharedModule } from '@shared/shared.module'; @@ -36,7 +37,7 @@ describe('NewWorkplaceSummaryComponent', () => { }, { provide: EstablishmentService, - useFactory: MockEstablishmentServiceCapacity.factory(hasQuestions), + useClass: hasQuestions ? MockEstablishmentService : MockEstablishmentServiceWithNoCapacities, }, { provide: CqcStatusChangeService, @@ -635,10 +636,10 @@ describe('NewWorkplaceSummaryComponent', () => { expect(serviceCapacityRow).toBeFalsy(); }); - it('should not show if there are no allServiceCapacities and showAddWorkplaceDetailsBanner is false', async () => { + it('should not show if there are no allServiceCapacities and showAddWorkplaceDetailsBanner is true', async () => { const { component, fixture, queryByTestId } = await setup(null, ['canEditEstablishment'], false); - component.workplace.showAddWorkplaceDetailsBanner = false; + component.workplace.showAddWorkplaceDetailsBanner = true; fixture.detectChanges();