Add tests

This commit is contained in:
MartinBraquet
2025-08-04 14:25:44 +02:00
parent a2abc4fda9
commit 814b4fe0ae
3 changed files with 22 additions and 10 deletions

View File

@@ -42,6 +42,14 @@ jobs:
# Optional: Playwright E2E tests
- name: Install Playwright deps
run: npx playwright install --with-deps
# npm install @playwright/test
# npx playwright install
- name: Run E2E tests
run: npx playwright test
run: |
npm start &
npx wait-on http://localhost:3000
npx playwright test tests/playwright
SERVER_PID=$(fuser -k 3000/tcp)
echo $SERVER_PID
kill $SERVER_PID

View File

@@ -1,17 +1,13 @@
import { render, screen } from '@testing-library/react';
import {render, screen} from '@testing-library/react';
import LoadingSpinner from '../lib/client/LoadingSpinner';
import '@testing-library/jest-dom';
describe('LoadingSpinner', () => {
it('renders a loading spinner', () => {
render(<LoadingSpinner />);
// Check if the spinner container is rendered with the correct classes
const spinnerContainer = screen.getByTestId('spinner-container');
expect(spinnerContainer).toBeInTheDocument();
expect(spinnerContainer).toHaveClass('flex', 'items-center', 'justify-center', 'min-h-screen');
render(<LoadingSpinner/>);
// Check if the spinner has the correct classes
const spinner = screen.getByTestId('spinner');
expect(spinner).toHaveClass('w-12', 'h-12', 'border-4', 'border-gray-300', 'border-t-gray-800', 'rounded-full', 'animate-spin');
expect(spinner).toHaveClass('animate-spin');
});
});

View File

@@ -0,0 +1,8 @@
import {expect, test} from '@playwright/test';
test('shows loading spinner on load', async ({page}) => {
await page.goto('http://localhost:3000/profiles'); // Adjust this to your route
const spinner = page.locator('[data-testid="spinner"]');
await expect(spinner).toBeVisible();
});