Skip to content

Commit

Permalink
Modified test by Jaime
Browse files Browse the repository at this point in the history
  • Loading branch information
carolbgmm committed Apr 29, 2024
1 parent d2aa839 commit 7897519
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions webapp/src/components/group/GroupCreationModal.test.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,32 @@
import { render, fireEvent, waitFor } from '@testing-library/react';
import axios from 'axios'; // Mockear axios
import { render, fireEvent } from '@testing-library/react';
import { CreationModal } from './GroupCreationModal';

jest.mock('axios');

describe('CreationModal component', () => {
test('renders the modal properly', async () => {
const { getByText, getByLabelText } = render(<CreationModal nowHasGroup={() => {}} setError={() => {}} toggleCreateModal={() => {}} />);
const { getByTestId } = render(<CreationModal nowHasGroup={() => {}} setError={() => {}} toggleCreateModal={() => {}} />);

// Verifica que el título del modal esté presente
expect(getByText('Create group')).toBeInTheDocument();
expect(getByTestId('modal-title')).toBeInTheDocument();

// Verifica que los elementos de entrada estén presentes
expect(getByLabelText('Group name')).toBeInTheDocument();
expect(getByText('Yes')).toBeInTheDocument();
expect(getByText('No')).toBeInTheDocument();
expect(getByLabelText('Description')).toBeInTheDocument();
expect(getByTestId('group-name-input')).toBeInTheDocument();
expect(getByTestId('yes-button')).toBeInTheDocument();
expect(getByTestId('no-button')).toBeInTheDocument();
expect(getByTestId('description-input')).toBeInTheDocument();
});

test('clicking on the create button calls the createGroup function', async () => {
const mockNowHasGroup = jest.fn();
const mockSetError = jest.fn();
const mockToggleCreateModal = jest.fn();

const { getByText } = render(<CreationModal nowHasGroup={mockNowHasGroup} setError={mockSetError} toggleCreateModal={mockToggleCreateModal} />);
const { getByTestId } = render(<CreationModal nowHasGroup={mockNowHasGroup} setError={mockSetError} toggleCreateModal={mockToggleCreateModal} />);

// Simula hacer clic en el botón de creación
fireEvent.click(getByText('Create group'));

fireEvent.click(getByTestId('create-button'));

});

test('changing the group name updates the state', async () => {
const { getByLabelText } = render(<CreationModal nowHasGroup={() => {}} setError={() => {}} toggleCreateModal={() => {}} />);

// Simula cambiar el valor del nombre del grupo
fireEvent.change(getByLabelText('Group name'), { target: { value: 'New Group' } });

// Verifica que el valor del nombre del grupo haya sido actualizado
expect(getByLabelText('Group name')).toHaveValue('New Group');
});

// Agrega más tests según sea necesario para cubrir otras funcionalidades y casos de uso.
});

0 comments on commit 7897519

Please sign in to comment.