* ✨ chore: update CI workflow to include testing and multi-arch build (#29) * ✨ chore: remove unused dependencies from package-lock.json and updated to a better local dev environment (#30) * ✨ test: add unit tests * ✨ test: add unit tests for whole project * ✨ feat: add whatwg-fetch for improved fetch support * ✨ chore: update Node.js version to 22 in workflow * ✨ refactor: update types and improve email handling tests * ✨ refactor: remove unused imports * ✨ fix: normalize image name to lowercase in workflows * ✨ fix: ensure Docker image names are consistently lowercase * ✨ chore: update * ✨ chore: update base URL to use secret variable * ✨ chore: update to login to ghcr * ✨ fix: add missing 'fi' to close if statement in workflow
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { render, screen, fireEvent } from '@testing-library/react';
|
|
import Contact from '@/app/components/Contact';
|
|
import '@testing-library/jest-dom';
|
|
|
|
// Mock the fetch function
|
|
global.fetch = jest.fn(() =>
|
|
Promise.resolve({
|
|
json: () => Promise.resolve({ message: 'Email sent' }),
|
|
})
|
|
) as jest.Mock;
|
|
|
|
describe('Contact', () => {
|
|
it('renders the contact form', () => {
|
|
render(<Contact />);
|
|
expect(screen.getByPlaceholderText('Name')).toBeInTheDocument();
|
|
expect(screen.getByPlaceholderText('Email')).toBeInTheDocument();
|
|
expect(screen.getByPlaceholderText('Message')).toBeInTheDocument();
|
|
});
|
|
|
|
it('submits the form', async () => {
|
|
render(<Contact />);
|
|
fireEvent.change(screen.getByPlaceholderText('Name'), { target: { value: 'John Doe' } });
|
|
fireEvent.change(screen.getByPlaceholderText('Email'), { target: { value: 'john@example.com' } });
|
|
fireEvent.change(screen.getByPlaceholderText('Message'), { target: { value: 'Hello!' } });
|
|
fireEvent.click(screen.getByText('Send'));
|
|
|
|
expect(await screen.findByText('Email sent')).toBeInTheDocument();
|
|
});
|
|
}); |