diff --git a/frontend/src/app/features/workplace/regulated-by-cqc/regulated-by-cqc.component.spec.ts b/frontend/src/app/features/workplace/regulated-by-cqc/regulated-by-cqc.component.spec.ts new file mode 100644 index 0000000000..3dc8120c6e --- /dev/null +++ b/frontend/src/app/features/workplace/regulated-by-cqc/regulated-by-cqc.component.spec.ts @@ -0,0 +1,43 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { ReactiveFormsModule, UntypedFormBuilder } from '@angular/forms'; +import { RouterModule } from '@angular/router'; +import { RouterTestingModule } from '@angular/router/testing'; +import { EstablishmentService } from '@core/services/establishment.service'; +import { LocationService } from '@core/services/location.service'; +import { SharedModule } from '@shared/shared.module'; +import { render } from '@testing-library/angular'; + +import { RegulatedByCqcComponent } from './regulated-by-cqc.component'; + +describe('RegulatedByCqcComponent', () => { + const workplaceUid = 'abc131355543435'; + + async function setup() { + const { fixture, getByText } = await render(RegulatedByCqcComponent, { + imports: [SharedModule, RouterModule, RouterTestingModule, HttpClientTestingModule, ReactiveFormsModule], + providers: [ + UntypedFormBuilder, + { + provide: EstablishmentService, + useValue: { + establishment: { uid: workplaceUid }, + }, + }, + LocationService, + ], + }); + + const component = fixture.componentInstance; + + return { + component, + fixture, + getByText, + }; + } + + it('should render a RegulatedByCqcComponent', async () => { + const { component } = await setup(); + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/features/workplace/regulated-by-cqc/regulated-by-cqc.component.ts b/frontend/src/app/features/workplace/regulated-by-cqc/regulated-by-cqc.component.ts index d970a80cf0..643bb6df08 100644 --- a/frontend/src/app/features/workplace/regulated-by-cqc/regulated-by-cqc.component.ts +++ b/frontend/src/app/features/workplace/regulated-by-cqc/regulated-by-cqc.component.ts @@ -30,7 +30,7 @@ export class RegulatedByCqcComponent extends RegulatedByCQCDirective { } protected init() { - this.flow = `workplace/${this.establishmentService.establishmentId}`; + this.flow = `workplace/${this.establishmentService.establishment.uid}`; this.isCQCLocationUpdate = true; this.setBackLink(); this.validateLocationChange(); diff --git a/frontend/src/app/features/workplace/select-main-service/select-main-service-cqc.component.spec.ts b/frontend/src/app/features/workplace/select-main-service/select-main-service-cqc.component.spec.ts index d4b7085ac6..bd0d6f9d0b 100644 --- a/frontend/src/app/features/workplace/select-main-service/select-main-service-cqc.component.spec.ts +++ b/frontend/src/app/features/workplace/select-main-service/select-main-service-cqc.component.spec.ts @@ -1,33 +1,36 @@ -import { render } from '@testing-library/angular'; -import { SharedModule } from '@shared/shared.module'; -import { RouterModule } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { getTestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; +import { Router, RouterModule } from '@angular/router'; +import { RouterTestingModule } from '@angular/router/testing'; import { EstablishmentService } from '@core/services/establishment.service'; import { MockEstablishmentService } from '@core/test-utils/MockEstablishmentService'; import { SelectMainServiceCqcComponent } from '@features/workplace/select-main-service/select-main-service-cqc.component'; -import { ReactiveFormsModule } from '@angular/forms'; +import { SharedModule } from '@shared/shared.module'; +import { fireEvent, render } from '@testing-library/angular'; describe('SelectMainServiceCQCComponent', () => { async function setup() { - const component = await render(SelectMainServiceCqcComponent, { - imports: [ - SharedModule, - RouterModule, - RouterTestingModule, - HttpClientTestingModule, - ReactiveFormsModule - ], + const { fixture, getByText } = await render(SelectMainServiceCqcComponent, { + imports: [SharedModule, RouterModule, RouterTestingModule, HttpClientTestingModule, ReactiveFormsModule], providers: [ { provide: EstablishmentService, - useClass: MockEstablishmentService + useClass: MockEstablishmentService, }, - ] + ], }); + const component = fixture.componentInstance; + const injector = getTestBed(); + const router = injector.inject(Router) as Router; + + const routerSpy = spyOn(router, 'navigate').and.returnValue(Promise.resolve(true)); + return { - component + component, + routerSpy, + getByText, }; } @@ -36,4 +39,17 @@ describe('SelectMainServiceCQCComponent', () => { expect(component).toBeTruthy(); }); + + it('should navigate to main service question when answer selected', async () => { + const { component, getByText, routerSpy } = await setup(); + + expect(component).toBeTruthy(); + const yesRadio = getByText('Yes'); + fireEvent.click(yesRadio); + + const continueButton = getByText('Continue'); + fireEvent.click(continueButton); + + expect(routerSpy).toHaveBeenCalledWith(['/workplace', component.establishment.uid, 'main-service']); + }); }); diff --git a/frontend/src/app/features/workplace/select-main-service/select-main-service-cqc.component.ts b/frontend/src/app/features/workplace/select-main-service/select-main-service-cqc.component.ts index f382240e15..9ed0988d33 100644 --- a/frontend/src/app/features/workplace/select-main-service/select-main-service-cqc.component.ts +++ b/frontend/src/app/features/workplace/select-main-service/select-main-service-cqc.component.ts @@ -36,8 +36,6 @@ export class SelectMainServiceCqcComponent extends Question { ], }, ]; - - this.form.get('cqc'); // If it's stupid but it works, it isn't stupid. } public onSubmit(): void { @@ -51,7 +49,7 @@ export class SelectMainServiceCqcComponent extends Question { if (this.form.valid) { this.establishmentService.mainServiceCQC = this.form.get('cqc').value; - this.router.navigate(['/workplace', this.establishmentService.establishmentId, 'main-service']); + this.router.navigate(['/workplace', this.establishment.uid, 'main-service']); } else { this.errorSummaryService.scrollToErrorSummary(); } diff --git a/frontend/src/app/features/workplace/select-main-service/select-main-service.component.spec.ts b/frontend/src/app/features/workplace/select-main-service/select-main-service.component.spec.ts index a6dd081855..8d87db587c 100644 --- a/frontend/src/app/features/workplace/select-main-service/select-main-service.component.spec.ts +++ b/frontend/src/app/features/workplace/select-main-service/select-main-service.component.spec.ts @@ -10,7 +10,7 @@ import { render } from '@testing-library/angular'; describe('SelectMainServiceComponent', () => { async function setup() { - const component = await render(SelectMainServiceComponent, { + const { fixture, getByText } = await render(SelectMainServiceComponent, { imports: [SharedModule, RouterModule, RouterTestingModule, HttpClientTestingModule, ReactiveFormsModule], providers: [ { @@ -20,8 +20,11 @@ describe('SelectMainServiceComponent', () => { ], }); + const component = fixture.componentInstance; + return { component, + getByText, }; } @@ -32,7 +35,14 @@ describe('SelectMainServiceComponent', () => { }); it('should render a subheading of Services', async () => { - const { component } = await setup(); - expect(component.getByText('Services')).toBeTruthy(); + const { getByText } = await setup(); + expect(getByText('Services')).toBeTruthy(); + }); + + it('should have cancel link with href back to dashboard', async () => { + const { getByText } = await setup(); + + const cancelLink = getByText('Cancel'); + expect(cancelLink.getAttribute('href')).toEqual('/dashboard'); }); }); diff --git a/frontend/src/app/features/workplace/select-main-service/select-main-service.component.ts b/frontend/src/app/features/workplace/select-main-service/select-main-service.component.ts index e938683c25..6d6511374a 100644 --- a/frontend/src/app/features/workplace/select-main-service/select-main-service.component.ts +++ b/frontend/src/app/features/workplace/select-main-service/select-main-service.component.ts @@ -31,6 +31,7 @@ export class SelectMainServiceComponent extends SelectMainServiceDirective { this.workplace = this.establishmentService.establishment; this.selectedMainService = this.workplace.mainService; this.isWorkPlaceUpdate = true; + this.flow = 'dashboard'; } protected getServiceCategories() { diff --git a/frontend/src/app/features/workplace/select-workplace/select-workplace.component.spec.ts b/frontend/src/app/features/workplace/select-workplace/select-workplace.component.spec.ts index d76a2d82db..488a96c07a 100644 --- a/frontend/src/app/features/workplace/select-workplace/select-workplace.component.spec.ts +++ b/frontend/src/app/features/workplace/select-workplace/select-workplace.component.spec.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { getTestBed, TestBed } from '@angular/core/testing'; -import { UntypedFormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { FormsModule, ReactiveFormsModule, UntypedFormBuilder } from '@angular/forms'; import { Router } from '@angular/router'; import { RouterTestingModule } from '@angular/router/testing'; import { BackService } from '@core/services/back.service'; @@ -134,12 +134,9 @@ describe('SelectWorkplaceComponent', () => { const continueButton = getByText('Save and return'); fireEvent.click(continueButton); - expect(spy).toHaveBeenCalledWith( - [`workplace/${component.establishmentService.establishmentId}`, 'cannot-create-account'], - { - state: { returnTo: `workplace/${component.establishmentService.establishmentId}/select-workplace` }, - }, - ); + expect(spy).toHaveBeenCalledWith([`workplace/${component.workplace.uid}`, 'cannot-create-account'], { + state: { returnTo: `workplace/${component.workplace.uid}/select-workplace` }, + }); }); it('should navigate to the back to the workplace page when workplace selected and the establishment does not already exists in the service', async () => { @@ -188,7 +185,7 @@ describe('SelectWorkplaceComponent', () => { component.setBackLink(); expect(backLinkSpy).toHaveBeenCalledWith({ - url: [`workplace/${component.establishmentService.establishmentId}/regulated-by-cqc`], + url: [`workplace/${component.workplace.uid}/regulated-by-cqc`], }); }); }); diff --git a/frontend/src/app/features/workplace/select-workplace/select-workplace.component.ts b/frontend/src/app/features/workplace/select-workplace/select-workplace.component.ts index 223de7c830..1aff164cc2 100644 --- a/frontend/src/app/features/workplace/select-workplace/select-workplace.component.ts +++ b/frontend/src/app/features/workplace/select-workplace/select-workplace.component.ts @@ -31,8 +31,8 @@ export class SelectWorkplaceComponent extends SelectWorkplaceDirective { } protected init(): void { - this.flow = `workplace/${this.establishmentService.establishmentId}`; this.workplace = this.establishmentService.establishment; + this.flow = `workplace/${this.workplace.uid}`; this.back = `${this.flow}/regulated-by-cqc`; !this.locationAddresses && this.redirect(); this.isCQCLocationUpdate = true; diff --git a/frontend/src/app/features/workplace/workplace-not-found/workplace-not-found.component.spec.ts b/frontend/src/app/features/workplace/workplace-not-found/workplace-not-found.component.spec.ts new file mode 100644 index 0000000000..8eb2259d27 --- /dev/null +++ b/frontend/src/app/features/workplace/workplace-not-found/workplace-not-found.component.spec.ts @@ -0,0 +1,51 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { ReactiveFormsModule, UntypedFormBuilder } from '@angular/forms'; +import { RouterModule } from '@angular/router'; +import { RouterTestingModule } from '@angular/router/testing'; +import { EstablishmentService } from '@core/services/establishment.service'; +import { LocationService } from '@core/services/location.service'; +import { SharedModule } from '@shared/shared.module'; +import { render } from '@testing-library/angular'; + +import { WorkplaceNotFoundComponent } from './workplace-not-found.component'; + +describe('WorkplaceNotFoundComponent', () => { + const workplaceUid = 'abc131355543435'; + + async function setup() { + const { fixture, getByText } = await render(WorkplaceNotFoundComponent, { + imports: [SharedModule, RouterModule, RouterTestingModule, HttpClientTestingModule, ReactiveFormsModule], + providers: [ + UntypedFormBuilder, + { + provide: EstablishmentService, + useValue: { + establishment: { uid: workplaceUid }, + }, + }, + LocationService, + ], + }); + + const component = fixture.componentInstance; + + return { + component, + fixture, + getByText, + }; + } + + it('should render a WorkplaceNotFoundComponent', async () => { + const { component } = await setup(); + expect(component).toBeTruthy(); + }); + + it('should show a go back link with workplace uid in url', async () => { + const { getByText } = await setup(); + + const link = getByText('go back and try again'); + + expect(link.getAttribute('href')).toEqual(`/workplace/${workplaceUid}/regulated-by-cqc`); + }); +}); diff --git a/frontend/src/app/features/workplace/workplace-not-found/workplace-not-found.component.ts b/frontend/src/app/features/workplace/workplace-not-found/workplace-not-found.component.ts index 3eb9957c08..2af51ef2b4 100644 --- a/frontend/src/app/features/workplace/workplace-not-found/workplace-not-found.component.ts +++ b/frontend/src/app/features/workplace/workplace-not-found/workplace-not-found.component.ts @@ -23,13 +23,13 @@ export class WorkplaceNotFoundComponent extends WorkplaceNotFound { protected locationService: LocationService, protected router: Router, protected backService: BackService, - private establishmentService: EstablishmentService + private establishmentService: EstablishmentService, ) { super(formBuilder, backService, errorSummaryService, locationService, router); } protected init(): void { - this.flow = `workplace/${this.establishmentService.establishmentId}`; this.workplace = this.establishmentService.establishment; + this.flow = `workplace/${this.workplace.uid}`; this.setBackLink(); }