Initial commit
This commit is contained in:
66
landing-e2e/src/landing.spec.ts
Normal file
66
landing-e2e/src/landing.spec.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test.describe('landing', () => {
|
||||
test('renders the hero server-side', async ({ page }) => {
|
||||
const response = await page.goto('/');
|
||||
|
||||
expect(response?.status()).toBe(200);
|
||||
await expect(page.locator('h1')).toContainText('Construimos software');
|
||||
});
|
||||
|
||||
test('serves the page in the language the URL asks for', async ({ page }) => {
|
||||
await page.goto('/?lang=en');
|
||||
|
||||
await expect(page.locator('h1')).toContainText('We build software');
|
||||
await expect(page.locator('html')).toHaveAttribute('lang', 'en');
|
||||
});
|
||||
|
||||
test('server-renders the whole page, not just the top of it', async ({
|
||||
browser,
|
||||
}) => {
|
||||
// With JavaScript off, what is left is exactly what the server sent. The
|
||||
// check is the last section and the footer: a component that throws during
|
||||
// rendering does not merely lose itself, it abandons everything after it,
|
||||
// and the page still answers 200 while quietly ending early. That is how
|
||||
// `pi-carousel` reaching for `document` once cost this page its contact
|
||||
// form server-side.
|
||||
const context = await browser.newContext({ javaScriptEnabled: false });
|
||||
const page = await context.newPage();
|
||||
|
||||
await page.goto('/');
|
||||
|
||||
await expect(page.locator('h1')).toContainText('Construimos software');
|
||||
await expect(page.locator('#contacto')).toBeAttached();
|
||||
await expect(page.getByRole('contentinfo')).toContainText('Pireon');
|
||||
|
||||
await context.close();
|
||||
});
|
||||
|
||||
test('answers 404 for an address it does not serve', async ({ page }) => {
|
||||
const response = await page.goto('/no-existe');
|
||||
|
||||
expect(response?.status()).toBe(404);
|
||||
await expect(page.locator('h1')).toContainText('no existe');
|
||||
});
|
||||
|
||||
test('refuses an incomplete contact submission without calling the API', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto('/');
|
||||
await page.locator('#contacto').scrollIntoViewIfNeeded();
|
||||
|
||||
const before = page.url();
|
||||
const submit = page.getByRole('button', { name: 'Enviar' });
|
||||
|
||||
// Enabled only once hydration attached the handler — before that a click
|
||||
// would submit natively and navigate away with the message. The generous
|
||||
// timeout is for the dev server's first compile, not for hydration.
|
||||
await expect(submit).toBeEnabled({ timeout: 30_000 });
|
||||
await submit.click();
|
||||
|
||||
// Nothing navigates and nothing is sent: the form holds the visitor there
|
||||
// rather than spending one of their throttled attempts on a bad payload.
|
||||
await expect(submit).toBeVisible();
|
||||
expect(page.url()).toBe(before);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user