forked from liftedinit/manifest-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
391 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
components/groups/forms/groups/__tests__/ConfirmationForm.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { describe, test, afterEach, expect, jest, mock } from 'bun:test'; | ||
import React from 'react'; | ||
import { screen, fireEvent, cleanup } from '@testing-library/react'; | ||
import ConfirmationModal from '@/components/groups/forms/groups/ConfirmationForm'; | ||
import matchers from '@testing-library/jest-dom/matchers'; | ||
import { FormData } from '@/helpers/formReducer'; | ||
import { renderWithChainProvider } from '@/tests/render'; | ||
|
||
expect.extend(matchers); | ||
|
||
const mockFormData: FormData = { | ||
title: 'Test Group', | ||
authors: 'manifest1author', | ||
summary: 'This is a test group', | ||
description: 'Detailed description of the test group', | ||
forumLink: 'http://forumlink.com', | ||
votingThreshold: '50%', | ||
votingPeriod: { seconds: BigInt(3600), nanos: 0 }, | ||
members: [ | ||
{ address: 'manifest1member1', name: 'Member 1', weight: '1' }, | ||
{ address: 'manifest1member2', name: 'Member 2', weight: '2' }, | ||
], | ||
}; | ||
|
||
const mockProps = { | ||
nextStep: jest.fn(), | ||
prevStep: jest.fn(), | ||
formData: mockFormData, | ||
}; | ||
|
||
describe('ConfirmationModal Component', () => { | ||
afterEach(cleanup); | ||
|
||
test('renders component with correct details', () => { | ||
renderWithChainProvider(<ConfirmationModal {...mockProps} />); | ||
expect(screen.getByText('Confirmation')).toBeInTheDocument(); | ||
expect(screen.getByText('GROUP DETAILS')).toBeInTheDocument(); | ||
expect(screen.getByText('GROUP TITLE')).toBeInTheDocument(); | ||
expect(screen.getByText('AUTHORS')).toBeInTheDocument(); | ||
expect(screen.getByText('SUMMARY')).toBeInTheDocument(); | ||
expect(screen.getByText('DESCRIPTION')).toBeInTheDocument(); | ||
expect(screen.getByText('THRESHOLD')).toBeInTheDocument(); | ||
expect(screen.getByText('VOTING PERIOD')).toBeInTheDocument(); | ||
expect(screen.getByText('MEMBERS')).toBeInTheDocument(); | ||
}); | ||
|
||
test('calls prevStep when "Prev: Member Info" button is clicked', () => { | ||
renderWithChainProvider(<ConfirmationModal {...mockProps} />); | ||
const prevButton = screen.getByText('Prev: Member Info'); | ||
fireEvent.click(prevButton); | ||
expect(mockProps.prevStep).toHaveBeenCalled(); | ||
}); | ||
|
||
|
||
test('disables "Sign Transaction" button when isSigning is true', () => { | ||
renderWithChainProvider(<ConfirmationModal {...mockProps} />); | ||
const signButton = screen.getByText('Sign Transaction'); | ||
fireEvent.click(signButton); | ||
expect(signButton).toBeDisabled(); | ||
}); | ||
|
||
test('disables "Sign Transaction" button when address is not provided', () => { | ||
mock.module('@/hooks/useChain', () => ({ | ||
useChain: () => ({ address: '' }), | ||
})); | ||
renderWithChainProvider(<ConfirmationModal {...mockProps} />); | ||
const signButton = screen.getByText('Sign Transaction'); | ||
fireEvent.click(signButton); | ||
expect(signButton).toBeDisabled(); | ||
}); | ||
}); |
74 changes: 74 additions & 0 deletions
74
components/groups/forms/groups/__tests__/GroupDetailsForm.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import {afterEach, describe, expect, jest, test} from 'bun:test'; | ||
import React from 'react'; | ||
import {cleanup, fireEvent, screen} from '@testing-library/react'; | ||
import GroupDetails from '@/components/groups/forms/groups/GroupDetailsForm'; | ||
import matchers from '@testing-library/jest-dom/matchers'; | ||
import {renderWithChainProvider} from '@/tests/render'; | ||
import {mockGroupFormData} from "@/tests/mock"; | ||
|
||
expect.extend(matchers); | ||
|
||
const mockProps = { | ||
nextStep: jest.fn(), | ||
formData: mockGroupFormData, | ||
dispatch: jest.fn(), | ||
address: 'cosmos1address', | ||
}; | ||
|
||
describe('GroupDetails Component', () => { | ||
afterEach(cleanup); | ||
|
||
test('renders component with correct details', () => { | ||
renderWithChainProvider(<GroupDetails {...mockProps} />); | ||
expect(screen.getByText('Group details')).toBeInTheDocument(); | ||
expect(screen.getByText('Group Title')).toBeInTheDocument(); | ||
expect(screen.getByText('Authors')).toBeInTheDocument(); | ||
expect(screen.getByText('Summary')).toBeInTheDocument(); | ||
expect(screen.getByText('Description')).toBeInTheDocument(); | ||
expect(screen.getByText('Forum Link')).toBeInTheDocument(); | ||
}); | ||
|
||
// TODO: Make this test pass. Why is the input not being updated? | ||
// test('updates form fields correctly', async () => { | ||
// renderWithChainProvider(<GroupDetails {...mockProps} />); | ||
// const titleInput = screen.getByPlaceholderText('Title'); | ||
// fireEvent.change(titleInput, { target: { value: 'New Group Title' } }); | ||
// await waitFor(() => expect(titleInput).toHaveValue('New Group Title')); | ||
// | ||
// const authorsInput = screen.getByPlaceholderText('List of authors or address'); | ||
// fireEvent.change(authorsInput, { target: { value: 'New Author' } }); | ||
// expect(authorsInput).toHaveValue('New Author'); | ||
// | ||
// const summaryInput = screen.getByPlaceholderText('Short Bio'); | ||
// fireEvent.change(summaryInput, { target: { value: 'New Summary' } }); | ||
// expect(summaryInput).toHaveValue('New Summary'); | ||
// | ||
// const descriptionInput = screen.getByPlaceholderText('Long Bio'); | ||
// fireEvent.change(descriptionInput, { target: { value: 'New Description' } }); | ||
// expect(descriptionInput).toHaveValue('New Description'); | ||
// | ||
// const forumLinkInput = screen.getByPlaceholderText('Link to forum'); | ||
// fireEvent.change(forumLinkInput, { target: { value: 'http://newforumlink.com' } }); | ||
// expect(forumLinkInput).toHaveValue('http://newforumlink.com'); | ||
// }); | ||
// | ||
test('next button is disabled when form is invalid', () => { | ||
const invalidFormData = { ...mockGroupFormData, title: '' }; | ||
renderWithChainProvider(<GroupDetails {...mockProps} formData={invalidFormData} />); | ||
const nextButton = screen.getByText('Next: Group Policy'); | ||
expect(nextButton).toBeDisabled(); | ||
}); | ||
|
||
test('next button is enabled when form is valid', () => { | ||
renderWithChainProvider(<GroupDetails {...mockProps} />); | ||
const nextButton = screen.getByText('Next: Group Policy'); | ||
expect(nextButton).toBeEnabled(); | ||
}); | ||
|
||
test('calls nextStep when next button is clicked', () => { | ||
renderWithChainProvider(<GroupDetails {...mockProps} />); | ||
const nextButton = screen.getByText('Next: Group Policy'); | ||
fireEvent.click(nextButton); | ||
expect(mockProps.nextStep).toHaveBeenCalled(); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
components/groups/forms/groups/__tests__/GroupPolicyForm.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { describe, test, afterEach, expect, jest } from 'bun:test'; | ||
import React from 'react'; | ||
import { screen, fireEvent, cleanup } from '@testing-library/react'; | ||
import GroupPolicyForm from '@/components/groups/forms/groups/GroupPolicyForm'; | ||
import matchers from '@testing-library/jest-dom/matchers'; | ||
import { renderWithChainProvider } from '@/tests/render'; | ||
import {mockGroupFormData} from "@/tests/mock"; | ||
|
||
expect.extend(matchers); | ||
|
||
const mockProps = { | ||
nextStep: jest.fn(), | ||
prevStep: jest.fn(), | ||
formData: mockGroupFormData, | ||
dispatch: jest.fn(), | ||
}; | ||
|
||
describe('GroupPolicyForm Component', () => { | ||
afterEach(cleanup); | ||
|
||
test('renders component with correct details', () => { | ||
renderWithChainProvider(<GroupPolicyForm {...mockProps} />); | ||
expect(screen.getByText('Group Policy')).toBeInTheDocument(); | ||
expect(screen.getByText('Voting Period')).toBeInTheDocument(); | ||
expect(screen.getByText('Voting Threshold')).toBeInTheDocument(); | ||
}); | ||
|
||
test('updates form fields correctly', () => { | ||
renderWithChainProvider(<GroupPolicyForm {...mockProps} />); | ||
const votingAmountInput = screen.getByPlaceholderText('Enter duration'); | ||
fireEvent.change(votingAmountInput, { target: { value: '2' } }); | ||
expect(votingAmountInput).toHaveValue(2); | ||
|
||
// TODO: The input is not being updated, why? | ||
// const votingThresholdInput = screen.getByPlaceholderText('e.g. (1)'); | ||
// fireEvent.change(votingThresholdInput, { target: { value: '3' } }); | ||
// expect(votingThresholdInput).toHaveValue('3'); | ||
}); | ||
|
||
test('next button is disabled when form is invalid', () => { | ||
const invalidFormData = { ...mockGroupFormData, votingThreshold: '' }; | ||
renderWithChainProvider(<GroupPolicyForm {...mockProps} formData={invalidFormData} />); | ||
const nextButton = screen.getByText('Next: Member Info'); | ||
expect(nextButton).toBeDisabled(); | ||
}); | ||
|
||
test('next button is enabled when form is valid', () => { | ||
renderWithChainProvider(<GroupPolicyForm {...mockProps} />); | ||
const nextButton = screen.getByText('Next: Member Info'); | ||
expect(nextButton).toBeEnabled(); | ||
}); | ||
|
||
test('calls nextStep when next button is clicked', () => { | ||
renderWithChainProvider(<GroupPolicyForm {...mockProps} />); | ||
const nextButton = screen.getByText('Next: Member Info'); | ||
fireEvent.click(nextButton); | ||
expect(mockProps.nextStep).toHaveBeenCalled(); | ||
}); | ||
|
||
test('calls prevStep when prev button is clicked', () => { | ||
renderWithChainProvider(<GroupPolicyForm {...mockProps} />); | ||
const prevButton = screen.getByText('Prev: Group Details'); | ||
fireEvent.click(prevButton); | ||
expect(mockProps.prevStep).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.