Skip to content
Merged
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
@@ -1,4 +1,8 @@
import { render, screen, fireEvent } from '@testing-library/react';
import {
exportTasksAsJSON,
exportTasksAsTXT,
} from '@/components/utils/ExportTasks';
import { NavbarMobile } from '../NavbarMobile';
import {
deleteAllTasks,
Expand All @@ -7,7 +11,12 @@ import {
routeList,
} from '../navbar-utils';

jest.mock('../navbar-utils', () => ({
jest.mock('@/components/utils/ExportTasks', () => ({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mocked export fnc,s

exportTasksAsJSON: jest.fn(),
exportTasksAsTXT: jest.fn(),
}));

jest.mock('@/components/HomeComponents/Navbar/navbar-utils', () => ({
deleteAllTasks: jest.fn(),
handleLogout: jest.fn(),
routeList: [
Expand Down Expand Up @@ -114,6 +123,34 @@ describe('NavbarMobile', () => {
fireEvent.click(logoutButton);
expect(handleLogout).toHaveBeenCalled();
});

test('export task as json and close menu', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added test to ensure that export fnc calls and close menu for both json && txt
and added test to check the autosync renders in dialog

render(<NavbarMobile {...openProps} />);

fireEvent.click(screen.getByText('Export Tasks'));
fireEvent.click(screen.getByText('Download .json'));

expect(exportTasksAsJSON).toHaveBeenCalledWith(openProps.tasks);
expect(mockSetIsOpen).toHaveBeenCalledWith(false);
});

test('export task as txt and close menu', () => {
render(<NavbarMobile {...openProps} />);

fireEvent.click(screen.getByText('Export Tasks'));
fireEvent.click(screen.getByText('Download .txt'));

expect(exportTasksAsTXT).toHaveBeenCalledWith(openProps.tasks);
expect(mockSetIsOpen).toHaveBeenCalledWith(false);
});

test('opens auto-sync dialog', () => {
render(<NavbarMobile {...openProps} />);

fireEvent.click(screen.getByText('Auto-sync'));

expect(screen.getByText(/Enable Auto-Sync/i)).toBeInTheDocument();
});
});

describe('NavbarMobile component using snapshot', () => {
Expand Down
Loading