generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93796af
commit 48feb0d
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |