Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "7.2.51",
"version": "7.2.51-3455",
"engines": {
"node": ">=18.19.0"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/ccd-case-ui-toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/ccd-case-ui-toolkit",
"version": "7.2.51",
"version": "7.2.51-3455",
"engines": {
"node": ">=18.19.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,11 +882,32 @@ describe('CaseEditComponent', () => {
it('should check page is not refreshed', () => {
mockSessionStorageService.getItem.and.returnValue(component.initialUrl = null);
mockSessionStorageService.getItem.and.returnValue(component.isPageRefreshed = false);

routerStub.url = 'test.com';
fixture.detectChanges();
expect(component.checkPageRefresh()).toBe(false);
});

it('should redirect to first wizard page when user navigates directly to submit without initialUrl', async () => {
routerStub.url = '/some/case/path/submit';
component.initialUrl = null;
component.isPageRefreshed = false;
component.eventTrigger = {
wizard_pages: [
{ id: 'secondPage', order: 2 },
{ id: 'firstPage', order: 1 }
]
} as any;

spyOn((component as any).windowsService, 'alert');
(routerStub.navigate as jasmine.Spy).and.returnValue(Promise.resolve(true));

const result = component.checkPageRefresh();

expect(result).toBeFalsy();
expect((component as any).windowsService.alert).toHaveBeenCalledWith(CaseEditComponent.ALERT_MESSAGE);
expect(routerStub.navigate).toHaveBeenCalledWith(['firstPage'], { relativeTo: (component as any).route });
});

it('should check page is refreshed', () => {
mockSessionStorageService.getItem.and.returnValue(component.initialUrl = 'test');
mockSessionStorageService.getItem.and.returnValue(component.isPageRefreshed = true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ export class CaseEditComponent implements OnInit, OnDestroy {
this.router.navigate([this.initialUrl], { relativeTo: this.route });
return true;
}
// if the url contains /submit there is the potential that the user has gone straight to the submit page
// we should try and work out if they have been through the journey or not and prevent them submitting directly
if (this.router.url.indexOf('/submit') !== -1 && !this.initialUrl) {
// we only want to check if the user has done this if there is a multi-page journey
if (this.eventTrigger.wizard_pages && this.eventTrigger.wizard_pages.length > 0) {
console.log('User has navigated to the end of an event journey directly, reset their journey');
const firstPage = this.eventTrigger.wizard_pages.reduce((min, page) => page.order < min.order ? page : min, this.eventTrigger.wizard_pages[0]);
this.windowsService.alert(CaseEditComponent.ALERT_MESSAGE);
this.router.navigate([firstPage ? firstPage.id : 'submit'], { relativeTo: this.route });
}
}
return false;
}

Expand Down