From da8d612cd511949f610b0dcd7d029c70f0cf9002 Mon Sep 17 00:00:00 2001 From: "Felix C. Morency" <1102868+fmorency@users.noreply.github.com> Date: Wed, 8 Jan 2025 11:15:47 -0500 Subject: [PATCH] fix: tests --- .../components/__tests__/groupInfo.test.tsx | 2 +- .../__tests__/UpdateGroupModal.test.tsx | 31 +++++++++++-------- components/groups/modals/updateGroupModal.tsx | 12 ++++--- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/components/groups/components/__tests__/groupInfo.test.tsx b/components/groups/components/__tests__/groupInfo.test.tsx index 36d5869..bf3981f 100644 --- a/components/groups/components/__tests__/groupInfo.test.tsx +++ b/components/groups/components/__tests__/groupInfo.test.tsx @@ -89,6 +89,6 @@ describe('GroupInfo', () => { fireEvent.click(updateButton); const modal = document.getElementById(`update-group-modal`) as HTMLDialogElement; expect(modal).toBeInTheDocument(); - expect(screen.getByText('Update Group')).toBeInTheDocument(); + expect(screen.getByLabelText('update-group-btn')).toBeInTheDocument(); }); }); diff --git a/components/groups/modals/__tests__/UpdateGroupModal.test.tsx b/components/groups/modals/__tests__/UpdateGroupModal.test.tsx index fe72488..1039a62 100644 --- a/components/groups/modals/__tests__/UpdateGroupModal.test.tsx +++ b/components/groups/modals/__tests__/UpdateGroupModal.test.tsx @@ -1,8 +1,11 @@ import { describe, test, expect, beforeEach, jest } from 'bun:test'; import React from 'react'; -import { fireEvent, screen } from '@testing-library/react'; +import { fireEvent, screen, waitFor } from '@testing-library/react'; import { UpdateGroupModal } from '@/components'; import { renderWithChainProvider } from '@/tests/render'; +import matchers from '@testing-library/jest-dom/matchers'; + +expect.extend(matchers); // Mock group data const mockProps = { @@ -58,25 +61,27 @@ describe('UpdateGroupModal Component Input State Changes', () => { test('updates input fields correctly', async () => { // Test name input - const nameInput = screen.getByLabelText('Group Name') as HTMLInputElement; + const nameInput = screen.getByLabelText('Group Title') as HTMLInputElement; fireEvent.change(nameInput, { target: { value: 'New Group Name' } }); expect(nameInput.value).toBe('New Group Name'); + const addAuthorButton = screen.getByText('Add Author'); + fireEvent.click(addAuthorButton); + + await waitFor(() => { + expect(screen.getByLabelText('Author name or address')).toBeInTheDocument(); + }); + // Test authors input - const authorsInput = screen.getByLabelText('Authors') as HTMLInputElement; + const authorsInput = screen.getByLabelText('Author name or address') as HTMLInputElement; fireEvent.change(authorsInput, { target: { value: 'New Author' } }); expect(authorsInput.value).toBe('New Author'); - // Test summary input - const summaryInput = screen.getByLabelText('Summary') as HTMLInputElement; - fireEvent.change(summaryInput, { target: { value: 'New Summary' } }); - expect(summaryInput.value).toBe('New Summary'); - - // Test threshold input - const thresholdInput = screen.getByLabelText('Threshold') as HTMLInputElement; - fireEvent.change(thresholdInput, { target: { value: '2' } }); - expect(thresholdInput.value).toBe('2'); - + // // Test threshold input + // const thresholdInput = screen.getByLabelText('Qualified Majority') as HTMLInputElement; + // fireEvent.change(thresholdInput, { target: { value: '2' } }); + // expect(thresholdInput.value).toBe('2'); + // // Test voting unit select const minutes = screen.getByLabelText('Minutes') as HTMLSelectElement; fireEvent.change(minutes, { target: { value: '30' } }); diff --git a/components/groups/modals/updateGroupModal.tsx b/components/groups/modals/updateGroupModal.tsx index daf7a01..fa08c99 100644 --- a/components/groups/modals/updateGroupModal.tsx +++ b/components/groups/modals/updateGroupModal.tsx @@ -60,7 +60,7 @@ export function UpdateGroupModal({ const [name, setName] = useState(maybeTitle); const [authors, setAuthors] = useState(maybeAuthors ? [maybeAuthors] : []); const [description, setDescription] = useState(maybeDetails); - const [threshold, setThreshold] = useState(maybeThreshold); + const [threshold, setThreshold] = useState(maybeThreshold !== '' ? maybeThreshold : '1'); const [votingPeriod, setVotingPeriod] = useState({ days: 0, hours: 0, @@ -432,6 +432,7 @@ export function UpdateGroupModal({ - + ); }