Skip to content

Commit

Permalink
fix(cb2-12599): ensure additional examiner notes appear in the correc…
Browse files Browse the repository at this point in the history
…t order
  • Loading branch information
pbardy2000 committed Jun 13, 2024
1 parent 521eb01 commit 819780a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { KeyValue, ViewportScroller } from '@angular/common';
import {
AfterContentInit,
Component, inject, OnDestroy, OnInit,
AfterContentInit, Component, OnDestroy, OnInit, inject,
} from '@angular/core';
import { FormArray, NgControl } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { AdditionalExaminerNotes } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/hgv/complete';
import { TechRecordType } from '@dvsa/cvs-type-definitions/types/v3/tech-record/tech-record-vehicle-type';
import { BaseControlComponent } from '@forms/components/base-control/base-control.component';
import { CustomControl, CustomFormControl } from '@forms/services/dynamic-form.types';
import { ReasonForEditing } from '@models/vehicle-tech-record.model';
import { Store } from '@ngrx/store';
import { TechnicalRecordService } from '@services/technical-record/technical-record.service';
import { ReplaySubject, takeUntil } from 'rxjs';
import { updateScrollPosition } from '@store/technical-records';
import { TechnicalRecordServiceState } from '@store/technical-records/reducers/technical-record-service.reducer';
import { Store } from '@ngrx/store';
import { ActivatedRoute, Router } from '@angular/router';
import { ReasonForEditing } from '@models/vehicle-tech-record.model';
import { AdditionalExaminerNotes } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/hgv/complete';
import { ReplaySubject, takeUntil } from 'rxjs';

@Component({
selector: 'app-adr-examiner-notes-history',
Expand Down Expand Up @@ -62,7 +61,9 @@ export class AdrExaminerNotesHistoryEditComponent extends BaseControlComponent i
}

getAdditionalExaminerNotes(): AdditionalExaminerNotes[] {
return this.currentTechRecord?.techRecord_adrDetails_additionalExaminerNotes ?? [];
return (this.currentTechRecord?.techRecord_adrDetails_additionalExaminerNotes ?? []).sort(
(a, b) => +new Date(b.createdAtDate ?? '') - +new Date(a.createdAtDate ?? ''),
);
}

get currentAdrNotesPage(): AdditionalExaminerNotes[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ng-container *ngIf="control">
<ng-container *ngIf="adrNotes">
<ng-container *ngIf="getAdditionalExaminerNotes() as adrNotes">
<section class="govuk-!-margin-top-4">
<label *ngIf="control.meta?.label" class="govuk-label govuk-label--m">
{{ control.meta.label }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ describe('AdrExaminerNotesHistoryViewComponent', () => {
component.currentTechRecord.techRecord_adrDetails_additionalExaminerNotes = [
{ createdAtDate: 'test', lastUpdatedBy: 'test', note: 'test note' },
];
expect(component.adrNotes).toEqual([{ createdAtDate: 'test', lastUpdatedBy: 'test', note: 'test note' }]);
expect(component.getAdditionalExaminerNotes()).toEqual([{ createdAtDate: 'test', lastUpdatedBy: 'test', note: 'test note' }]);
});

it('should return an empty array if the adr examiner notes is undefined', () => {
component.currentTechRecord = { ...MOCK_HGV };
component.currentTechRecord.techRecord_adrDetails_additionalExaminerNotes = undefined;
expect(component.adrNotes).toEqual([]);
expect(component.getAdditionalExaminerNotes()).toEqual([]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import {
Component, inject, OnDestroy, OnInit,
} from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { BaseControlComponent } from '@forms/components/base-control/base-control.component';
import { AdditionalExaminerNotes } from '@dvsa/cvs-type-definitions/types/v3/tech-record/get/hgv/complete';
import { TechRecordType } from '@dvsa/cvs-type-definitions/types/v3/tech-record/tech-record-vehicle-type';
import { BaseControlComponent } from '@forms/components/base-control/base-control.component';
import { RouterService } from '@services/router/router.service';
import { TechnicalRecordService } from '@services/technical-record/technical-record.service';
import {
map, Observable, Subject, takeUntil,
} from 'rxjs';
import { RouterService } from '@services/router/router.service';

@Component({
selector: 'app-adr-examiner-notes-history-view',
Expand Down Expand Up @@ -47,8 +47,10 @@ export class AdrExaminerNotesHistoryViewComponent extends BaseControlComponent i
this.cdr.detectChanges();
}

get adrNotes(): AdditionalExaminerNotes[] {
return this.currentTechRecord?.techRecord_adrDetails_additionalExaminerNotes ?? [];
getAdditionalExaminerNotes(): AdditionalExaminerNotes[] {
return (this.currentTechRecord?.techRecord_adrDetails_additionalExaminerNotes ?? []).sort(
(a, b) => +new Date(b.createdAtDate ?? '') - +new Date(a.createdAtDate ?? ''),
);
}

get currentAdrNotesPage(): AdditionalExaminerNotes[] {
Expand Down

0 comments on commit 819780a

Please sign in to comment.