@@ -13,6 +13,7 @@ import {FRONTEND_PATHS} from "@/constants/environment"
1313import { getSearchParams } from "@/helpers/getSearchParams"
1414import { handleRestartLogin } from "@/helpers/logout"
1515import axios from "axios"
16+ import { RoleDetails } from "@cpt-ui-common/common-types"
1617
1718jest . mock ( "@/context/AuthProvider" )
1819jest . mock ( "@/helpers/getSearchParams" )
@@ -89,7 +90,6 @@ describe("RoleSelectionPage", () => {
8990 it ( "renders loading spinner if redirecting during sign in" , ( ) => {
9091 mockUseAuth . mockReturnValue ( {
9192 isSigningIn : true ,
92- hasNoAccess : false ,
9393 rolesWithAccess : [ ] ,
9494 rolesWithoutAccess : [ ] ,
9595 error : null ,
@@ -107,7 +107,6 @@ describe("RoleSelectionPage", () => {
107107 it ( "renders error message if auth.error exists" , ( ) => {
108108 mockUseAuth . mockReturnValue ( {
109109 isSigningIn : false ,
110- hasNoAccess : false ,
111110 rolesWithAccess : [ ] ,
112111 rolesWithoutAccess : [ ] ,
113112 error : "Something went wrong"
@@ -118,10 +117,9 @@ describe("RoleSelectionPage", () => {
118117 expect ( screen . getByText ( "Something went wrong" ) ) . toBeInTheDocument ( )
119118 } )
120119
121- it ( "renders titleNoAccess and captionNoAccess when hasNoAccess is true " , ( ) => {
120+ it ( "renders titleNoAccess and captionNoAccess when rolesWithAccess is empty " , ( ) => {
122121 mockUseAuth . mockReturnValue ( {
123122 isSigningIn : false ,
124- hasNoAccess : true ,
125123 rolesWithAccess : [ ] ,
126124 rolesWithoutAccess : [ ] ,
127125 error : null
@@ -139,8 +137,6 @@ describe("RoleSelectionPage", () => {
139137 mockUseAuth . mockReturnValue ( {
140138 isSigningIn : true ,
141139 isSignedIn : false ,
142- hasSingleRoleAccess : true ,
143- hasNoAccess : false ,
144140 rolesWithAccess : [ ] ,
145141 rolesWithoutAccess : [ ] ,
146142 selectedRole : null ,
@@ -157,16 +153,21 @@ describe("RoleSelectionPage", () => {
157153 expect ( navigateMock ) . toHaveBeenCalledWith ( FRONTEND_PATHS . LOGIN )
158154 } )
159155
160- it ( "redirects if user hasSingleRoleAccess " , ( ) => {
156+ it ( "redirects if user has single roleWithAccess " , ( ) => {
161157 const navigateMock = jest . fn ( )
162158 mockNavigate . mockReturnValue ( navigateMock )
163159
164160 mockUseAuth . mockReturnValue ( {
165161 isSigningIn : false ,
166162 isSignedIn : true ,
167- hasSingleRoleAccess : true ,
168- hasNoAccess : false ,
169- rolesWithAccess : [ ] ,
163+ rolesWithAccess : [
164+ {
165+ role_id : "1" ,
166+ role_name : "Pharmacist" ,
167+ org_code : "ABC" ,
168+ org_name : "Pharmacy Org"
169+ }
170+ ] ,
170171 rolesWithoutAccess : [ ] ,
171172 selectedRole : null ,
172173 error : null
@@ -180,8 +181,6 @@ describe("RoleSelectionPage", () => {
180181 it ( "renders login info when selectedRole is present" , ( ) => {
181182 mockUseAuth . mockReturnValue ( {
182183 isSigningIn : false ,
183- hasSingleRoleAccess : false ,
184- hasNoAccess : false ,
185184 selectedRole : {
186185 org_name : "Test Org" ,
187186 org_code : "TEST123" ,
@@ -202,7 +201,6 @@ describe("RoleSelectionPage", () => {
202201 it ( "renders roles without access in table" , ( ) => {
203202 mockUseAuth . mockReturnValue ( {
204203 isSigningIn : false ,
205- hasNoAccess : false ,
206204 rolesWithAccess : [ ] ,
207205 rolesWithoutAccess : [
208206 {
@@ -224,7 +222,6 @@ describe("RoleSelectionPage", () => {
224222 it ( "renders EpsCard components for roles with access" , ( ) => {
225223 mockUseAuth . mockReturnValue ( {
226224 isSigningIn : false ,
227- hasNoAccess : false ,
228225 selectedRole : {
229226 role_id : "1"
230227 } ,
@@ -265,7 +262,6 @@ describe("RoleSelectionPage", () => {
265262 it ( "navigates on confirm and continue button click" , async ( ) => {
266263 mockUseAuth . mockReturnValue ( {
267264 isSigningIn : false ,
268- hasNoAccess : false ,
269265 selectedRole : {
270266 role_id : "1" ,
271267 org_name : "Pharmacy A" ,
@@ -284,7 +280,6 @@ describe("RoleSelectionPage", () => {
284280 expect ( button ) . toBeEnabled ( )
285281 fireEvent . click ( button )
286282
287- expect ( mockNavigate . mock . calls . length ) . toBe ( 5 )
288283 expect ( mockNavigate ) . toHaveBeenCalledWith ( "/continue" )
289284 } )
290285
@@ -293,11 +288,9 @@ describe("RoleSelectionPage", () => {
293288 const authState = {
294289 isSigningIn : true ,
295290 isSignedIn : false ,
296- hasSingleRoleAccess : false ,
297- hasNoAccess : false ,
298- rolesWithAccess : [ ] ,
291+ rolesWithAccess : [ ] as Array < RoleDetails > ,
299292 rolesWithoutAccess : [ ] ,
300- selectedRole : null ,
293+ selectedRole : undefined as RoleDetails | undefined ,
301294 error : null ,
302295 clearAuthState : jest . fn ( )
303296 }
@@ -317,8 +310,14 @@ describe("RoleSelectionPage", () => {
317310 // Step 2: Simulate login complete and role assignment
318311 act ( ( ) => {
319312 authState . isSigningIn = false
320- authState . isSignedIn = true
321- authState . hasSingleRoleAccess = true
313+ const role = {
314+ role_id : "2" ,
315+ role_name : "Pharmacist" ,
316+ org_code : "ABC" ,
317+ org_name : "Pharmacy Org"
318+ }
319+ authState . rolesWithAccess = [ role ]
320+ authState . selectedRole = role
322321 authState . isSignedIn = true
323322 mockUseAuth . mockReturnValue ( authState )
324323 } )
0 commit comments