1+ jest . mock ( '@/components/ui/slider' , ( ) => ( {
2+ Slider : ( ) => < div data-testid = "sync-slider" /> ,
3+ } ) ) ;
4+ jest . mock ( '@/components/ui/switch' , ( ) => ( {
5+ Switch : ( { onCheckedChange } : any ) => (
6+ < button onClick = { ( ) => onCheckedChange ( true ) } > toggle</ button >
7+ ) ,
8+ } ) ) ;
9+ jest . mock ( '@/components/utils/ExportTasks' , ( ) => ( {
10+ exportTasksAsJSON : jest . fn ( ) ,
11+ exportTasksAsTXT : jest . fn ( ) ,
12+ } ) ) ;
13+ jest . mock ( '../navbar-utils' , ( ) => ( {
14+ ...jest . requireActual ( '../navbar-utils' ) ,
15+ deleteAllTasks : jest . fn ( ) ,
16+ } ) ) ;
17+ jest . mock ( '@/components/ui/dialog' , ( ) => ( {
18+ Dialog : ( { children } : any ) => < div > { children } </ div > ,
19+ DialogTrigger : ( { children } : any ) => < div > { children } </ div > ,
20+ DialogContent : ( { children } : any ) => (
21+ < div data-testid = "export-dialog" > { children } </ div >
22+ ) ,
23+ DialogHeader : ( { children } : any ) => < div > { children } </ div > ,
24+ DialogTitle : ( { children } : any ) => < h2 > { children } </ h2 > ,
25+ DialogDescription : ( { children } : any ) => < p > { children } </ p > ,
26+ } ) ) ;
127import { render , screen } from '@testing-library/react' ;
28+ import userEvent from '@testing-library/user-event' ;
229import { NavbarDesktop } from '../NavbarDesktop' ;
330import { Props , routeList } from '../navbar-utils' ;
431
5- // Mock external dependencies
632jest . mock ( '../navbar-utils' , ( ) => ( {
733 deleteAllTasks : jest . fn ( ) ,
834 handleLogout : jest . fn ( ) ,
@@ -13,8 +39,17 @@ jest.mock('../navbar-utils', () => ({
1339 { href : '#faq' , label : 'FAQ' } ,
1440 ] ,
1541} ) ) ;
42+ jest . mock ( '@/components/HomeComponents/DevLogs/DevLogs' , ( ) => ( {
43+ DevLogs : ( ) => < div data-testid = "dev-logs-dialog" /> ,
44+ } ) ) ;
1645
46+ jest . mock ( '@/components/utils/URLs' , ( ) => ( {
47+ url : {
48+ githubRepoURL : 'https://github.com/test/repo' ,
49+ } ,
50+ } ) ) ;
1751const mockSetIsLoading = jest . fn ( ) ;
52+
1853const mockProps : Props = {
1954 imgurl : 'http://example.com/image.png' ,
2055 email : 'test@example.com' ,
@@ -34,22 +69,77 @@ describe('NavbarDesktop', () => {
3469 afterEach ( ( ) => {
3570 jest . clearAllMocks ( ) ;
3671 } ) ;
37-
3872 it ( 'renders the navigation links correctly' , ( ) => {
3973 render ( < NavbarDesktop { ...extendedProps } /> ) ;
4074
4175 routeList . forEach ( ( route ) => {
4276 expect ( screen . getByText ( route . label ) ) . toBeInTheDocument ( ) ;
4377 } ) ;
4478 } ) ;
79+ it ( 'opens user menu and displays email' , async ( ) => {
80+ render ( < NavbarDesktop { ...extendedProps } /> ) ;
4581
46- it ( 'displays user email and handles dropdown menu actions' , ( ) => {
82+ const avatarFallback = screen . getByText ( 'CN' ) ;
83+ await userEvent . click ( avatarFallback ) ;
84+
85+ expect ( screen . getAllByText ( 'test@example.com' ) [ 0 ] ) . toBeInTheDocument ( ) ;
86+ } ) ;
87+
88+ it ( 'opens github link when clicked' , async ( ) => {
89+ const openSpy = jest . spyOn ( window , 'open' ) . mockImplementation ( ( ) => null ) ;
90+
91+ const user = userEvent . setup ( ) ;
4792 render ( < NavbarDesktop { ...extendedProps } /> ) ;
93+
94+ await user . click ( screen . getByText ( 'CN' ) ) ;
95+ await user . click ( screen . getByText ( 'GitHub' ) ) ;
96+
97+ expect ( openSpy ) . toHaveBeenCalledWith (
98+ 'https://github.com/test/repo' ,
99+ '_blank'
100+ ) ;
101+
102+ openSpy . mockRestore ( ) ;
103+ } ) ;
104+ it ( 'exports tasks as TXT and triggers export handler' , async ( ) => {
105+ const user = userEvent . setup ( ) ;
106+ const { exportTasksAsTXT } = require ( '@/components/utils/ExportTasks' ) ;
107+
108+ render ( < NavbarDesktop { ...extendedProps } /> ) ;
109+
110+ await user . click ( screen . getByText ( 'CN' ) ) ;
111+ await user . click ( screen . getByText ( 'Export tasks' ) ) ;
112+
113+ expect ( screen . getByText ( / W o u l d y o u l i k e t o d o w n l o a d / i) ) . toBeInTheDocument ( ) ;
114+
115+ await user . click ( screen . getByText ( 'Download .txt' ) ) ;
116+
117+ expect ( exportTasksAsTXT ) . toHaveBeenCalledWith ( [ ] ) ;
118+ } ) ;
119+ it ( 'exports tasks as JSON' , async ( ) => {
120+ const { exportTasksAsJSON } = require ( '@/components/utils/ExportTasks' ) ;
121+
122+ render ( < NavbarDesktop { ...extendedProps } /> ) ;
123+
124+ await userEvent . click ( screen . getByText ( 'CN' ) ) ;
125+ await userEvent . click ( screen . getByText ( 'Export tasks' ) ) ;
126+ await userEvent . click ( screen . getByText ( 'Download .json' ) ) ;
127+
128+ expect ( exportTasksAsJSON ) . toHaveBeenCalledWith ( [ ] ) ;
129+ } ) ;
130+ it ( 'shows slider when auto sync is enabled' , async ( ) => {
131+ const user = userEvent . setup ( ) ;
132+ render ( < NavbarDesktop { ...extendedProps } /> ) ;
133+
134+ await user . click ( screen . getByText ( 'CN' ) ) ;
135+ await user . click ( screen . getByText ( 'toggle' ) ) ;
136+
137+ expect ( screen . getByTestId ( 'sync-slider' ) ) . toBeInTheDocument ( ) ;
48138 } ) ;
49139} ) ;
50140
51- describe ( 'NavbarDesktop component using snapshot' , ( ) => {
52- test ( 'renders correctly' , ( ) => {
141+ describe ( 'NavbarDesktop snapshot' , ( ) => {
142+ it ( 'renders correctly' , ( ) => {
53143 const { asFragment } = render ( < NavbarDesktop { ...extendedProps } /> ) ;
54144 expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
55145 } ) ;
0 commit comments