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
4 changed files
with
166 additions
and
8 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
components/groups/modals/__tests__/voteDetailsModal.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,115 @@ | ||
import { describe, test, expect, jest, mock, afterEach } from 'bun:test'; | ||
import React from 'react'; | ||
import { screen, fireEvent, cleanup, waitFor } from '@testing-library/react'; | ||
import VoteDetailsModal from '../voteDetailsModal'; | ||
import { | ||
ProposalSDKType, | ||
MemberSDKType, | ||
VoteSDKType, | ||
ProposalStatus, | ||
ProposalExecutorResult, | ||
} from '@liftedinit/manifestjs/dist/codegen/cosmos/group/v1/types'; | ||
import { QueryTallyResultResponseSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/group/v1/query'; | ||
import matchers from '@testing-library/jest-dom/matchers'; | ||
import { renderWithChainProvider } from '@/tests/render'; | ||
import { | ||
manifestAddr1, | ||
mockGroupFormData, | ||
mockMembers, | ||
mockProposals, | ||
mockTally, | ||
mockVotes, | ||
} from '@/tests/mock'; | ||
|
||
expect.extend(matchers); | ||
|
||
mock.module('react-apexcharts', () => ({ | ||
default: jest.fn(), | ||
})); | ||
|
||
mock.module('@cosmos-kit/react', () => ({ | ||
useChain: jest.fn().mockReturnValue({ | ||
address: mockProposals['test_policy_address'][0].proposers[0], | ||
chain: { fees: null }, | ||
}), | ||
})); | ||
|
||
const mockProposal = mockProposals['test_policy_address'][0]; | ||
|
||
describe('VoteDetailsModal', () => { | ||
const defaultProps = { | ||
tallies: mockTally, | ||
votes: mockVotes, | ||
members: mockMembers, | ||
proposal: mockProposal, | ||
onClose: jest.fn(), | ||
modalId: 'voteDetailsModal', | ||
refetchVotes: jest.fn(), | ||
refetchTally: jest.fn(), | ||
refetchProposals: jest.fn(), | ||
}; | ||
|
||
afterEach(() => { | ||
mock.restore(); | ||
cleanup(); | ||
}); | ||
|
||
test('renders the component with provided props', () => { | ||
renderWithChainProvider(<VoteDetailsModal {...defaultProps} />); | ||
expect(screen.getByText(`#${mockProposal.id.toString()}`)).toBeInTheDocument(); | ||
expect(screen.getByText(mockProposal.title)).toBeInTheDocument(); | ||
expect(screen.getByText('SUMMARY')).toBeInTheDocument(); | ||
expect(screen.getByText(mockProposal.summary)).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders the tally chart', () => { | ||
renderWithChainProvider(<VoteDetailsModal {...defaultProps} />); | ||
expect(screen.getByLabelText('chart-tally')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders voting countdown timer', () => { | ||
renderWithChainProvider(<VoteDetailsModal {...defaultProps} />); | ||
expect(screen.getByLabelText('voting-countdown-1')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('voting-countdown-2')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders messages section with correct data', () => { | ||
renderWithChainProvider(<VoteDetailsModal {...defaultProps} />); | ||
expect(screen.getByText('MESSAGES')).toBeInTheDocument(); | ||
expect(screen.getByText('Send')).toBeInTheDocument(); | ||
expect(screen.getByText('from_address:')).toBeInTheDocument(); | ||
expect(screen.getByText('to_address:')).toBeInTheDocument(); | ||
}); | ||
|
||
test('conditionally renders execute button when proposal is accepted', () => { | ||
const props = { | ||
...defaultProps, | ||
proposal: { | ||
...mockProposal, | ||
status: 'PROPOSAL_STATUS_ACCEPTED', | ||
executor_result: 'PROPOSAL_EXECUTOR_RESULT_NOT_RUN', | ||
}, | ||
}; | ||
renderWithChainProvider(<VoteDetailsModal {...props} />); | ||
expect(screen.getByText('Execute')).toBeInTheDocument(); | ||
}); | ||
|
||
test('conditionally renders vote button when proposal is open and user has not voted', () => { | ||
renderWithChainProvider(<VoteDetailsModal {...defaultProps} />); | ||
expect(screen.getByText('Vote')).toBeInTheDocument(); | ||
}); | ||
|
||
test('does not render vote button when user has already voted', () => { | ||
const props = { ...defaultProps, votes: [{ ...mockVotes[0], voter: 'proposer1' }] }; | ||
renderWithChainProvider(<VoteDetailsModal {...props} />); | ||
const btn = screen.getByLabelText('action-btn'); | ||
expect(btn.textContent).not.toBe('Vote'); | ||
}); | ||
|
||
test('handles vote button click and opens voting modal', async () => { | ||
renderWithChainProvider(<VoteDetailsModal {...defaultProps} />); | ||
const voteButton = screen.getByText('Vote'); | ||
fireEvent.click(voteButton); | ||
await waitFor(() => expect(screen.getByLabelText('vote-modal')).toBeInTheDocument()); | ||
}); | ||
}); |
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