From f8e9e29c44dc05f9a5fdd35e340ada60505477b1 Mon Sep 17 00:00:00 2001 From: Liliana Date: Fri, 26 Apr 2024 10:30:41 +0200 Subject: [PATCH] test for game config --- .../src/components/game/GameConfiguration.js | 8 ++------ .../components/game/GameConfiguration.test.js | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/webapp/src/components/game/GameConfiguration.js b/webapp/src/components/game/GameConfiguration.js index 57ad263b..c60d9a9a 100644 --- a/webapp/src/components/game/GameConfiguration.js +++ b/webapp/src/components/game/GameConfiguration.js @@ -16,15 +16,12 @@ const previousBackgroundColor = '#1a1a1a' const GameConfiguration = () => { - let tematicas - let state = useLocation().state + let tematicas = []; + let state = useLocation().state; if( state !== null) tematicas = state.topics; - else - tematicas = [] console.log(tematicas) - // Almacen de temáticas const [tematicasSeleccionadas, setTematicasSeleccionadas] = useState([]); // Almacen para el número de preguntas @@ -34,7 +31,6 @@ const GameConfiguration = () => { const [numRes, setNumRes] = useState(2); - const handleTematicaChange = (event) => { const tematicaSeleccionada = event.target.value; diff --git a/webapp/src/components/game/GameConfiguration.test.js b/webapp/src/components/game/GameConfiguration.test.js index c82306aa..1e6dd5ae 100644 --- a/webapp/src/components/game/GameConfiguration.test.js +++ b/webapp/src/components/game/GameConfiguration.test.js @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react'; +import { render, screen, fireEvent } from '@testing-library/react'; import { ContextFun } from '../Context'; import axios from 'axios'; import MockAdapter from 'axios-mock-adapter'; @@ -49,5 +49,21 @@ describe("Game Configuration", () => { expect(numPreguntas).toHaveLength(1); }); + test("modify number of questions for game",async () => { + + const { getByLabelText } = + render( + + + + + + ); + + const input = getByLabelText('Número de respuestas:'); + fireEvent.change(input, { target: { value: '5' } }); + expect(input.value).toBe('5'); + }); + });