generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: creating the tests for the dashboard.
- Loading branch information
Showing
2 changed files
with
53 additions
and
2 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
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,52 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, screen, waitFor, act, getByLabelText, getByTestId } from '@testing-library/react'; | ||
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import Login from '../pages/Login'; | ||
import { MemoryRouter, createMemoryRouter } from 'react-router'; | ||
import router from '../components/Router'; | ||
import Dashboard from '../pages/Dashboard'; | ||
|
||
const mockAxios = new MockAdapter(axios); | ||
const mockRouter = createMemoryRouter(router); | ||
|
||
describe('Dashboard component', () => { | ||
it('renders dashboard elements correctly', async () => { | ||
const { getByText } = render(<MemoryRouter><Dashboard/></MemoryRouter>); | ||
|
||
// Check if the heading is rendered | ||
expect(getByText("common.dashboard")).toBeInTheDocument(); | ||
|
||
// Check if the buttons are rendered | ||
expect(screen.getByTestId('Rules')).toBeInTheDocument(); | ||
expect(screen.getByTestId('Play')).toBeInTheDocument(); | ||
expect(screen.getByTestId('Statistics')).toBeInTheDocument(); | ||
|
||
// Check if the logout button is rendered | ||
expect(screen.getByText(/logout/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('navigates to the rules route on button click', () => { | ||
// Render the component | ||
render(<MemoryRouter><Dashboard /></MemoryRouter>); | ||
|
||
const rulesButton = screen.getByTestId('Rules'); | ||
fireEvent.click(rulesButton); | ||
|
||
// Check the change of path | ||
expect(screen.getByText("common.rules")).toBeInTheDocument(); | ||
}); | ||
|
||
it('do not navigates to the statistics route on button click', () => { | ||
// Render the component | ||
render(<MemoryRouter><Dashboard /></MemoryRouter>); | ||
|
||
const statisticsButton = screen.getByTestId('Statistics'); | ||
fireEvent.click(statisticsButton); | ||
|
||
// Check the change of path | ||
expect(screen.getByText("common.dashboard")).toBeInTheDocument(); | ||
}); | ||
|
||
// Test the play and log out buttons. | ||
}); |