Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import {
DropdownMenuLabel,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { Avatar, AvatarFallback, AvatarImage } from '../../ui/avatar';
import { ModeToggle } from '../../utils/ThemeModeToggle';

import { ModeToggle } from '@/components/utils/ThemeModeToggle';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';

import { buttonVariants } from '@/components/ui/button';
import {
routeList,
Expand All @@ -41,7 +43,7 @@ import {
exportTasksAsTXT,
} from '@/components/utils/ExportTasks';
import { useState } from 'react';
import { DevLogs } from '../DevLogs/DevLogs';
import { DevLogs } from '@/components/HomeComponents/DevLogs/DevLogs';
import { useTaskAutoSync } from '@/components/utils/TaskAutoSync';
import { Label } from '@/components/ui/label';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
jest.mock('@/components/ui/slider', () => ({
Slider: () => <div data-testid="sync-slider" />,
}));
jest.mock('@/components/ui/switch', () => ({
Switch: ({ onCheckedChange }: any) => (
<button onClick={() => onCheckedChange(true)}>toggle</button>
),
}));
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { NavbarDesktop } from '../NavbarDesktop';
import { Props, routeList } from '../navbar-utils';

// Mock external dependencies
jest.mock('../navbar-utils', () => ({
deleteAllTasks: jest.fn(),
handleLogout: jest.fn(),
Expand All @@ -13,8 +21,17 @@ jest.mock('../navbar-utils', () => ({
{ href: '#faq', label: 'FAQ' },
],
}));
jest.mock('@/components/HomeComponents/DevLogs/DevLogs', () => ({
DevLogs: () => <div data-testid="dev-logs-dialog" />,
}));

jest.mock('@/components/utils/URLs', () => ({
url: {
githubRepoURL: 'https://github.com/test/repo',
},
}));
const mockSetIsLoading = jest.fn();

const mockProps: Props = {
imgurl: 'http://example.com/image.png',
email: 'test@example.com',
Expand All @@ -34,22 +51,51 @@ describe('NavbarDesktop', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('renders the navigation links correctly', () => {
render(<NavbarDesktop {...extendedProps} />);

routeList.forEach((route) => {
expect(screen.getByText(route.label)).toBeInTheDocument();
});
});
it('opens user menu and displays email', async () => {
render(<NavbarDesktop {...extendedProps} />);

const avatarFallback = screen.getByText('CN');
await userEvent.click(avatarFallback);

expect(screen.getAllByText('test@example.com')[0]).toBeInTheDocument();
});

it('opens github link when clicked', async () => {
const openSpy = jest.spyOn(window, 'open').mockImplementation(() => null);

it('displays user email and handles dropdown menu actions', () => {
const user = userEvent.setup();
render(<NavbarDesktop {...extendedProps} />);

await user.click(screen.getByText('CN'));
await user.click(screen.getByText('GitHub'));

expect(openSpy).toHaveBeenCalledWith(
'https://github.com/test/repo',
'_blank'
);

openSpy.mockRestore();
});
it('shows slider when auto sync is enabled', async () => {
const user = userEvent.setup();
render(<NavbarDesktop {...extendedProps} />);

await user.click(screen.getByText('CN'));
await user.click(screen.getByText('toggle'));

expect(screen.getByTestId('sync-slider')).toBeInTheDocument();
});
});

describe('NavbarDesktop component using snapshot', () => {
test('renders correctly', () => {
describe('NavbarDesktop snapshot', () => {
it('renders correctly', () => {
const { asFragment } = render(<NavbarDesktop {...extendedProps} />);
expect(asFragment()).toMatchSnapshot();
});
Expand Down