-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/RELEASE-123' into fix/CB2-10419
- Loading branch information
Showing
47 changed files
with
1,108 additions
and
366 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...eatures/tech-record/components/tech-record-amend-vrm/tech-record-amend-vrm.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...rd-edit-additional-examiner-note/tech-record-edit-additional-examiner-note.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div *ngIf="currentTechRecord"> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-full"> | ||
<dl class="govuk-summary-list"> | ||
<h1 class="govuk-heading-l">Edit Additional Examiner Note</h1> | ||
<div class="parent-div"> | ||
<td class="govuk-heading-s">Date</td> | ||
<td class="table-value">{{ examinerNoteObj.createdAtDate | date: 'dd/MM/yyyy' | defaultNullOrEmpty }}</td> | ||
<td class="govuk-heading-s">Created by</td> | ||
<td class="table-value">{{ examinerNoteObj.lastUpdatedBy }}</td> | ||
</div> | ||
<div class="govuk-summary-list__row"> | ||
<form [formGroup]="form"> | ||
<app-text-area | ||
#examinerNote | ||
formControlName="additionalExaminerNote" | ||
name="AdditionalExaminerNote" | ||
[width]="width.L" | ||
(ngModelChange)="ngOnChanges(examinerNote.value)" | ||
> | ||
</app-text-area> | ||
</form> | ||
</div> | ||
</dl> | ||
</div> | ||
</div> | ||
<app-button-group> | ||
<app-button id="submit-examiner-note" (clicked)="handleSubmit()">Save</app-button> | ||
<app-button id="cancel-amend-examiner-note" design="link" data-module="govuk-button" (clicked)="navigateBack()">Cancel</app-button> | ||
</app-button-group> | ||
</div> |
8 changes: 8 additions & 0 deletions
8
...rd-edit-additional-examiner-note/tech-record-edit-additional-examiner-note.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.parent-div { | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
.table-value { | ||
margin-left: 1%; | ||
margin-right: 1%; | ||
} |
95 changes: 95 additions & 0 deletions
95
...edit-additional-examiner-note/tech-record-edit-additional-examiner-note.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { DynamicFormsModule } from '@forms/dynamic-forms.module'; | ||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { TechnicalRecordService } from '@services/technical-record/technical-record.service'; | ||
import { MockStore, provideMockStore } from '@ngrx/store/testing'; | ||
import { initialAppState } from '@store/index'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { of } from 'rxjs'; | ||
import { GlobalErrorService } from '@core/components/global-error/global-error.service'; | ||
import { TechRecordEditAdditionalExaminerNoteComponent } from './tech-record-edit-additional-examiner-note.component'; | ||
|
||
const mockTechRecordService = { | ||
techRecord$: jest.fn(), | ||
}; | ||
describe('TechRecordEditAdditionalExaminerNoteComponent', () => { | ||
let fixture: ComponentFixture<TechRecordEditAdditionalExaminerNoteComponent>; | ||
let component: TechRecordEditAdditionalExaminerNoteComponent; | ||
let router: Router; | ||
let errorService: GlobalErrorService; | ||
let route: ActivatedRoute; | ||
let store: MockStore; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [TechRecordEditAdditionalExaminerNoteComponent], | ||
imports: [DynamicFormsModule, FormsModule, ReactiveFormsModule, RouterTestingModule], | ||
providers: [ | ||
{ provide: TechnicalRecordService, useValue: mockTechRecordService }, | ||
provideMockStore({ initialState: initialAppState }), | ||
{ provide: ActivatedRoute, useValue: { params: of([{ id: 1 }]) } }, | ||
], | ||
}).compileComponents(); | ||
fixture = TestBed.createComponent(TechRecordEditAdditionalExaminerNoteComponent); | ||
component = fixture.componentInstance; | ||
router = TestBed.inject(Router); | ||
errorService = TestBed.inject(GlobalErrorService); | ||
route = TestBed.inject(ActivatedRoute); | ||
store = TestBed.inject(MockStore); | ||
}); | ||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
describe('ngOnInit', () => { | ||
it('should call all initialisation functions', () => { | ||
const examinerNoteSpy = jest.spyOn(component, 'getExaminerNote').mockReturnValue(); | ||
const techRecordSpy = jest.spyOn(component, 'getTechRecord').mockReturnValue(); | ||
const formSpy = jest.spyOn(component, 'setupForm').mockReturnValue(); | ||
component.ngOnInit(); | ||
expect(examinerNoteSpy).toHaveBeenCalled(); | ||
expect(formSpy).toHaveBeenCalled(); | ||
expect(techRecordSpy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
describe('navigateBack', () => { | ||
it('should clear all errors', () => { | ||
jest.spyOn(router, 'navigate').mockImplementation(); | ||
|
||
const clearErrorsSpy = jest.spyOn(errorService, 'clearErrors'); | ||
|
||
component.navigateBack(); | ||
|
||
expect(clearErrorsSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should navigate back to the previous page', () => { | ||
const navigateSpy = jest.spyOn(router, 'navigate').mockImplementation(() => Promise.resolve(true)); | ||
|
||
component.navigateBack(); | ||
|
||
expect(navigateSpy).toHaveBeenCalledWith(['../../'], { relativeTo: route }); | ||
}); | ||
}); | ||
describe('handleSubmit', () => { | ||
it('should not dispatch an action if the notes are the same', () => { | ||
const storeSpy = jest.spyOn(store, 'dispatch'); | ||
const navigateBackSpy = jest.spyOn(component, 'navigateBack').mockReturnValue(); | ||
component.originalExaminerNote = 'foobar'; | ||
component.editedExaminerNote = 'foobar'; | ||
component.handleSubmit(); | ||
expect(storeSpy).not.toHaveBeenCalled(); | ||
expect(navigateBackSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should dispatch an action if the notes are not the same', () => { | ||
const storeSpy = jest.spyOn(store, 'dispatch'); | ||
const navigateBackSpy = jest.spyOn(component, 'navigateBack').mockReturnValue(); | ||
component.originalExaminerNote = 'foo'; | ||
component.editedExaminerNote = 'bar'; | ||
component.handleSubmit(); | ||
expect(storeSpy).toHaveBeenCalled(); | ||
expect(navigateBackSpy).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
108 changes: 108 additions & 0 deletions
108
...cord-edit-additional-examiner-note/tech-record-edit-additional-examiner-note.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { TechnicalRecordService } from '@services/technical-record/technical-record.service'; | ||
import { TechRecordType } from '@dvsa/cvs-type-definitions/types/v3/tech-record/tech-record-vehicle-type'; | ||
import { ReplaySubject, take, takeUntil } from 'rxjs'; | ||
import { GlobalErrorService } from '@core/components/global-error/global-error.service'; | ||
import { | ||
CustomFormControl, | ||
FormNodeEditTypes, | ||
FormNodeTypes, | ||
FormNodeWidth, | ||
} from '@forms/services/dynamic-form.types'; | ||
import { FormGroup, Validators } from '@angular/forms'; | ||
import { Store } from '@ngrx/store'; | ||
import { State } from '@store/index'; | ||
import { updateExistingADRAdditionalExaminerNote } from '@store/technical-records'; | ||
import { AdditionalExaminerNotes } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/hgv/complete'; | ||
|
||
@Component({ | ||
selector: 'tech-record-edit-additional-examiner-note', | ||
templateUrl: './tech-record-edit-additional-examiner-note.component.html', | ||
styleUrls: ['./tech-record-edit-additional-examiner-note.component.scss'], | ||
}) | ||
export class TechRecordEditAdditionalExaminerNoteComponent implements OnInit { | ||
currentTechRecord!: TechRecordType<'hgv' | 'trl' | 'lgv'>; | ||
examinerNoteIndex!: number; | ||
editedExaminerNote: string = ''; | ||
originalExaminerNote: string = ''; | ||
examinerNoteObj!: AdditionalExaminerNotes; | ||
destroy$ = new ReplaySubject<boolean>(1); | ||
form!: FormGroup; | ||
formControl!: CustomFormControl; | ||
|
||
constructor( | ||
private router: Router, | ||
private route: ActivatedRoute, | ||
private technicalRecordService: TechnicalRecordService, | ||
private globalErrorService: GlobalErrorService, | ||
private store: Store<State>, | ||
) { } | ||
|
||
ngOnInit() { | ||
this.getTechRecord(); | ||
this.getExaminerNote(); | ||
this.setupForm(); | ||
} | ||
|
||
getTechRecord() { | ||
this.technicalRecordService.techRecord$.pipe(takeUntil(this.destroy$)).subscribe((currentTechRecord) => { | ||
this.currentTechRecord = currentTechRecord as TechRecordType<'hgv' | 'lgv' | 'trl'>; | ||
}); | ||
} | ||
|
||
getExaminerNote() { | ||
this.route.params.pipe(take(1)).subscribe((params) => { | ||
this.examinerNoteIndex = params['examinerNoteIndex']; | ||
}); | ||
const additionalExaminerNotes = this.currentTechRecord?.techRecord_adrDetails_additionalExaminerNotes; | ||
if (additionalExaminerNotes) { | ||
const examinerNote = additionalExaminerNotes[this.examinerNoteIndex].note; | ||
if (examinerNote) { | ||
this.examinerNoteObj = additionalExaminerNotes[this.examinerNoteIndex]; | ||
this.originalExaminerNote = examinerNote; | ||
this.editedExaminerNote = examinerNote; | ||
} | ||
} | ||
} | ||
|
||
setupForm() { | ||
this.formControl = new CustomFormControl({ | ||
name: 'additionalExaminerNote', type: FormNodeTypes.CONTROL, | ||
}, '', [Validators.required]); | ||
this.form = new FormGroup({ | ||
additionalExaminerNote: this.formControl, | ||
}); | ||
this.formControl.patchValue(this.editedExaminerNote); | ||
} | ||
|
||
navigateBack() { | ||
this.globalErrorService.clearErrors(); | ||
void this.router.navigate(['../../'], { relativeTo: this.route }); | ||
} | ||
|
||
handleSubmit(): void { | ||
if (this.originalExaminerNote !== this.editedExaminerNote) { | ||
this.store.dispatch( | ||
updateExistingADRAdditionalExaminerNote({ | ||
examinerNoteIndex: this.examinerNoteIndex, | ||
additionalExaminerNote: this.editedExaminerNote, | ||
}), | ||
); | ||
} | ||
this.navigateBack(); | ||
} | ||
|
||
ngOnChanges(examinerNote: string) { | ||
this.editedExaminerNote = examinerNote; | ||
} | ||
|
||
get editTypes(): typeof FormNodeEditTypes { | ||
return FormNodeEditTypes; | ||
} | ||
|
||
get width(): typeof FormNodeWidth { | ||
return FormNodeWidth; | ||
} | ||
|
||
} |
Oops, something went wrong.