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.
#29 Mas tests unitarios en el frontend
- Loading branch information
1 parent
a8ba435
commit 0cb68fa
Showing
11 changed files
with
232 additions
and
39 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
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,119 @@ | ||
import { screen, render, fireEvent, waitFor } from "@testing-library/react" | ||
import Game from "./Game" | ||
import i18n from '../../translation/i18n'; | ||
import { getUser, getCategories, getQuestions, updateUser } from '../../backend/dataSource'; | ||
import { MemoryRouter } from "react-router-dom"; | ||
|
||
describe('Game', () => { | ||
const mockUser = { | ||
id: '123', | ||
name: 'Alvaro', | ||
totalGames: 1, | ||
correctAnswers: 8, | ||
inCorrectAnswers: 24, | ||
totalQuestionAnswered: 15, | ||
lastCategoryPlayed: 'Deportes', | ||
}; | ||
|
||
const mockCategories = [ | ||
{ id: '1', name: 'Deportes' }, | ||
{ id: '2', name: 'Ciencia' }, | ||
]; | ||
|
||
const mockQuestions = [ | ||
{ | ||
text: '¿Cuál es el planeta más grande?', | ||
timeLimit: 10, | ||
answers: [ | ||
{ text: 'Júpiter', isCorrect: true }, | ||
{ text: 'Saturno', isCorrect: false }, | ||
{ text: 'Tierra', isCorrect: false }, | ||
{ text: 'Marte', isCorrect: false }, | ||
], | ||
}, | ||
]; | ||
|
||
beforeAll(() => { | ||
i18n.changeLanguage('Spain'); | ||
}); | ||
|
||
// beforeEach(() => { | ||
// // Mockear las funciones asíncronas | ||
// jest.mock('../../backend/dataSource', () => ({ | ||
// getUser: jest.fn().mockResolvedValue(mockUser), | ||
// getCategories: jest.fn().mockResolvedValue(mockCategories), | ||
// getQuestions: jest.fn().mockResolvedValue(mockQuestions) | ||
// })); | ||
// }); | ||
|
||
test('Game renders correctly', () => { | ||
render(<Game/>) | ||
|
||
const element = screen.getByTestId('syg-game-container') | ||
expect(element).toBeInTheDocument(); | ||
}) | ||
|
||
test('Header components renders correctly', () => { | ||
render(<Game/>) | ||
|
||
const gameContent = screen.getByTestId('syg-game-content') | ||
expect(gameContent).toBeInTheDocument(); | ||
|
||
// const gameStart = screen.getByTestId('syg-game-content-start-game') | ||
// expect(gameStart).toBeInTheDocument(); | ||
|
||
// const gameStartOptions = screen.getByTestId('syg-game-content-start-game-options') | ||
// expect(gameStartOptions).toBeInTheDocument(); | ||
|
||
}) | ||
|
||
|
||
// test('starts game and answers questions', async () => { | ||
// render( | ||
// <MemoryRouter> | ||
// <Game /> | ||
// </MemoryRouter> | ||
// ); | ||
|
||
// // Esperar a que se carguen categorías | ||
// await waitFor(() => { | ||
// expect(screen.getByText('Deportes')).toBeInTheDocument(); | ||
// }); | ||
|
||
// // Iniciar el juego | ||
// fireEvent.click(screen.getByText('Deportes')); // Elige una categoría para comenzar | ||
|
||
// await waitFor(() => { | ||
// expect(screen.getByText('¿Cuál es el planeta más grande?')).toBeInTheDocument(); | ||
// }); | ||
|
||
// // Responder una pregunta | ||
// fireEvent.click(screen.getByText('Júpiter')); // Respuesta correcta | ||
|
||
// await waitFor(() => { | ||
// expect(updateUser).toHaveBeenCalled(); // Verificar que `updateUser` fue llamado | ||
// }); | ||
// }); | ||
|
||
// test('finishes the game and shows results', async () => { | ||
// render( | ||
// <MemoryRouter> | ||
// <Game /> | ||
// </MemoryRouter> | ||
// ); | ||
|
||
// // Iniciar el juego | ||
// fireEvent.click(screen.getByText('Deportes')); // Elegir una categoría | ||
|
||
// await waitFor(() => { | ||
// expect(screen.getByText('¿Cuál es el planeta más grande?')).toBeInTheDocument(); | ||
// }); | ||
|
||
// // Responder todas las preguntas y terminar el juego | ||
// fireEvent.click(screen.getByText('Júpiter')); // Primera respuesta | ||
// await waitFor(() => { | ||
// expect(screen.getByText('game.results.title')).toBeInTheDocument(); // Verificar que muestra los resultados | ||
// }); | ||
// }); | ||
|
||
}) |
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,58 @@ | ||
import { screen, render, fireEvent } from "@testing-library/react" | ||
import StadisticsGame from "./StadisticsGame" | ||
import i18n from '../../translation/i18n'; | ||
|
||
describe('StadisticsGame', () => { | ||
beforeAll(() => { | ||
i18n.changeLanguage('Spain'); | ||
}); | ||
|
||
test('StadisticsGame renders correctly', () => { | ||
render(<StadisticsGame correctAnswers={10} incorrectAnswers={20}/>) | ||
|
||
const element = screen.getByTestId('stadistic-game-container') | ||
expect(element).toBeInTheDocument(); | ||
}) | ||
|
||
test('StadisticsGame components renders correctly', () => { | ||
render(<StadisticsGame correctAnswers={10} incorrectAnswers={20}/>) | ||
|
||
const stadisticgameCorrect = screen.getByTestId('stadistic-game-correct') | ||
expect(stadisticgameCorrect).toBeInTheDocument(); | ||
|
||
const stadisticgameCorrectInfo = screen.getByTestId('stadistic-game-correct-info') | ||
expect(stadisticgameCorrectInfo).toBeInTheDocument(); | ||
|
||
const stadisticgameCorrectBar = screen.getByTestId('stadistic-game-correct-bar') | ||
expect(stadisticgameCorrectBar).toBeInTheDocument(); | ||
|
||
const stadisticgameInCorrect = screen.getByTestId('stadistic-game-incorrect') | ||
expect(stadisticgameInCorrect).toBeInTheDocument(); | ||
|
||
const stadisticgameInCorrectInfo = screen.getByTestId('stadistic-game-incorrect-info') | ||
expect(stadisticgameInCorrectInfo).toBeInTheDocument(); | ||
|
||
const stadisticgameInCorrectBar = screen.getByTestId('stadistic-game-incorrect-bar') | ||
expect(stadisticgameInCorrectBar).toBeInTheDocument(); | ||
}) | ||
|
||
test('StadisticsGame correct aswers tests', () => { | ||
render(<StadisticsGame correctAnswers={10} incorrectAnswers={20}/>) | ||
|
||
const stadisticgameCorrectInfo = screen.getByTestId('stadistic-game-correct-info') | ||
expect(stadisticgameCorrectInfo).toHaveTextContent("Respuestas correctas:"); | ||
|
||
const stadisticgameCorrectBar = screen.getByTestId('stadistic-game-correct-bar') | ||
expect(stadisticgameCorrectBar).toHaveTextContent("10"); | ||
}) | ||
|
||
test('StadisticsGame incorrect aswers tests', () => { | ||
render(<StadisticsGame correctAnswers={10} incorrectAnswers={20}/>) | ||
|
||
const stadisticgameInCorrectInfo = screen.getByTestId('stadistic-game-incorrect-info') | ||
expect(stadisticgameInCorrectInfo).toHaveTextContent("Respuestas incorrectas:"); | ||
|
||
const stadisticgameInCorrectBar = screen.getByTestId('stadistic-game-incorrect-bar') | ||
expect(stadisticgameInCorrectBar).toHaveTextContent("20"); | ||
}) | ||
}) |
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
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,23 @@ | ||
import { screen, render, fireEvent } from "@testing-library/react" | ||
import Home from "./Home" | ||
import i18n from '../../translation/i18n'; | ||
|
||
describe('Home', () => { | ||
beforeAll(() => { | ||
i18n.changeLanguage('Spain'); | ||
}); | ||
|
||
test('Home renders correctly', () => { | ||
render(<Home/>) | ||
|
||
const element = screen.getByTestId('syg-home-container') | ||
expect(element).toBeInTheDocument(); | ||
}) | ||
|
||
test('Home components renders correctly', () => { | ||
render(<Home/>) | ||
|
||
const homeContent = screen.getByTestId('syg-home-content') | ||
expect(homeContent).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
Oops, something went wrong.