Skip to content

Commit

Permalink
Remove test duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrome committed Sep 10, 2024
1 parent c51a98f commit e2df757
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 43 deletions.
45 changes: 6 additions & 39 deletions frontend/src/app/core/test-utils/MockEstablishmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
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: [],
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -36,7 +37,7 @@ describe('NewWorkplaceSummaryComponent', () => {
},
{
provide: EstablishmentService,
useFactory: MockEstablishmentServiceCapacity.factory(hasQuestions),
useClass: hasQuestions ? MockEstablishmentService : MockEstablishmentServiceWithNoCapacities,
},
{
provide: CqcStatusChangeService,
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit e2df757

Please sign in to comment.