Skip to content

Commit

Permalink
test: add test for dashboard page
Browse files Browse the repository at this point in the history
  • Loading branch information
sahsisunny committed Nov 11, 2023
1 parent 93796af commit 48feb0d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions __tests__/pages/dashboard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { fireEvent, render, screen, waitFor } from '@testing-library/react';

import Dashboard from '../../src/pages/dashboard';
import React from 'react';
import fetchMock from 'jest-fetch-mock';

describe('Dashboard', () => {
beforeEach(() => {
fetchMock.resetMocks();
});

const mockWriteText = jest.fn();
global.navigator.clipboard = { writeText: mockWriteText };

it('renders without crashing', () => {
render(<Dashboard />);
expect(screen.getByText('URL Shortener')).toBeInTheDocument();
});

it('displays a message when no URLs are found', async () => {
fetchMock.mockResponseOnce(JSON.stringify({ urls: [] }));
render(<Dashboard />);
await waitFor(() => {
expect(screen.getByText('No URLs found')).toBeInTheDocument();
});
});

it('navigates to create page when "Create one" link is clicked', async () => {
render(<Dashboard />);
const createLink = screen.getByText('Create one');
fireEvent.click(createLink);

await waitFor(() => {
expect(screen.getByText('URL Shortener')).toBeInTheDocument();
});
});
});

0 comments on commit 48feb0d

Please sign in to comment.