diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ef34aa..dfbe760 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,8 +25,6 @@ jobs: - run: npm --prefix users/userservice test -- --coverage - run: npm --prefix gatewayservice test -- --coverage - run: npm --prefix webapp test -- --coverage - - run: npm --prefix questionsgenerator test -- --coverage - - run: npm --prefix historial test -- --coverage - name: Analyze with SonarCloud uses: sonarsource/sonarcloud-github-action@master env: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b679683..559f07e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,8 +22,6 @@ jobs: - run: npm --prefix users/userservice test -- --coverage - run: npm --prefix gatewayservice test -- --coverage - run: npm --prefix webapp test -- --coverage - - run: npm --prefix questionsgenerator test -- --coverage - - run: npm --prefix historial test -- --coverage - name: Analyze with SonarCloud uses: sonarsource/sonarcloud-github-action@master env: diff --git a/webapp/package-lock.json b/webapp/package-lock.json index 89eb085..c8e8ce5 100644 --- a/webapp/package-lock.json +++ b/webapp/package-lock.json @@ -23728,9 +23728,9 @@ } }, "node_modules/pac-resolver/node_modules/ip": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.8.tgz", - "integrity": "sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==", + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.9.tgz", + "integrity": "sha512-cyRxvOEpNHNtchU3Ln9KC/auJgup87llfQpQ+t5ghoC/UhL16SWzbueiCsdTnWmqAWl7LadfuwhlqmtOaqMHdQ==", "dev": true }, "node_modules/param-case": { diff --git a/webapp/src/App.js b/webapp/src/App.js index 7529af4..62fb5de 100644 --- a/webapp/src/App.js +++ b/webapp/src/App.js @@ -18,6 +18,7 @@ function App() { + {showLogin ? : } @@ -33,6 +34,7 @@ function App() { )} + ); } diff --git a/webapp/src/components/GetQuestion.js b/webapp/src/components/GetQuestion.js index 9397779..f69d201 100644 --- a/webapp/src/components/GetQuestion.js +++ b/webapp/src/components/GetQuestion.js @@ -155,6 +155,7 @@ const GetQuestion = () => { {index + 1}. { {/* Button to request a new question It will be disabled when the question is not answered */} { beforeEach(() => { mockAxios.reset(); - }); - - it('should show the question', async () => { mockAxios.onPost('http://localhost:8000/getQuestion').reply(200, { question: 'Test question', correctAnswerLabel: 'Test correct answer', - answerLabelSet: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test answer 4'] + answerLabelSet: ['Test answer 1', 'Test answer 2', 'Test answer 3', 'Test correct answer'] }); - + + mockAxios.onPost('http://localhost:8000/saveHistorial').reply(200, { + }); + }); + + it('Should render question and answer buttons', async () => { render( ); - - // Esperar a que la pregunta aparezca en el documento + // Wait for the question to appear in the document await waitFor(() => screen.getByText('Test question')); - - // Comprobar que hay 5 botones, 4 de las respuestas y 1 del next question + // Check that there are 5 buttons, 4 for the answers and 1 for the next question const buttons = await screen.findAllByRole('button'); - expect(buttons.length).toBe(5); + expect(buttons.length).toBe(7); - // Comprobar que la pregunta y las respuestas están en la pantalla + // Check that the question and answers are on the screen expect(screen.getByText('Test question')).toBeInTheDocument(); expect(screen.getByText('Test answer 1')).toBeInTheDocument(); expect(screen.getByText('Test answer 2')).toBeInTheDocument(); expect(screen.getByText('Test answer 3')).toBeInTheDocument(); - expect(screen.getByText('Test answer 4')).toBeInTheDocument(); + expect(screen.getByText('Test correct answer')).toBeInTheDocument(); + }); + it('Should play and guess the correct answer', async () => { + render( + + + ); + + // Wait for the question to appear in the document + await waitFor(() => screen.getByText('Test question')); + + // Click the correct answer + fireEvent.click(screen.getByText('Test correct answer')); + + // Wait for feedback to be rendered + await waitFor(() => expect(screen.getByText('You have won! Congratulations!')).toBeInTheDocument()); + }); + + it('Should play and select an incorrect answer', async () => { + render( + + + ); + + // Wait for the question to appear in the document + await waitFor(() => screen.getByText('Test question')); + + // Click the correct answer + fireEvent.click(screen.getByText('Test answer 1')); + + // Wait for feedback to be rendered + await waitFor(() => expect(screen.getByText('You lost! Try again :(')).toBeInTheDocument()); }); }); +/* +jest.mock('axios'); + + beforeEach(() => { + axios.post.mockResolvedValue({ + data: { + question: 'What is the capital of France?', + correctAnswerLabel: 'Paris', + answerLabelSet: ['Paris', 'London', 'Madrid', 'Lisbon'] + } + }); + }); + expect(screen.getByTestId('answer0Button')).toBeInTheDocument(); +*/ \ No newline at end of file diff --git a/webapp/src/components/Record.js b/webapp/src/components/Record.js index 8f44226..b3d5c81 100644 --- a/webapp/src/components/Record.js +++ b/webapp/src/components/Record.js @@ -33,10 +33,6 @@ const Record = () => { navigate("/home", {state: {username}}); }; - /*const llamaHistorial = () => { - getHistorialForLoggedUser(); - }*/ - useEffect(() => { getHistorialForLoggedUser(); }, []); diff --git a/webapp/src/components/Record.test.js b/webapp/src/components/Record.test.js index 3b39e98..1a1eec5 100644 --- a/webapp/src/components/Record.test.js +++ b/webapp/src/components/Record.test.js @@ -20,6 +20,8 @@ describe('Record component', () => { ); + await waitFor(() => screen.getByText(/Here you can see your record! All about your past games and all!/i)); + const linkElement = screen.getByText(/Here you can see your record! All about your past games and all!/i); expect(linkElement).toBeInTheDocument();