Skip to content

Commit

Permalink
fix: mint form test
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency committed Nov 7, 2024
1 parent fa0ebeb commit a103b33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions components/factory/forms/MintForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export default function MintForm({
{!denom.base.includes('umfx') && (
<button
type="submit"
aria-label={`mint-btn-${denom.display}`}
className="btn btn-gradient btn-md flex-grow text-white"
disabled={isSigning || !isValid || !dirty}
>
Expand Down
30 changes: 16 additions & 14 deletions components/factory/forms/__tests__/MintForm.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, afterEach, expect, jest } from 'bun:test';
import { describe, test, afterEach, expect, jest, mock } from 'bun:test';
import React from 'react';
import { screen, fireEvent, cleanup, waitFor } from '@testing-library/react';
import MintForm from '@/components/factory/forms/MintForm';
Expand All @@ -8,6 +8,15 @@ import { mockDenomMeta1, mockMfxDenom } from '@/tests/mock';

expect.extend(matchers);

// Mock next/router
const m = jest.fn();
mock.module('next/router', () => ({
useRouter: m.mockReturnValue({
query: {},
push: jest.fn(),
}),
}));

const mockProps = {
isAdmin: true,
admin: 'cosmos1adminaddress',
Expand All @@ -34,7 +43,7 @@ describe('MintForm Component', () => {

test('updates amount input correctly', async () => {
renderWithProps();
const amountInput = screen.getByLabelText('mint-amount-input');
const amountInput = screen.getByLabelText('AMOUNT');
fireEvent.change(amountInput, { target: { value: '100' } });
await waitFor(() => {
expect(amountInput).toHaveValue(100);
Expand All @@ -52,10 +61,10 @@ describe('MintForm Component', () => {

test('mint button is disabled when inputs are invalid', async () => {
renderWithProps();
const mintButton = screen.getByText('Mint');
const mintButton = screen.getByLabelText(`mint-btn-${mockDenomMeta1.display}`);
expect(mintButton).toBeDisabled();

const amountInput = screen.getByLabelText('mint-amount-input');
const amountInput = screen.getByLabelText('AMOUNT');
fireEvent.change(amountInput, { target: { value: '-100' } });

await waitFor(() => {
Expand All @@ -65,9 +74,9 @@ describe('MintForm Component', () => {

test('mint button is enabled when inputs are valid', async () => {
renderWithProps();
const amountInput = screen.getByLabelText('mint-amount-input');
const recipientInput = screen.getByLabelText('mint-recipient-input');
const mintButton = screen.getByText('Mint');
const amountInput = screen.getByLabelText('AMOUNT');
const recipientInput = screen.getByLabelText('RECIPIENT');
const mintButton = screen.getByLabelText(`mint-btn-${mockDenomMeta1.display}`);

fireEvent.change(amountInput, { target: { value: '1' } });
fireEvent.change(recipientInput, {
Expand All @@ -83,11 +92,4 @@ describe('MintForm Component', () => {
renderWithProps({ denom: mockMfxDenom });
expect(screen.getByLabelText('multi-mint-button')).toBeInTheDocument();
});

test('renders not affiliated message when not admin and token is mfx', () => {
renderWithProps({ isAdmin: false, denom: mockMfxDenom });
expect(
screen.getByText('You are not affiliated with any PoA Admin entity.')
).toBeInTheDocument();
});
});

0 comments on commit a103b33

Please sign in to comment.