Skip to content

Commit

Permalink
feat: creating the tests for the dashboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
gony02 committed Mar 4, 2024
1 parent 94d5707 commit 17988dd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
3 changes: 1 addition & 2 deletions webapp/src/pages/Rules.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Center } from "@chakra-ui/layout";
import { Text, Grid, Flex, Heading, Button, Box } from "@chakra-ui/react";
import { Text, Flex, Heading, Button, Box } from "@chakra-ui/react";
import React from "react";
import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import ButtonEf from '../components/ButtonEf';

export default function Rules() {
const navigate = useNavigate();
Expand Down
52 changes: 52 additions & 0 deletions webapp/src/tests/Dashboard.test.js
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.
});

0 comments on commit 17988dd

Please sign in to comment.