Skip to content

Commit

Permalink
add unit tests for bounty index.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
MirzaHanan committed Feb 20, 2024
1 parent 2255ebf commit a52d9f6
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/components/form/bounty/bountyCreation.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { act, fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { wantedCodingTaskSchema } from '../schema.ts';
import Form from './index.tsx';

describe('Bounty index', () => {
beforeEach(async () => {
act(async () => {
render(<Form onSubmit={jest.fn()} schema={wantedCodingTaskSchema} />);
const PostBountyButton = await screen.findByRole('button', { name: /Post a Bounty/i });
expect(PostBountyButton).toBeInTheDocument();
fireEvent.click(PostBountyButton);
const StartButton = await screen.findByRole('button', { name: /Start/i });
expect(StartButton).toBeInTheDocument();
const bountyTitleInput = await screen.findByRole('input', { name: /Bounty Title /i });
expect(bountyTitleInput).toBeInTheDocument();
fireEvent.change(bountyTitleInput, { target: { value: 'new text' } });
const dropdown = screen.getByText(/Category /i);
fireEvent.click(dropdown);
const desiredOption = screen.getByText(/Web Development/i);
fireEvent.click(desiredOption);
const NextButton = await screen.findByRole('button', { name: /Next/i });
expect(NextButton).toBeInTheDocument();
fireEvent.click(NextButton);
const DescriptionInput = await screen.findByRole('input', { name: /Description /i });
expect(DescriptionInput).toBeInTheDocument();
fireEvent.change(DescriptionInput, { target: { value: 'new text' } });
const NextButton2 = await screen.findByRole('button', { name: /Next/i });
expect(NextButton2).toBeInTheDocument();
fireEvent.click(NextButton2);
const SatInput = await screen.findByRole('input', { name: /Price(Sats)/i });
expect(SatInput).toBeInTheDocument();
});
});

test('Placeholder text for 0 Sats is visible for amount input box', async () => {
act(async () => {
const SatInput = await screen.findByRole('input', { name: /Price(Sats)/i });
expect(SatInput).toBeInTheDocument();
const amountInput = await screen.findByText('0');
expect(amountInput).toBeInTheDocument();
});
});

test('Next button is disabled if amount is set to zero', async () => {
act(async () => {
const amountInput = await screen.findByText('0');
fireEvent.change(amountInput, { target: { value: '0' } });
const nextButton = screen.findByRole('button', { name: /Next/i });
expect(nextButton).toBeDisabled();
});
});

test('Next button is enabled for amount > 0 and Disabled again when reverting to 0', async () => {
act(async () => {
const amountInput = await screen.findByText('0');
fireEvent.change(amountInput, { target: { value: '50' } });
const nextButton = screen.findByRole('button', { name: /Next/i });
expect(nextButton).toBeEnabled();
fireEvent.change(amountInput, { target: { value: '0' } });
expect(nextButton).toBeDisabled();
});
});

test('Proceeding to next page of form only if value for amount is greater than 0', async () => {
act(async () => {
const amountInput = await screen.findByText('0');
fireEvent.change(amountInput, { target: { value: '13' } });
const nextButton = screen.findByRole('button', { name: /Next/i });
fireEvent.click(await nextButton);
const nextPage = await screen.findByText('Assign Developer');
expect(nextPage).toBeInTheDocument();
const DecideLaterButton = await screen.findByRole('button', { name: /Decide Later/i });
expect(DecideLaterButton).toBeInTheDocument();
});
});
});

0 comments on commit a52d9f6

Please sign in to comment.