From e7698debeffdf47dfeeb8c7edbd5f48b1f5cf676 Mon Sep 17 00:00:00 2001 From: JaimeLoredo Date: Mon, 29 Apr 2024 17:12:52 +0200 Subject: [PATCH 1/3] Improvement over NoGroup to test the "join group" functionality futher --- webapp/src/components/group/NoGroup.test.js | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/webapp/src/components/group/NoGroup.test.js b/webapp/src/components/group/NoGroup.test.js index 01fd2901..aff8dac1 100644 --- a/webapp/src/components/group/NoGroup.test.js +++ b/webapp/src/components/group/NoGroup.test.js @@ -1,5 +1,5 @@ import React from 'react'; -import { render, screen, fireEvent, waitFor } from '@testing-library/react'; +import { render, screen, fireEvent, waitFor,act } from '@testing-library/react'; import axios from 'axios'; // Mockear axios import NoGroup from './NoGroup'; @@ -65,4 +65,29 @@ describe('NoGroup component', () => { expect(screen.getByTestId('create-group-modal')).toBeInTheDocument(); }); }); + + test('joining a group calls the joinGroup API', async () => { + render(); + + // Simula hacer clic en el botón "Join a group" para abrir el modal + fireEvent.click(screen.getByTestId('join-group-button')); + + // Verifica que el modal de join group se muestre en el DOM + await waitFor(() => { + expect(screen.getByTestId('join-group-modal')).toBeInTheDocument(); + }); + + // Simula un nombre de grupo ficticio + const groupName = 'TestGroup'; + + // Simula la llamada a joinGroup + await act(async () => { + await fireEvent.click(screen.getByTestId(`join-group-button`)); + }); + // Simula una respuesta exitosa de la API + axios.post.mockResolvedValueOnce({}); + + + }); + }); From c4eb539943b3267412ae425d782b2a4d82b64118 Mon Sep 17 00:00:00 2001 From: JaimeLoredo Date: Mon, 29 Apr 2024 17:18:36 +0200 Subject: [PATCH 2/3] Remove testing variable that was left forgotten to pass quality gate --- webapp/src/components/group/NoGroup.test.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/webapp/src/components/group/NoGroup.test.js b/webapp/src/components/group/NoGroup.test.js index aff8dac1..bcd8a8d9 100644 --- a/webapp/src/components/group/NoGroup.test.js +++ b/webapp/src/components/group/NoGroup.test.js @@ -77,9 +77,6 @@ describe('NoGroup component', () => { expect(screen.getByTestId('join-group-modal')).toBeInTheDocument(); }); - // Simula un nombre de grupo ficticio - const groupName = 'TestGroup'; - // Simula la llamada a joinGroup await act(async () => { await fireEvent.click(screen.getByTestId(`join-group-button`)); From e6df3f196556126932580ff20a6d4b971eebf3c2 Mon Sep 17 00:00:00 2001 From: JaimeLoredo Date: Mon, 29 Apr 2024 17:24:20 +0200 Subject: [PATCH 3/3] Refactor some lines into single function --- webapp/src/components/group/NoGroup.test.js | 27 +++++---------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/webapp/src/components/group/NoGroup.test.js b/webapp/src/components/group/NoGroup.test.js index bcd8a8d9..60a36ea9 100644 --- a/webapp/src/components/group/NoGroup.test.js +++ b/webapp/src/components/group/NoGroup.test.js @@ -52,6 +52,12 @@ describe('NoGroup component', () => { await waitFor(() => { expect(screen.getByTestId('join-group-modal')).toBeInTheDocument(); }); + // Simula la llamada a joinGroup + await act(async () => { + await fireEvent.click(screen.getByTestId(`join-group-button`)); + }); + // Simula una respuesta exitosa de la API + axios.post.mockResolvedValueOnce({}); }); test('clicking on "Create a group" button opens the create modal', async () => { @@ -66,25 +72,4 @@ describe('NoGroup component', () => { }); }); - test('joining a group calls the joinGroup API', async () => { - render(); - - // Simula hacer clic en el botón "Join a group" para abrir el modal - fireEvent.click(screen.getByTestId('join-group-button')); - - // Verifica que el modal de join group se muestre en el DOM - await waitFor(() => { - expect(screen.getByTestId('join-group-modal')).toBeInTheDocument(); - }); - - // Simula la llamada a joinGroup - await act(async () => { - await fireEvent.click(screen.getByTestId(`join-group-button`)); - }); - // Simula una respuesta exitosa de la API - axios.post.mockResolvedValueOnce({}); - - - }); - });