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.
- Loading branch information
1 parent
ab327ad
commit 2241bbd
Showing
1 changed file
with
41 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,41 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, screen, waitFor, act } from '@testing-library/react'; | ||
import Question from './Question'; | ||
import useAuthUser from 'react-auth-kit/hooks/useAuthUser'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import axios from 'axios'; | ||
const mockAxios = new MockAdapter(axios); | ||
|
||
const mock = jest.fn(); | ||
|
||
jest.mock('react-auth-kit/hooks/useAuthUser'); | ||
jest.mock('react-router-dom', () => ({ | ||
useNavigate: () => mock, | ||
})); | ||
|
||
describe('Question page', () => { | ||
beforeEach(() => { | ||
mockAxios.reset(); | ||
}); | ||
|
||
it('should render a flags question if category is flags', async () => { | ||
useAuthUser.mockReturnValue({ username: 'testUser' }); | ||
|
||
mockAxios.onGet('http://localhost:8000/imgs/flags/question').reply(200, | ||
{ | ||
question: "Which of the following flags belongs to Spain?", | ||
images:["SpainImage","EnglandImage","PolandImage","GermanyImage"] | ||
}); | ||
|
||
render(<Question type="imgs" category="flags"/>); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText(/Which of the following flags belongs to/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Score/i)).toBeInTheDocument(); | ||
}); | ||
|
||
let imgs = [] | ||
imgs = screen.getAllByRole("button") | ||
expect(imgs.length).toBe(4) | ||
}); | ||
}); |