Skip to content

Commit

Permalink
Merge pull request #6331 from NMDSdevopsServiceAdm/feat/1465-changes-…
Browse files Browse the repository at this point in the history
…to-mandatory-information

Feat/1465 changes to mandatory information
  • Loading branch information
duncanc19 authored Aug 27, 2024
2 parents 3e32baf + 4bbdc1c commit f9b9ff9
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 281 deletions.
22 changes: 20 additions & 2 deletions frontend/src/app/core/test-utils/MockWorkerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { QualificationsByGroup } from '@core/model/qualification.model';
import { MultipleTrainingResponse, TrainingRecordRequest } from '@core/model/training.model';
import { URLStructure } from '@core/model/url.model';
import { Worker, WorkerEditResponse, WorkersResponse } from '@core/model/worker.model';
import { WorkerService } from '@core/services/worker.service';
import { NewWorkerMandatoryInfo, WorkerService } from '@core/services/worker.service';
import { build, fake, oneOf, perBuild, sequence } from '@jackfranklin/test-data-bot';
import { Observable, of } from 'rxjs';

Expand Down Expand Up @@ -339,7 +339,7 @@ export class MockWorkerService extends WorkerService {

@Injectable()
export class MockWorkerServiceWithUpdateWorker extends MockWorkerService {
public static factory(worker: Worker) {
public static factory(worker: Worker = null) {
return (httpClient: HttpClient) => {
const service = new MockWorkerServiceWithUpdateWorker(httpClient);
if (worker) {
Expand All @@ -359,6 +359,24 @@ export class MockWorkerServiceWithUpdateWorker extends MockWorkerService {
}
}

@Injectable()
export class MockWorkerServiceWithNoWorker extends MockWorkerService {
public static factory(workerMandatoryInfo: NewWorkerMandatoryInfo = null) {
return (httpClient: HttpClient) => {
const service = new MockWorkerServiceWithNoWorker(httpClient);
if (workerMandatoryInfo) {
service.setNewWorkerMandatoryInfo(workerMandatoryInfo.nameOrId, workerMandatoryInfo.contract);
}
return service;
};
}
public get worker() {
return null;
}

public worker$ = of(null);
}

@Injectable()
export class MockWorkerServiceWithoutReturnUrl extends MockWorkerServiceWithUpdateWorker {
public static factory(worker: Worker) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { render } from '@testing-library/angular';
import { MainJobRoleComponent } from './main-job-role.component';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClient } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ReactiveFormsModule, UntypedFormBuilder } from '@angular/forms';
import { ProgressBarComponent } from '@shared/components/progress-bar/progress-bar.component';
import { WorkerService } from '@core/services/worker.service';
import { MockWorkerServiceWithUpdateWorker, workerBuilder } from '@core/test-utils/MockWorkerService';
import { WindowRef } from '@core/services/window.ref';
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { SharedModule } from '@shared/shared.module';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { getTestBed } from '@angular/core/testing';
import { ReactiveFormsModule, UntypedFormBuilder } from '@angular/forms';
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { Contracts } from '@core/model/contracts.enum';
import { Roles } from '@core/model/roles.enum';
import { Worker } from '@core/model/worker.model';
import { AlertService } from '@core/services/alert.service';
import { PermissionsService } from '@core/services/permissions/permissions.service';
import { MockPermissionsService } from '@core/test-utils/MockPermissionsService';
import { HttpClient } from '@angular/common/http';
import { UserService } from '@core/services/user.service';
import { WindowRef } from '@core/services/window.ref';
import { WorkerService } from '@core/services/worker.service';
import { MockPermissionsService } from '@core/test-utils/MockPermissionsService';
import { MockUserService } from '@core/test-utils/MockUserService';
import { Roles } from '@core/model/roles.enum';
import { Contracts } from '@core/model/contracts.enum';
import { Worker } from '@core/model/worker.model';
import { MockWorkerServiceWithUpdateWorker, workerBuilder } from '@core/test-utils/MockWorkerService';
import { ProgressBarComponent } from '@shared/components/progress-bar/progress-bar.component';
import { SharedModule } from '@shared/shared.module';
import { render } from '@testing-library/angular';
import userEvent from '@testing-library/user-event';
import { AlertService } from '@core/services/alert.service';

import { MainJobRoleComponent } from './main-job-role.component';

describe('MainJobRoleComponent', () => {
async function setup(insideFlow = true, returnToMandatoryDetails = false, addNewWorker = false) {
Expand Down Expand Up @@ -433,5 +434,28 @@ describe('MainJobRoleComponent', () => {
'mental-health-professional',
]);
});

it('should clear the mandatory worker info in the worker service on submit', async () => {
const { fixture, getByText, workerService } = await setup();

const clearWorkerInfoSpy = spyOn(workerService, 'clearNewWorkerMandatoryInfo');

userEvent.click(getByText('Professional and related roles'));
userEvent.click(getByText('Social worker'));
userEvent.click(getByText('Save and return'));
fixture.detectChanges();

expect(clearWorkerInfoSpy).toHaveBeenCalled();
});

it('should clear the mandatory worker info in the worker service on click of Cancel', async () => {
const { getByText, workerService } = await setup();

const clearWorkerInfoSpy = spyOn(workerService, 'clearNewWorkerMandatoryInfo');

userEvent.click(getByText('Cancel'));

expect(clearWorkerInfoSpy).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { QuestionComponent } from '../question/question.component';
import { Job } from '@core/model/job.model';
import { UntypedFormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { Job } from '@core/model/job.model';
import { AlertService } from '@core/services/alert.service';
import { BackLinkService } from '@core/services/backLink.service';
import { ErrorSummaryService } from '@core/services/error-summary.service';
import { NewWorkerMandatoryInfo, WorkerService } from '@core/services/worker.service';
import { EstablishmentService } from '@core/services/establishment.service';
import { AlertService } from '@core/services/alert.service';
import { NewWorkerMandatoryInfo, WorkerService } from '@core/services/worker.service';

import { QuestionComponent } from '../question/question.component';

@Component({
selector: 'app-main-job-role.component',
Expand Down Expand Up @@ -156,7 +157,6 @@ export class MainJobRoleComponent extends QuestionComponent implements OnInit, O
if (this.editFlow) {
this.next = this.determineConditionalRouting();
} else {
this.workerService.clearNewWorkerMandatoryInfo();
this.next = this.getRoutePath('mandatory-details');
}
!this.editFlow && this.workerService.setAddStaffRecordInProgress(true);
Expand All @@ -183,4 +183,9 @@ export class MainJobRoleComponent extends QuestionComponent implements OnInit, O
},
];
}

public onSubmit(): void {
this.workerService.clearNewWorkerMandatoryInfo();
super.onSubmit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,56 +26,6 @@ <h1 class="govuk-fieldset__heading">{{ worker ? 'Update' : 'Add a' }} staff reco
type="text"
/>
</div>
<div
class="govuk-form-group"
[class.govuk-form-group--error]="
submitted && (form.get('mainJob').invalid || form.get('otherJobRole').invalid)
"
>
<label class="govuk-label" for="mainJob"> Main job role </label>
<span *ngIf="submitted && form.get('mainJob').errors" id="mainJob-error" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span>
{{ getFormErrorMessage('mainJob', 'required') }}
</span>
<select
class="govuk-select"
[class.govuk-select--error]="submitted && form.get('mainJob').invalid"
[formControlName]="'mainJob'"
id="mainJob"
name="mainJob"
(change)="selectedJobRole($event.target.value)"
>
<option [ngValue]="null">Select main job role</option>
<option *ngFor="let job of jobsAvailable" [value]="job.id">
{{ job.title }}
</option>
</select>

<div
class="govuk-radios__conditional govuk-!-margin-top-4"
[class.govuk-select__conditional--hidden]="!showInputTextforOtherRole"
>
<label class="govuk-label" for="otherJobRole-conditional"> What is the job role? </label>
<span
*ngIf="submitted && form.get('otherJobRole').invalid"
id="otherJobRole-error"
class="govuk-error-message"
>
<span class="govuk-visually-hidden">Error:</span>
{{ getFormErrorMessage('otherJobRole', 'maxlength') }}
</span>
<input
data-testid="other-job-role"
class="govuk-input govuk-!-width-two-thirds"
[formControlName]="'otherJobRole'"
id="otherJobRole-conditional"
name="otherJobRole"
type="text"
aria-describedby="otherJobRole-hint"
[class.govuk-select--error]="submitted && form.get('otherJobRole').invalid"
/>
</div>
</div>

<div class="govuk-form-group" [class.govuk-form-group--error]="submitted && form.get('contract').invalid">
<fieldset class="govuk-fieldset">
Expand Down Expand Up @@ -120,8 +70,8 @@ <h1 class="govuk-fieldset__heading">
</div>
</div>
<app-submit-button
[summaryContinue]="summaryContinue"
[callToAction]="submitTitle"
[summaryContinue]="false"
[callToAction]="'Continue'"
[recordSummary]="false"
[canExit]="canExit"
[return]="editFlow"
Expand Down
Loading

0 comments on commit f9b9ff9

Please sign in to comment.