Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency committed Jan 8, 2025
1 parent e288200 commit da8d612
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion components/groups/components/__tests__/groupInfo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
31 changes: 18 additions & 13 deletions components/groups/modals/__tests__/UpdateGroupModal.test.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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' } });
Expand Down
12 changes: 7 additions & 5 deletions components/groups/modals/updateGroupModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -432,6 +432,7 @@ export function UpdateGroupModal({
</button>
<button
type="submit"
aria-label={'update-group-btn'}
className="btn btn-md w-[calc(50%-8px)] btn-gradient text-white"
disabled={isSigning || !isValid || !hasAnyChanges(values)}
>
Expand Down Expand Up @@ -479,7 +480,7 @@ function GroupPolicyFormFields({
}>();

return (
<Form className="flex flex-col gap-4">
<div className="flex flex-col gap-4">
<div>
<label className="block text-sm mb-1 font-medium dark:text-[#FFFFFF99]">
Voting Period
Expand Down Expand Up @@ -511,6 +512,7 @@ function GroupPolicyFormFields({
Qualified Majority
</label>
<NumberInput
aria-label={'Qualified Majority'}
name="votingThreshold"
placeholder="e.g., 1"
value={values.votingThreshold}
Expand All @@ -522,7 +524,7 @@ function GroupPolicyFormFields({
min={1}
/>
</div>
</Form>
</div>
);
}

Expand All @@ -548,7 +550,7 @@ function GroupDetailsFormFields({
}>();

return (
<Form className="flex flex-col gap-4">
<div className="flex flex-col gap-4">
<TextInput
label="Group Title"
name="name"
Expand Down Expand Up @@ -626,6 +628,6 @@ function GroupDetailsFormFields({
<PlusIcon className="mr-2" /> Add Author
</button>
</div>
</Form>
</div>
);
}

0 comments on commit da8d612

Please sign in to comment.