1- import { useStore } from "@/data/store" ;
1+ import { StoreState , useStore } from "@/data/store" ;
22import { mockedJwt } from "@/mocks/data/auth" ;
33import { mockedUser } from "@/mocks/data/user" ;
44import theme from "@/theme" ;
@@ -15,6 +15,9 @@ import {
1515 waitFor ,
1616} from "../../utils/testUtils" ;
1717import NavBar from "./NavBar" ;
18+ import { mockedOrganisation } from "@/mocks/data/organisation" ;
19+ import { mockedCustodian } from "@/mocks/data/custodian" ;
20+ import { AccountType } from "@/types/accounts" ;
1821
1922jest . mock ( "js-cookie" , ( ) => ( {
2023 get : jest . fn ( ) ,
@@ -117,7 +120,11 @@ describe("NavBar Component", () => {
117120 selector ( {
118121 getUser : ( ) => mockedUser ( ) ,
119122 setUser : jest . fn ( ) ,
120- } )
123+ config : {
124+ organisation : mockedOrganisation ,
125+ custodian : mockedCustodian ,
126+ } ,
127+ } as unknown as StoreState )
121128 ) ;
122129
123130 render ( < NavBar loggedIn /> ) ;
@@ -127,6 +134,40 @@ describe("NavBar Component", () => {
127134 expect ( handleLogout ) . toHaveBeenCalled ( ) ;
128135 } ) ;
129136
137+ it ( "displays 'Organisation' chip when the user belongs to an organisation" , ( ) => {
138+ mockUseStore . mockImplementation ( selector =>
139+ selector ( {
140+ getUser : ( ) => mockedUser ( ) ,
141+ setUser : jest . fn ( ) ,
142+ config : {
143+ organisation : mockedOrganisation ,
144+ custodian : undefined ,
145+ } ,
146+ } as unknown as StoreState )
147+ ) ;
148+
149+ render ( < NavBar loggedIn /> ) ;
150+
151+ expect ( screen . getByText ( AccountType . ORGANISATION ) ) . toBeInTheDocument ( ) ;
152+ } ) ;
153+
154+ it ( "displays 'Custodian' chip when the user belongs to an custodian" , ( ) => {
155+ mockUseStore . mockImplementation ( selector =>
156+ selector ( {
157+ getUser : ( ) => mockedUser ( ) ,
158+ setUser : jest . fn ( ) ,
159+ config : {
160+ organisation : undefined ,
161+ custodian : mockedCustodian ,
162+ } ,
163+ } as unknown as StoreState )
164+ ) ;
165+
166+ render ( < NavBar loggedIn /> ) ;
167+
168+ expect ( screen . getByText ( AccountType . CUSTODIAN ) ) . toBeInTheDocument ( ) ;
169+ } ) ;
170+
130171 it ( "displays 'My Account' and 'Sign Out' if the user is authenticated" , ( ) => {
131172 mockGetMe . mockResolvedValueOnce ( {
132173 status : 200 ,
@@ -137,7 +178,11 @@ describe("NavBar Component", () => {
137178 selector ( {
138179 getUser : ( ) => mockedUser ( ) ,
139180 setUser : jest . fn ( ) ,
140- } )
181+ config : {
182+ organisation : undefined ,
183+ custodian : undefined ,
184+ } ,
185+ } as unknown as StoreState )
141186 ) ;
142187
143188 ( get as jest . Mock ) . mockReturnValue ( mockedJwt ) ;
0 commit comments