forked 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.
Merge pull request #414 from Arquisoft/sergio
Mejorando tests Login, UsersList y RankingList
- Loading branch information
Showing
12 changed files
with
448 additions
and
96 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
coverage | ||
docs/build | ||
docs/build | ||
.idea/ |
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
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 |
---|---|---|
@@ -1,43 +1,131 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { render, screen, act } from '@testing-library/react'; | ||
import GeneratedQuestionsList from './GeneratedQuestionsList'; | ||
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
|
||
jest.mock('axios'); | ||
|
||
const mockAxios = new MockAdapter(axios); | ||
|
||
describe('GeneratedQuestionsList component', () => { | ||
// Test for rendering the component and checking the main heading | ||
test('renders GeneratedQuestionsList component and main heading', () => { | ||
render(<GeneratedQuestionsList />); | ||
beforeEach(() => { | ||
axios.get.mockResolvedValue({ | ||
status: 200, | ||
data: [ | ||
{ | ||
generatedQuestionBody: "¿A qué género literario pertenece 'Cinco horas con Mario'?", | ||
correctAnswer: 'Narrativo' | ||
}, | ||
{ | ||
generatedQuestionBody: "¿De qué grupo es la canción 'Vino Tinto'?", | ||
correctAnswer: 'Estopa' | ||
}, | ||
{ | ||
generatedQuestionBody: "¿Cuál es la capital de Portugal?", | ||
correctAnswer: 'Lisboa' | ||
}, | ||
{ | ||
generatedQuestionBody: "¿Quién escribió la novela 'El Extranjero'?", | ||
correctAnswer: 'Albert Camus' | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
// Check if the main heading is in the document | ||
test('renders GeneratedQuestionsList component and main heading', async () => { | ||
await act( async () => { | ||
render(<GeneratedQuestionsList setError={() => {}} />); | ||
}); | ||
const heading = screen.getByRole('heading', { name: /Lista de preguntas/i }); | ||
expect(heading).toBeInTheDocument(); | ||
}); | ||
|
||
// Test for rendering the table | ||
it('should display the table', () => { | ||
render(<GeneratedQuestionsList />); | ||
|
||
it('should display the table', async () => { | ||
await act( async () => { | ||
render(<GeneratedQuestionsList setError={() => {}} />); | ||
}); | ||
const table = screen.getByRole('table'); | ||
expect(table).toBeInTheDocument(); | ||
}); | ||
|
||
// Test for rendering the table headers | ||
test('renders table headers', () => { | ||
render(<GeneratedQuestionsList />); | ||
|
||
// Check if the table headers are in the document | ||
test('renders table headers', async () => { | ||
await act( async () => { | ||
render(<GeneratedQuestionsList setError={() => {}} />); | ||
}); | ||
const questionHeader = screen.getByRole('columnheader', { name: /Pregunta/i }); | ||
const answerHeader = screen.getByRole('columnheader', { name: /Respuesta Correcta/i }); | ||
expect(questionHeader).toBeInTheDocument(); | ||
expect(answerHeader).toBeInTheDocument(); | ||
}); | ||
|
||
// Test for rendering the table rows | ||
test('renders table rows', () => { | ||
render(<GeneratedQuestionsList />); | ||
test('renders table rows', async () => { | ||
await act( async () => { | ||
render(<GeneratedQuestionsList setError={() => {}} />); | ||
}); | ||
const tableRows = screen.getAllByRole('row'); | ||
expect(tableRows).not.toHaveLength(0); | ||
}); | ||
|
||
test('should order questions by questionBody correctly', async () => { | ||
await act(async () => { | ||
render(<GeneratedQuestionsList setError={() => {}} />); | ||
}); | ||
|
||
const questionBodyHeader = screen.getByRole('columnheader', { name: /Pregunta/i }); | ||
|
||
await act(async() => { | ||
questionBodyHeader.click(); | ||
}); | ||
|
||
let rows = await screen.findAllByRole('row'); | ||
|
||
expect(rows[1]).toHaveTextContent("¿A qué género literario pertenece 'Cinco horas con Mario'?"); | ||
expect(rows[2]).toHaveTextContent("¿Cuál es la capital de Portugal?"); | ||
expect(rows[3]).toHaveTextContent("¿De qué grupo es la canción 'Vino Tinto'?"); | ||
expect(rows[4]).toHaveTextContent("¿Quién escribió la novela 'El Extranjero'?"); | ||
|
||
await act(async() => { | ||
questionBodyHeader.click(); | ||
}); | ||
|
||
rows = await screen.findAllByRole('row'); | ||
|
||
// Check if the table rows are in the document | ||
const tableRows = screen.getAllByRole('row'); | ||
expect(tableRows).not.toHaveLength(0); | ||
}); | ||
expect(rows[4]).toHaveTextContent("¿A qué género literario pertenece 'Cinco horas con Mario'?"); | ||
expect(rows[3]).toHaveTextContent("¿Cuál es la capital de Portugal?"); | ||
expect(rows[2]).toHaveTextContent("¿De qué grupo es la canción 'Vino Tinto'?"); | ||
expect(rows[1]).toHaveTextContent("¿Quién escribió la novela 'El Extranjero'?"); | ||
}); | ||
|
||
test('should order questions by answer correctly', async () => { | ||
await act(async () => { | ||
render(<GeneratedQuestionsList setError={() => {}} />); | ||
}); | ||
|
||
const answerHeader = screen.getByRole('columnheader', { name: /Respuesta Correcta/i }); | ||
|
||
await act(async() => { | ||
answerHeader.click(); | ||
}); | ||
|
||
let rows = await screen.findAllByRole('row'); | ||
|
||
expect(rows[1]).toHaveTextContent("Albert Camus"); | ||
expect(rows[2]).toHaveTextContent("Estopa"); | ||
expect(rows[3]).toHaveTextContent("Lisboa"); | ||
expect(rows[4]).toHaveTextContent("Narrativo"); | ||
|
||
|
||
await act(async() => { | ||
answerHeader.click(); | ||
}); | ||
|
||
rows = await screen.findAllByRole('row'); | ||
|
||
expect(rows[4]).toHaveTextContent("Albert Camus"); | ||
expect(rows[3]).toHaveTextContent("Estopa"); | ||
expect(rows[2]).toHaveTextContent("Lisboa"); | ||
expect(rows[1]).toHaveTextContent("Narrativo"); | ||
}); | ||
|
||
}); |
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
Oops, something went wrong.