Skip to content

Commit

Permalink
AKR:OTR:VKT:YKI:SHARED(Frontend) useBlocker fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrkkp committed Jan 15, 2024
1 parent a7e1034 commit a05b49f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ describe('ClerkTranslatorOverview:ClerkTranslatorDetails', () => {
onClerkTranslatorOverviewPage.expectSaveAuthorisationButtonDisabled();
});

it.skip('should display a confirmation dialog if the back button is clicked and there are unsaved changes', () => {
it('should display a confirmation dialog if the back button is clicked and there are unsaved changes', () => {
onClerkTranslatorOverviewPage.navigateById(translatorResponse.id);
cy.wait('@getClerkTranslatorOverview');
onClerkTranslatorOverviewPage.clickEditTranslatorDetailsButton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('ClerkInterpreterOverview:ClerkInterpreterDetails', () => {
);
});

it.skip('should display a confirmation dialog if the back button is clicked and there are unsaved changes', () => {
it('should display a confirmation dialog if the back button is clicked and there are unsaved changes', () => {
onClerkInterpreterOverviewPage.clickEditInterpreterDetailsButton();
onClerkInterpreterOverviewPage.editInterpreterField(
'lastName',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect } from 'react';
import { Location, unstable_useBlocker as useBlocker } from 'react-router-dom';
import { Location, unstable_useBlocker as useBlocker, unstable_usePrompt as usePrompt } from 'react-router-dom';

export const useNavigationProtection = (
when: boolean,

Check warning on line 5 in frontend/packages/shared/src/hooks/useNavigationProtection/useNavigationProtection.ts

View workflow job for this annotation

GitHub Actions / deploy (20.9.0)

'usePrompt' is defined but never used. Allowed unused vars must match /^_/u
Expand All @@ -15,13 +15,22 @@ export const useNavigationProtection = (
}: {
currentLocation: Location;
nextLocation: Location;
}): boolean =>
!!(
when &&
baseUrl &&
!nextLocation.pathname.includes(baseUrl) &&
currentLocation.pathname !== nextLocation.pathname
);
}): boolean => {

if (baseUrl) {
return !!(
when &&
baseUrl &&
!nextLocation.pathname.includes(baseUrl) &&
currentLocation.pathname !== nextLocation.pathname
);
} else {
return !!(
when &&
currentLocation.pathname !== nextLocation.pathname
);
}
}

const blocker = useBlocker(shouldBlock);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('ClerkExamEventOverview:ClerkExamEventDetails', () => {
cy.isOnPage(AppRoutes.ClerkHomePage);
});

it.skip('should display a confirmation dialog if the back button is clicked and there are unsaved changes', () => {
it('should display a confirmation dialog if the back button is clicked and there are unsaved changes', () => {
onClerkExamEventOverviewPage.clickEditExamEventDetailsButton();
onClerkExamEventOverviewPage.editExamEventField(
'level',
Expand Down
3 changes: 3 additions & 0 deletions frontend/packages/vkt/src/tests/msw/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export const handlers = [
http.get(APIEndpoints.PublicExamEvent, () => {
return new Response(JSON.stringify(publicExamEvents11));
}),
http.get(APIEndpoints.PublicUser, () => {
return new Response(JSON.stringify(null));
}),
http.put(`${APIEndpoints.PublicReservation}/1/renew`, () => {
const response: PublicReservationResponse = {
id: 1,
Expand Down

0 comments on commit a05b49f

Please sign in to comment.