Skip to content

Commit

Permalink
update:Add->FormTest Components
Browse files Browse the repository at this point in the history
  • Loading branch information
dovanminhquan0505 committed May 19, 2024
1 parent b36d0e9 commit a10afa8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 35 deletions.
43 changes: 8 additions & 35 deletions __tests__/components/Form.test.jsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import Form from "../../components/Form"

jest.mock('../../components/Form', () => ({
__esModule: true,
default: jest.fn(),
}));

const mockPost = {
prompt: '',
tag: '',
};

const mockSubmitHandler = jest.fn();

test('renders the Form component with placeholders', () => {
Form.mockImplementationOnce(() => (
<Form type="Create" post={mockPost} setPost={() => {}} submitting={false} handleSubmit={mockSubmitHandler} />
));
render(<Form />); // You can render directly without props here

// Assertions using screen.getByText, screen.getByPlaceholderText, etc.
expect(screen.getByText(/Create Post/i)).toBeInTheDocument();
expect(screen.getByPlaceholderText(/Write Your Prompt Here.../i)).toBeInTheDocument();
expect(screen.getByText(/Field of Prompt/i)).toBeInTheDocument();
});

test('disables submit button when submitting is true', () => {
Form.mockImplementationOnce(() => (
<Form type="Create" post={mockPost} setPost={() => {}} submitting={true} handleSubmit={mockSubmitHandler} />
));
render(<Form />);

const submitButton = screen.getByRole('button', { name: /Create/i });
expect(submitButton).toBeDisabled();
});
import { Form } from '@/components';

describe("Form Components", () => {
it("should render Form Component", () => {
expect(Form).toBeDefined()
expect(Form).toMatchSnapshot()
})
})
3 changes: 3 additions & 0 deletions __tests__/components/__snapshots__/Form.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Form Components should render Form Component 1`] = `[Function]`;

0 comments on commit a10afa8

Please sign in to comment.