* 🚀 refactor: simplify deployment process in workflow file

* 🚀 chore: add IMAGE_NAME to GITHUB_ENV for deployment workflow

*  chore: simplify deployment logging in workflow file

* 🚀 fix: correct container name in deployment script logic

* 🚀 refactor: rename job and streamline deployment steps

* Update README.md

*  fix: prevent multiple form submissions in Contact component

*  feat: honeypot and timestamp checks to form submission

*  refactor: simplify contact form and improve UI elements
This commit is contained in:
denshooter
2025-02-22 22:29:23 +01:00
committed by GitHub
parent a31754d178
commit 9088a7cd32
3 changed files with 163 additions and 50 deletions

View File

@@ -1,4 +1,4 @@
import { render, screen, fireEvent } from '@testing-library/react';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import Contact from '@/app/components/Contact';
import '@testing-library/jest-dom';
@@ -10,20 +10,34 @@ global.fetch = jest.fn(() =>
) as jest.Mock;
describe('Contact', () => {
beforeAll(() => {
jest.useFakeTimers('modern');
});
afterAll(() => {
jest.useRealTimers();
});
it('renders the contact form', () => {
render(<Contact />);
expect(screen.getByPlaceholderText('Name')).toBeInTheDocument();
expect(screen.getByPlaceholderText('Email')).toBeInTheDocument();
expect(screen.getByPlaceholderText('Message')).toBeInTheDocument();
expect(screen.getByPlaceholderText('Your Name')).toBeInTheDocument();
expect(screen.getByPlaceholderText('you@example.com')).toBeInTheDocument();
expect(screen.getByPlaceholderText('Your Message...')).toBeInTheDocument();
expect(screen.getByLabelText('I accept the privacy policy.')).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();
// Fast forward time to ensure the timestamp check passes
jest.advanceTimersByTime(3000);
fireEvent.change(screen.getByPlaceholderText('Your Name'), { target: { value: 'John Doe' } });
fireEvent.change(screen.getByPlaceholderText('you@example.com'), { target: { value: 'john@example.com' } });
fireEvent.change(screen.getByPlaceholderText('Your Message...'), { target: { value: 'Hello!' } });
fireEvent.click(screen.getByLabelText('I accept the privacy policy.'));
fireEvent.click(screen.getByText('Send Message'));
await waitFor(() => expect(screen.getByText('Email sent')).toBeInTheDocument());
});
});