@@ -26,15 +26,36 @@ import {
2626 IconUsers ,
2727 IconUserStar ,
2828} from '@tabler/icons-react'
29- import { fireEvent , render , screen } from '@testing-library/react'
29+ import { cleanup , fireEvent , render , screen } from '@testing-library/react'
3030import { type JSX , ReactNode } from 'react'
31- import { beforeAll , describe , expect , it , vi } from 'vitest'
31+ import { afterEach , beforeAll , describe , expect , it , vi } from 'vitest'
3232
3333import { NavBar } from './NavBar'
3434
3535const BASE_PATH = 'http://localhost:3000'
3636
37+ vi . mock ( 'react-i18next' , async ( ) => {
38+ const reactI18next = ( await vi . importActual ( 'react-i18next' ) ) as Record <
39+ string ,
40+ unknown
41+ >
42+
43+ return {
44+ ...reactI18next ,
45+ getI18n : ( ) => ( { language : 'en' } ) ,
46+ }
47+ } )
48+
49+ vi . mock ( 'next/navigation' , ( ) => ( {
50+ usePathname : ( ) => '/en/admin/users' ,
51+ } ) )
52+
3753describe ( 'NavBar' , ( ) => {
54+ afterEach ( ( ) => {
55+ cleanup ( )
56+ vi . clearAllMocks ( )
57+ } )
58+
3859 const NAV_LINKS : NavLink [ ] = [
3960 {
4061 icon : < IconHome /> ,
@@ -150,19 +171,19 @@ describe('NavBar', () => {
150171
151172 expect (
152173 screen . getByText ( 'navigation.users.label' ) . closest ( 'a' ) ,
153- ) . toHaveProperty ( 'href' , `${ BASE_PATH } /admin/ users` )
174+ ) . toHaveProperty ( 'href' , `${ BASE_PATH } /users` )
154175
155176 expect (
156177 screen . getByText ( 'navigation.roles.label' ) . closest ( 'a' ) ,
157- ) . toHaveProperty ( 'href' , `${ BASE_PATH } /admin/ roles` )
178+ ) . toHaveProperty ( 'href' , `${ BASE_PATH } /roles` )
158179
159180 expect (
160181 screen . getByText ( 'navigation.rights.label' ) . closest ( 'a' ) ,
161- ) . toHaveProperty ( 'href' , `${ BASE_PATH } /admin/ rights` )
182+ ) . toHaveProperty ( 'href' , `${ BASE_PATH } /rights` )
162183
163184 expect (
164185 screen . getByText ( 'navigation.translations.label' ) . closest ( 'a' ) ,
165- ) . toHaveProperty ( 'href' , `${ BASE_PATH } /admin/ translations` )
186+ ) . toHaveProperty ( 'href' , `${ BASE_PATH } /translations` )
166187
167188 renderedComponent . unmount ( )
168189 } )
@@ -178,15 +199,15 @@ describe('NavBar', () => {
178199
179200 expect (
180201 screen . getByText ( 'navigation.users.label' ) . closest ( 'a' ) ,
181- ) . toHaveProperty ( 'href' , `${ BASE_PATH } /admin/ users` )
202+ ) . toHaveProperty ( 'href' , `${ BASE_PATH } /users` )
182203
183204 expect (
184205 screen . getByText ( 'navigation.roles.label' ) . closest ( 'a' ) ,
185- ) . toHaveProperty ( 'href' , `${ BASE_PATH } /admin/ roles` )
206+ ) . toHaveProperty ( 'href' , `${ BASE_PATH } /roles` )
186207
187208 expect (
188209 screen . getByText ( 'navigation.rights.label' ) . closest ( 'a' ) ,
189- ) . toHaveProperty ( 'href' , `${ BASE_PATH } /admin/ rights` )
210+ ) . toHaveProperty ( 'href' , `${ BASE_PATH } /rights` )
190211
191212 expect ( screen . queryByText ( 'navigation.translations.label' ) ) . toBeNull ( )
192213
0 commit comments