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

Fix/1477 cqc workplace questions in sub navigate to parent #6306

Merged
Original file line number Diff line number Diff line change
@@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
};
}

Expand All @@ -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']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -20,8 +20,11 @@ describe('SelectMainServiceComponent', () => {
],
});

const component = fixture.componentInstance;

return {
component,
getByText,
};
}

Expand All @@ -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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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`],
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Loading