Skip to content

Commit 732092a

Browse files
VIA-172 AJ Removed the unused stay-logged-in button handler as it is supposed to just reset the inactivity. Also refactored for better readability
1 parent 2b23bb0 commit 732092a

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

src/app/_components/inactivity/InactivityDialog.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { InactivityDialog } from "@src/app/_components/inactivity/InactivityDialog";
22
import { SESSION_LOGOUT_ROUTE } from "@src/app/session-logout/constants";
3-
import { userExtendSession } from "@src/utils/auth/user-extend-session";
43
import { render, screen } from "@testing-library/react";
54
import { userLogout } from "@src/utils/auth/user-logout";
65
import useInactivityTimer from "@src/utils/auth/inactivity-timer";
@@ -18,7 +17,6 @@ jest.mock("next-auth/react", () => ({
1817

1918
jest.mock("@src/utils/auth/inactivity-timer");
2019
jest.mock("@src/utils/auth/user-logout");
21-
jest.mock("@src/utils/auth/user-extend-session");
2220

2321
const mockRouterPush = jest.fn();
2422
jest.mock("next/navigation", () => ({
@@ -106,13 +104,16 @@ describe("InactivityDialog", () => {
106104
expect(userLogout).toHaveBeenCalledTimes(1);
107105
});
108106

109-
it("should call extend session when user clicks the button", async () => {
107+
it("should close the dialog when user clicks the stay logged in button", async () => {
110108
idleSession = true;
111109

112110
render(<InactivityDialog />);
113111
screen.getByRole("button", { name: "Stay logged in" }).click();
114112

115-
expect(userExtendSession).toHaveBeenCalledTimes(1);
113+
const inactivityWarningModal: HTMLElement = screen.getByRole("dialog", {
114+
hidden: true,
115+
});
116+
expect(inactivityWarningModal).not.toBeVisible();
116117
});
117118

118119
it("should call logout when user clicks the button", async () => {

src/app/_components/inactivity/InactivityDialog.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use client";
22

33
import { SESSION_LOGOUT_ROUTE } from "@src/app/session-logout/constants";
4-
import { userExtendSession } from "@src/utils/auth/user-extend-session";
54
import { createRef, JSX, useEffect } from "react";
65
import styles from "./styles.module.css";
76
import { userLogout } from "@src/utils/auth/user-logout";
@@ -16,18 +15,16 @@ const InactivityDialog = (): JSX.Element => {
1615
const dialogRef = createRef<HTMLDialogElement>();
1716

1817
useEffect(() => {
19-
if (status === "unauthenticated") {
18+
if (status === "authenticated") {
19+
if (isTimedOut) {
20+
dialogRef.current?.close();
21+
userLogout();
22+
} else if (isIdle) {
23+
dialogRef.current?.showModal();
24+
}
25+
} else if (status === "unauthenticated") {
2026
dialogRef.current?.close();
2127
router.push(SESSION_LOGOUT_ROUTE);
22-
return;
23-
}
24-
25-
const isAuthenticated = status === "authenticated";
26-
if (isAuthenticated && isTimedOut) {
27-
dialogRef.current?.close();
28-
userLogout();
29-
} else if (isAuthenticated && isIdle) {
30-
dialogRef.current?.showModal();
3128
}
3229
}, [dialogRef, isIdle, isTimedOut, router, status]);
3330

@@ -40,7 +37,6 @@ const InactivityDialog = (): JSX.Element => {
4037
className={"nhsuk-button nhsapp-button"}
4138
onClick={() => {
4239
dialogRef.current?.close();
43-
userExtendSession();
4440
}}
4541
>
4642
Stay logged in

src/utils/auth/user-extend-session.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)