forked from pglez82/asw2324_0
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from Arquisoft/pablo
Test HistoricalData y RegisteredUsers
- Loading branch information
Showing
4 changed files
with
95 additions
and
3 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,44 @@ | ||
import React from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import HistoricalData from './HistoricalData'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
|
||
const mockAxios = new MockAdapter(axios); | ||
|
||
describe('HistoricalData component', () => { | ||
beforeEach(() => { | ||
mockAxios.reset(); | ||
}); | ||
|
||
it('muestra la página con el histórico de preguntas generadas', async () => { | ||
|
||
const question1 = ['¿Cual es la capital de Venezuela?', 'Caracas', 'Doha', 'Barcelona', 'Nasáu']; | ||
const question2 = ['¿Cual es la capital de Francia?', 'París', 'Londres', 'Madrid', 'Roma']; | ||
const mockUsers = [question1, question2]; | ||
mockAxios.onGet("http://localhost:8000/getquestionshistory").reply(200, mockUsers); | ||
|
||
render(<Router> | ||
<HistoricalData /> | ||
</Router>); | ||
|
||
await waitFor(() => { | ||
|
||
expect(screen.getByText('¿Cual es la capital de Venezuela?')).toBeInTheDocument(); | ||
expect(screen.getByText('Caracas')).toBeInTheDocument(); | ||
expect(screen.getByText('Doha')).toBeInTheDocument(); | ||
expect(screen.getByText('Barcelona')).toBeInTheDocument(); | ||
expect(screen.getByText('Nasáu')).toBeInTheDocument(); | ||
|
||
expect(screen.getByText('¿Cual es la capital de Francia?')).toBeInTheDocument(); | ||
expect(screen.getByText('París')).toBeInTheDocument(); | ||
expect(screen.getByText('Londres')).toBeInTheDocument(); | ||
expect(screen.getByText('Madrid')).toBeInTheDocument(); | ||
expect(screen.getByText('Roma')).toBeInTheDocument(); | ||
|
||
}); | ||
}); | ||
}); | ||
|
||
|
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,32 @@ | ||
import React from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import {BrowserRouter as Router} from "react-router-dom"; | ||
import RegisteredUsers from './RegisteredUsers'; | ||
|
||
const mockAxios = new MockAdapter(axios); | ||
|
||
describe('Registered Users component', () => { | ||
beforeEach(() => { | ||
mockAxios.reset(); | ||
}); | ||
|
||
it('muestra todos los usuarios registrados', async () => { | ||
const user1 = ['pablo', '4/23/2024']; | ||
const mockUsers = [user1]; | ||
mockAxios.onGet("http://localhost:8000/getregisteredusers").reply(200, mockUsers); | ||
|
||
render( | ||
<Router> | ||
<RegisteredUsers /> | ||
</Router>); | ||
|
||
await waitFor(() => { | ||
|
||
expect(screen.getByText('pablo')).toBeInTheDocument(); | ||
expect(screen.getByText('4/23/2024')).toBeInTheDocument(); | ||
}); | ||
|
||
}); | ||
}); |