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

noc back button fix and qm qualifying question style fix #4167

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"@cucumber/cucumber": "^10.8.0",
"@edium/fsm": "^2.1.2",
"@faker-js/faker": "^9.2.0",
"@hmcts/ccd-case-ui-toolkit": "7.1.25",
"@hmcts/ccd-case-ui-toolkit": "7.1.32-qm-style-update",
"@hmcts/ccpay-web-component": "6.2.1",
"@hmcts/frontend": "0.0.50-alpha",
"@hmcts/media-viewer": "4.0.9",
Expand Down
47 changes: 43 additions & 4 deletions src/noc/containers/noc-home/noc-home.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NO_ERRORS_SCHEMA, Pipe, PipeTransform } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { Router } from '@angular/router';
import { Location } from '@angular/common';
import { RouterTestingModule } from '@angular/router/testing';
import { Store } from '@ngrx/store';
import { provideMockStore } from '@ngrx/store/testing';
Expand Down Expand Up @@ -33,6 +34,8 @@ describe('NocHomeComponent', () => {

const loggerServiceMock = jasmine.createSpyObj('loggerService', ['error']);

const locationMock = jasmine.createSpyObj('Location', ['back']);

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
Expand All @@ -50,7 +53,8 @@ describe('NocHomeComponent', () => {
providers: [
provideMockStore(),
{ provide: Router, useValue: routerMock },
{ provide: LoggerService, useValue: loggerServiceMock }
{ provide: LoggerService, useValue: loggerServiceMock },
{ provide: Location, useValue: locationMock }
]
}).compileComponents();

Expand Down Expand Up @@ -89,11 +93,46 @@ describe('NocHomeComponent', () => {
expect(expected).toBeFalsy();
});

it('should navigate to home page when click back button if on start page', () => {
routerMock.navigateByUrl.and.returnValue(Promise.resolve(true));
it('should navigate back on BACK event and START state', () => {
component.navigationHandler(NocNavigationEvent.BACK);
component.nocNavigationCurrentState = NocState.START;

expect(locationMock.back).toHaveBeenCalled();
expect(loggerServiceMock.error).not.toHaveBeenCalled();
expect(routerMock.navigateByUrl).not.toHaveBeenCalled();
});

it('should navigate to fallback route if Location back fails', () => {
component.nocNavigationCurrentState = NocState.START;
locationMock.back.and.throwError('Back navigation failed');
routerMock.navigateByUrl.and.returnValue(Promise.resolve(true));

component.navigationHandler(NocNavigationEvent.BACK);
expect(routerMock.navigateByUrl).toHaveBeenCalled();

expect(locationMock.back).toHaveBeenCalled();
expect(loggerServiceMock.error).toHaveBeenCalledWith(
'Error navigating back, trying fallback route.',
jasmine.any(Error)
);
expect(routerMock.navigateByUrl).toHaveBeenCalledWith('');
});

it('should log an error if fallback route navigation fails', async () => {
component.nocNavigationCurrentState = NocState.START;
locationMock.back.and.throwError('Back navigation failed');
routerMock.navigateByUrl.and.returnValue(Promise.reject('Navigation failed'));

await component.navigationHandler(NocNavigationEvent.BACK);

expect(locationMock.back).toHaveBeenCalled();
expect(loggerServiceMock.error).toHaveBeenCalledWith(
'Error navigating back, trying fallback route.',
jasmine.any(Error)
);
expect(loggerServiceMock.error).toHaveBeenCalledWith(
'Error navigating to \'\' ',
'Navigation failed'
);
});

it('should navigate to case ref page when click back button if on question page', () => {
Expand Down
13 changes: 10 additions & 3 deletions src/noc/containers/noc-home/noc-home.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { Location } from '@angular/common';
import { select, Store } from '@ngrx/store';
import { Subscription } from 'rxjs';
import { caseRefVisibilityStates, checkAnswerVisibilityStates, nocErrorVisibilityStates, nocSubmitSuccessStates, qAndAVisibilityStates } from '../../constants';
Expand Down Expand Up @@ -40,6 +41,7 @@ export class NocHomeComponent implements OnInit, OnDestroy {
constructor(
private readonly store: Store<fromFeature.State>,
private readonly router: Router,
private readonly location: Location,
private readonly loggerService: LoggerService,
) {}

Expand All @@ -65,9 +67,14 @@ export class NocHomeComponent implements OnInit, OnDestroy {
switch (this.nocNavigationCurrentState) {
case NocState.START:
case NocState.CASE_REF_VALIDATION_FAILURE:
this.router.navigateByUrl('').catch((err) => {
this.loggerService.error('Error navigating to \'\' ', err);
});
try {
this.location.back();
} catch (err) {
this.loggerService.error('Error navigating back, trying fallback route.', err);
this.router.navigateByUrl('').catch((err) => {
this.loggerService.error('Error navigating to \'\' ', err);
});
}
break;
case NocState.QUESTION:
case NocState.CASE_REF_SUBMISSION_FAILURE:
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3455,12 +3455,12 @@ __metadata:
languageName: node
linkType: hard

"@hmcts/ccd-case-ui-toolkit@npm:7.1.25":
version: 7.1.25
resolution: "@hmcts/ccd-case-ui-toolkit@npm:7.1.25"
"@hmcts/ccd-case-ui-toolkit@npm:7.1.32-qm-style-update":
version: 7.1.32-qm-style-update
resolution: "@hmcts/ccd-case-ui-toolkit@npm:7.1.32-qm-style-update"
dependencies:
tslib: "npm:^2.3.0"
checksum: 10/085ee1ad56ba184df2325360748901fec4f3e1ca44ec7ce37578d60715a3568cbe762a4bdda78c7d44cc44156d7ab87dbda97a539e1aa30c1c2319984c5c369c
checksum: 10/f22e28cd11cd12e5934f13c31eaa5e16e3cd474843304886b65706ce8eab6ef61a0bbd7729e06f3ec7a79fa86f1d34af38c8f61344f0ff372e2bc0a1f44faa04
languageName: node
linkType: hard

Expand Down Expand Up @@ -22271,7 +22271,7 @@ __metadata:
"@cucumber/cucumber": "npm:^10.8.0"
"@edium/fsm": "npm:^2.1.2"
"@faker-js/faker": "npm:^9.2.0"
"@hmcts/ccd-case-ui-toolkit": "npm:7.1.25"
"@hmcts/ccd-case-ui-toolkit": "npm:7.1.32-qm-style-update"
"@hmcts/ccpay-web-component": "npm:6.2.1"
"@hmcts/frontend": "npm:0.0.50-alpha"
"@hmcts/media-viewer": "npm:4.0.9"
Expand Down