rework of the e2e test suites

This commit is contained in:
Codex Agent
2025-11-19 22:23:33 +01:00
parent 8d2075bdd2
commit 0127114e59
32 changed files with 1593 additions and 124 deletions

View File

@@ -0,0 +1,33 @@
import { test, expect } from '@playwright/test';
test.describe('Marketing hero CTA smoke', () => {
test('home hero CTA navigates to packages', async ({ page, baseURL }) => {
test.skip(!baseURL, 'baseURL is required to run marketing smoke tests');
await page.goto('/');
const cta = page.getByRole('link', {
name: /Pakete entdecken|Jetzt loslegen|Discover Packages|Get started now/i,
});
await expect(cta).toBeVisible();
await cta.click();
await expect(page).toHaveURL(/\/packages/);
});
test('packages hero CTA jumps to endcustomer section', async ({ page, baseURL }) => {
test.skip(!baseURL, 'baseURL is required to run marketing smoke tests');
await page.goto('/packages');
const cta = page.getByRole('link', {
name: /Pakete entdecken|Lieblingspaket sichern|Discover Packages|Explore top packages/i,
});
await expect(cta).toBeVisible();
await cta.click();
await expect(page.locator('#endcustomer')).toBeVisible();
});
});

View File

@@ -0,0 +1,155 @@
import { test, expect } from '@playwright/test';
import { execSync } from 'child_process';
const LOGIN_EMAIL = 'checkout-e2e@example.com';
const LOGIN_PASSWORD = 'Password123!';
test.describe('Checkout Payment Step Paddle flow', () => {
test.beforeAll(async () => {
execSync(
`php artisan tenant:add-dummy --email=${LOGIN_EMAIL} --password=${LOGIN_PASSWORD} --first_name=Checkout --last_name=Tester --address="Playwrightstr. 1" --phone="+4912345678"`
);
execSync(
`php artisan tinker --execute="App\\\\Models\\\\User::where('email', '${LOGIN_EMAIL}')->update(['email_verified_at' => now()]);"`
);
});
test.beforeEach(async ({ page }) => {
await page.goto('/login');
await page.fill('input[name="email"]', LOGIN_EMAIL);
await page.fill('input[name="password"]', LOGIN_PASSWORD);
await page.getByRole('button', { name: /Anmelden|Login/ }).click();
await expect(page).toHaveURL(/dashboard/);
});
test('opens Paddle checkout and shows success notice', async ({ page }) => {
await page.route('**/paddle/create-checkout', async (route) => {
const request = route.request();
const postData = request.postDataJSON() as { inline?: boolean } | null;
const inline = Boolean(postData?.inline);
if (inline) {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
mode: 'inline',
items: [
{ priceId: 'pri_123', quantity: 1 },
],
custom_data: {
tenant_id: '1',
package_id: '2',
checkout_session_id: 'cs_123',
},
customer: {
email: LOGIN_EMAIL,
},
}),
});
return;
}
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
checkout_url: 'https://paddle.test/checkout/success',
}),
});
});
await page.route('https://cdn.paddle.com/paddle/v2/paddle.js', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/javascript',
body: `
window.Paddle = {
Environment: { set: function(env) { window.__paddleEnv = env; } },
Initialize: function(opts) { window.__paddleInit = opts; },
Checkout: {
open: function(config) {
window.__paddleOpenConfig = config;
}
}
};
`,
});
});
await openCheckoutPaymentStep(page);
await page.evaluate(() => {
window.__openedUrls = [];
window.open = (url: string, target?: string | null, features?: string | null) => {
window.__openedUrls.push({ url, target: target ?? null, features: features ?? null });
return null;
};
});
await page.getByRole('button', { name: /Continue with Paddle|Weiter mit Paddle/ }).click();
await expect(
page.locator(
'text=/Paddle checkout is running in a secure overlay|Der Paddle-Checkout läuft jetzt in einem Overlay/'
)
).toBeVisible();
await expect.poll(async () => {
return page.evaluate(() => window.__paddleOpenConfig?.items?.[0]?.priceId ?? null);
}).toBe('pri_123');
await expect.poll(async () => {
return page.evaluate(() => window.__openedUrls?.length ?? 0);
}).toBe(0);
});
test('shows error state when Paddle checkout creation fails', async ({ page }) => {
await page.route('**/paddle/create-checkout', async (route) => {
await route.fulfill({
status: 500,
contentType: 'application/json',
body: JSON.stringify({ message: 'test-error' }),
});
});
await openCheckoutPaymentStep(page);
await page.getByRole('button', { name: /Continue with Paddle|Weiter mit Paddle/ }).click();
await expect(
page.locator('text=/Paddle checkout could not be started|Paddle-Checkout konnte nicht gestartet werden/')
).toBeVisible();
});
});
async function openCheckoutPaymentStep(page: import('@playwright/test').Page) {
await page.goto('/packages');
const checkoutLink = page.locator('a[href^="/checkout/"]').first();
const href = await checkoutLink.getAttribute('href');
if (!href) {
throw new Error('No checkout link found on packages page.');
}
await page.goto(href);
const nextButton = page.getByRole('button', {
name: /Weiter zum Zahlungsschritt|Continue to Payment/,
});
if (await nextButton.isVisible()) {
await nextButton.click();
}
await page.waitForSelector('text=/Zahlung|Payment/');
}
declare global {
interface Window {
__openedUrls?: Array<{ url: string; target?: string | null; features?: string | null }>;
__paddleOpenConfig?: { url?: string; items?: Array<{ priceId: string; quantity: number }>; settings?: { displayMode?: string } };
__paddleEnv?: string;
__paddleInit?: Record<string, unknown>;
}
}

View File

@@ -0,0 +1,12 @@
import { test, expectFixture as expect } from '../helpers/test-fixtures';
test.describe('Coupon scaffolding', () => {
test('default coupon presets are created via testing API', async ({ seedTestCoupons }) => {
const seeded = await seedTestCoupons();
expect(seeded.length).toBeGreaterThanOrEqual(3);
expect(seeded.map((coupon) => coupon.code)).toEqual(
expect.arrayContaining(['PERCENT10', 'FLAT50', 'EXPIRED25'])
);
});
});

View File

@@ -0,0 +1,106 @@
import { test, expect } from '@playwright/test';
test.describe('Homepage Links Test', () => {
test('Click all links on homepage and check for errors', async ({ page }) => {
// Listen for failed requests (e.g., 404s)
const failedRequests: { url: string; status: number }[] = [];
page.on('response', response => {
if (response.status() >= 400) {
failedRequests.push({
url: response.url(),
status: response.status()
});
}
});
// Listen for console errors
const consoleErrors: string[] = [];
page.on('console', msg => {
if (msg.type() === 'error') {
consoleErrors.push(msg.text());
}
});
// Navigate to homepage
await page.goto('/');
// Wait for page to load
await page.waitForLoadState('networkidle');
// Get all links
const links = page.locator('a');
const linkCount = await links.count();
console.log(`Found ${linkCount} links on homepage.`);
for (let i = 0; i < linkCount; i++) {
const link = links.nth(i);
const href = await link.getAttribute('href');
const text = await link.textContent() || '';
if (!href || href.startsWith('#') || href.startsWith('mailto:') || href.startsWith('tel:')) {
console.log(`Skipping non-navigational link: ${text} (${href})`);
continue;
}
console.log(`Clicking link ${i + 1}/${linkCount}: "${text}" -> ${href}`);
// For each link, create temporary listeners
const linkFailedRequests: { url: string; status: number }[] = [];
const linkConsoleErrors: string[] = [];
const linkResponseHandler = (response: any) => {
if (response.status() >= 400) {
linkFailedRequests.push({
url: response.url(),
status: response.status()
});
}
};
const linkConsoleHandler = (msg: any) => {
if (msg.type() === 'error') {
linkConsoleErrors.push(msg.text());
}
};
page.on('response', linkResponseHandler);
page.on('console', linkConsoleHandler);
let currentUrl = page.url();
try {
// Hover and click
await link.hover();
await link.click({ force: true });
// Wait for navigation or load
await page.waitForTimeout(2000);
currentUrl = page.url();
// Remove temporary handlers
page.removeListener('response', linkResponseHandler);
page.removeListener('console', linkConsoleHandler);
// Check for errors during this click
expect(linkFailedRequests.length).toBe(0);
expect(linkConsoleErrors.length).toBe(0);
console.log(`✓ Link "${text}" successful: ${currentUrl}`);
} catch (error: unknown) {
// Remove handlers
page.removeListener('response', linkResponseHandler);
page.removeListener('console', linkConsoleHandler);
console.error(`✗ Error clicking link "${text}": ${(error as Error).message}`);
}
// Go back to homepage if navigated away
if (currentUrl !== page.url() && !currentUrl.includes('/')) {
await page.goBack({ waitUntil: 'networkidle' });
}
}
// Final checks
expect(failedRequests.length).toBe(0);
expect(consoleErrors.length).toBe(0);
console.log('All links tested successfully.');
});
});

View File

@@ -0,0 +1,95 @@
import { test, expect } from '@playwright/test';
import { execSync } from 'child_process'; // Für artisan seed
test.describe('Marketing Package Flow: Auswahl → Registrierung → Kauf (Free & Paid)', () => {
test.beforeAll(async () => {
// Seed Test-Tenant (einmalig)
execSync('php artisan tenant:add-dummy --email=test@example.com --password=password123 --first_name=Test --last_name=User --address="Teststr. 1" --phone="+49123"');
// Mock Verifizierung: Update DB (in Test-Env)
execSync('php artisan tinker --execute="App\\Models\\User::where(\'email\', \'test@example.com\')->update([\'email_verified_at\' => now()]);"');
});
test('Free-Paket-Flow mit Wizard (ID=1, Starter, eingeloggter User)', async ({ page }) => {
// Login first
await page.goto('http://localhost:8000/de/login');
await page.fill('[name="email"]', 'test@example.com');
await page.fill('[name="password"]', 'password123');
await page.getByRole('button', { name: 'Anmelden' }).click();
await expect(page).toHaveURL(/\/dashboard/);
// Go to Wizard
await page.goto('http://localhost:8000/purchase-wizard/10');
await expect(page.locator('text=Sie sind bereits eingeloggt')).toBeVisible();
await page.getByRole('button', { name: 'Weiter zum Zahlungsschritt' }).click();
await expect(page).toHaveURL(/\/purchase-wizard\/1/); // Next step
await page.screenshot({ path: 'wizard-logged-in.png', fullPage: true });
// Payment (Free: Success)
await expect(page.locator('text=Free package assigned')).toBeVisible();
await page.screenshot({ path: 'wizard-free-success.png', fullPage: true });
});
test('Wizard Login-Fehler mit Toast', async ({ page }) => {
await page.goto('http://localhost:8000/purchase-wizard/10');
// Switch to Login
await page.getByRole('button', { name: 'Anmelden' }).click();
await page.fill('[name="email"]', 'wrong@example.com');
await page.fill('[name="password"]', 'wrong');
await page.getByRole('button', { name: 'Anmelden' }).click();
await expect(page.locator('[data-testid="toast"]')).toBeVisible(); // Toast for error
await expect(page.locator('text=Ungültige Anmeldedaten')).toBeVisible(); // Inline error
await page.screenshot({ path: 'wizard-login-error.png', fullPage: true });
});
test('Wizard Registrierung-Fehler mit Toast', async ({ page }) => {
await page.goto('http://localhost:8000/purchase-wizard/10');
// Reg form with invalid data
await page.fill('[name="email"]', 'invalid');
await page.getByRole('button', { name: 'Registrieren' }).click();
await expect(page.locator('[data-testid="toast"]')).toBeVisible();
await expect(page.locator('text=Das E-Mail muss eine gültige E-Mail-Adresse sein')).toBeVisible();
await page.screenshot({ path: 'wizard-reg-error.png', fullPage: true });
});
test('Wizard Erfolgreiche Reg mit Success-Message', async ({ page }) => {
await page.goto('http://localhost:8000/purchase-wizard/10');
// Fill valid reg data (use unique email)
await page.fill('[name="first_name"]', 'TestReg');
await page.fill('[name="last_name"]', 'User');
await page.fill('[name="email"]', 'testreg@example.com');
await page.fill('[name="username"]', 'testreguser');
await page.fill('[name="address"]', 'Teststr. 1');
await page.fill('[name="phone"]', '+49123');
await page.fill('[name="password"]', 'Password123!');
await page.fill('[name="password_confirmation"]', 'Password123!');
await page.check('[name="privacy_consent"]');
await page.getByRole('button', { name: 'Registrieren' }).click();
await expect(page.locator('text=Sie sind nun eingeloggt')).toBeVisible(); // Success message
await page.waitForTimeout(2000); // Auto-next
await expect(page).toHaveURL(/\/purchase-wizard\/1/); // Payment step
await page.screenshot({ path: 'wizard-reg-success.png', fullPage: true });
});
test('Paid-Paket-Flow (ID=2, Pro mit Stripe-Test)', async ({ page }) => {
// Ähnlich wie Free, aber package_id=2
await page.goto('http://localhost:8000/de/packages');
await page.getByRole('button', { name: 'Details anzeigen' }).nth(1).click(); // Zweites Paket (Paid)
// ... (Modal, Register/Login wie oben)
await expect(page).toHaveURL(/\/buy-packages\/2/);
// Mock Stripe
await page.route('https://checkout.stripe.com/**', async route => {
await route.fulfill({ status: 200, body: '<html>Mock Stripe Success</html>' });
});
// Simuliere Checkout: Fill Test-Karte
await page.fill('[name="cardNumber"]', '4242424242424242');
await page.fill('[name="cardExpiry"]', '12/25');
await page.fill('[name="cardCvc"]', '123');
await page.click('[name="submit"]');
await page.waitForURL(/\/marketing\/success/); // Nach Webhook
await page.screenshot({ path: 'paid-step6-success.png', fullPage: true });
// Integration: Limits-Check wie in package-flow.test.ts
await expect(page.locator('text=Remaining Photos')).toContainText('Unbegrenzt'); // Pro-Limit
});
});

View File

@@ -0,0 +1,60 @@
import { test, expect } from '@playwright/test';
import { chromium } from 'playwright';
test.describe('Package Flow in Admin PWA', () => {
test('Create event with package and verify limits', async ({ page }) => {
// Assume logged in as tenant admin, navigate to events page
await page.goto('/event-admin/events');
// Click create event button
await page.click('[data-testid="create-event"]');
await expect(page).toHaveURL(/\/event-admin\/events\/create/);
// Fill form
await page.fill('[name="name"]', 'Test Package Event');
await page.fill('[name="slug"]', 'test-package-event');
await page.fill('[name="date"]', '2025-10-01');
// Select package from dropdown
await page.selectOption('[name="package_id"]', '1'); // Assume ID 1 is Starter package
await expect(page.locator('[name="package_id"]')).toHaveValue('1');
// Submit
await page.click('[type="submit"]');
await expect(page).toHaveURL(/\/event-admin\/events/);
// Verify event created and package assigned
await expect(page.locator('text=Test Package Event')).toBeVisible();
await expect(page.locator('text=Starter')).toBeVisible(); // Package name in table
// Check dashboard limits
await page.goto('/event-admin/events');
await expect(page.locator('text=Remaining Photos')).toContainText('300'); // Starter limit
// Try to create another event to test reseller limit if applicable
// (Skip for endcustomer; assume tenant has reseller package with limit 1)
await page.goto('/event-admin/events');
await page.click('[data-testid="create-event"]');
await page.fill('[name="name"]', 'Second Event');
await page.fill('[name="slug"]', 'second-event');
await page.fill('[name="date"]', '2025-10-02');
await page.selectOption('[name="package_id"]', '1');
await page.click('[type="submit"]');
// If limit reached, expect error
await expect(page.locator('text=No available package')).toBeVisible();
});
test('Upload blocked when package limit reached in Guest PWA', async ({ page }) => {
// Assume event with package limit 0 created
await page.goto('/e/test-limited-event'); // Slug of event with max_photos = 0
// Navigate to upload
await page.click('text=Upload');
await expect(page).toHaveURL(/\/upload/);
// Expect upload disabled and error message
await expect(page.locator('button:disabled')).toBeVisible(); // Upload button disabled
await expect(page.locator('text=Upload-Limit erreicht')).toBeVisible();
});
});

View File

@@ -0,0 +1,159 @@
import { test, expectFixture as expect } from '../helpers/test-fixtures';
test.describe('Standard package checkout with Paddle completion', () => {
test('registers, applies coupon, and reaches confirmation', async ({
page,
clearTestMailbox,
getLatestCheckoutSession,
simulatePaddleCompletion,
getTestMailbox,
}) => {
await clearTestMailbox();
const unique = Date.now();
const email = `checkout+${unique}@example.test`;
const password = 'Password123!';
const username = `playwright-${unique}`;
await page.addInitScript(() => {
window.__openedWindows = [];
const originalOpen = window.open;
window.open = function (...args) {
window.__openedWindows.push(args);
return originalOpen?.apply(this, args) ?? null;
};
});
await page.route('https://cdn.paddle.com/paddle/v2/paddle.js', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/javascript',
body: `
window.__paddleEventCallback = null;
window.__paddleInitOptions = null;
window.__paddleCheckoutConfig = null;
window.Paddle = {
Environment: { set() {} },
Initialize(options) {
window.__paddleInitOptions = options;
window.__paddleEventCallback = options?.eventCallback || null;
},
Checkout: {
open(config) {
window.__paddleCheckoutConfig = config;
},
},
};
`,
});
});
let paddleRequestPayload: Record<string, unknown> | null = null;
await page.route('**/paddle/create-checkout', async (route) => {
paddleRequestPayload = route.request().postDataJSON() as Record<string, unknown>;
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
checkout_url: 'https://sandbox.paddle.test/checkout/abc123',
}),
});
});
await page.goto('/de/packages');
const standardDetailsButton = page
.getByRole('heading', { name: /^Standard$/ })
.locator('..')
.getByRole('button', { name: /Details/i })
.first();
await expect(standardDetailsButton).toBeVisible();
await standardDetailsButton.click();
await expect(page.getByRole('dialog')).toBeVisible();
await page.getByRole('link', { name: /Jetzt bestellen|Order now/i }).click();
await expect(page).toHaveURL(/purchase-wizard/);
await page.getByRole('button', { name: /^Weiter$/ }).first().click();
await expect(page.getByRole('heading', { name: 'Registrieren' })).toBeVisible();
await page.getByLabel(/Vorname/i).fill('Playwright');
await page.getByLabel(/Nachname/i).fill('Tester');
await page.getByLabel(/E-Mail/i).fill(email);
await page.getByLabel(/Telefon/i).fill('+49123456789');
await page.getByLabel(/Adresse/i).fill('Teststr. 1, 12345 Berlin');
await page.getByLabel(/Username/i).fill(username);
await page.getByLabel(/^Passwort$/i).fill(password);
await page.getByLabel(/Passwort bestätigen/i).fill(password);
await page.getByLabel(/Datenschutzerklärung/i).check();
await page.getByRole('button', { name: /^Registrieren$/ }).click();
await expect(page.getByRole('heading', { name: 'Zahlung' })).toBeVisible();
await page.getByPlaceholder(/Gutscheincode/i).fill('PERCENT10');
await page.getByRole('button', { name: /Gutschein anwenden|Apply coupon/i }).click();
await expect(page.getByText(/Gutschein PERCENT10/i)).toBeVisible();
await page.getByRole('button', { name: /Weiter mit Paddle|Continue with Paddle/i }).click();
await expect.poll(async () => page.evaluate(() => window.__paddleCheckoutConfig)).not.toBeNull();
await expect.poll(async () => {
return page.evaluate(() => window.__openedWindows?.length ?? 0);
}).toBe(1);
await expect.poll(async () => {
return page.evaluate(() => window.__openedWindows?.[0]?.[0] ?? null);
}).toContain('https://sandbox.paddle.test/checkout/abc123');
await page.evaluate(() => {
window.__paddleEventCallback?.({ name: 'checkout.completed' });
});
let session = null;
for (let i = 0; i < 6; i++) {
session = await getLatestCheckoutSession({ email });
if (session) {
break;
}
await page.waitForTimeout(500);
}
expect(session).not.toBeNull();
await simulatePaddleCompletion(session!.id);
for (let i = 0; i < 6; i++) {
const refreshed = await getLatestCheckoutSession({ email });
if (refreshed?.status === 'completed') {
session = refreshed;
break;
}
await page.waitForTimeout(500);
}
expect(session?.status).toBe('completed');
await expect(page.getByRole('button', { name: /^Weiter$/ })).toBeEnabled();
await page.getByRole('button', { name: /^Weiter$/ }).last().click();
await expect(page.getByText(/Marketing-Dashboard/)).toBeVisible();
await expect(
page.getByRole('button', { name: /Zum Admin-Bereich|To Admin Area/i })
).toBeVisible();
expect(paddleRequestPayload).not.toBeNull();
expect(paddleRequestPayload?.['coupon_code']).toBe('PERCENT10');
const messages = await getTestMailbox();
expect(messages.length).toBeGreaterThan(0);
});
});
declare global {
interface Window {
__openedWindows?: unknown[];
__paddleEventCallback?: ((event: { name: string }) => void) | null;
__paddleInitOptions?: unknown;
__paddleCheckoutConfig?: unknown;
}
}

View File

@@ -0,0 +1,49 @@
import { test, expectFixture as expect } from '../helpers/test-fixtures';
test.describe('Standard package checkout with coupons', () => {
test('applies seeded coupon and shows discount summary', async ({
page,
tenantAdminCredentials,
seedTestCoupons,
}) => {
test.skip(!tenantAdminCredentials, 'Tenant admin credentials required via E2E_TENANT_EMAIL/PASSWORD');
await seedTestCoupons();
await page.goto('/de/packages');
const detailsButtons = page.getByRole('button', {
name: /Details ansehen|Details anzeigen|View details/i,
});
await expect(detailsButtons.first()).toBeVisible();
await detailsButtons.nth(1).click();
const dialog = page.getByRole('dialog');
await expect(dialog).toBeVisible();
await expect(dialog.getByRole('heading', { name: /Standard/i })).toBeVisible();
await dialog.getByRole('link', { name: /Jetzt bestellen|Order now|Jetzt buchen/i }).click();
await expect(page).toHaveURL(/\/purchase-wizard\/\d+/);
await page.getByRole('button', { name: /^Weiter$/ }).first().click();
await expect(page.getByRole('heading', { name: /Registrieren/i })).toBeVisible();
await page.getByRole('button', { name: /^Anmelden$/ }).first().click();
await page.fill('input[name="identifier"]', tenantAdminCredentials.email);
await page.fill('input[name="password"]', tenantAdminCredentials.password);
await page.getByRole('button', { name: /^Anmelden$/ }).last().click();
await expect(page.getByPlaceholder(/Gutscheincode/i)).toBeVisible();
await page.getByPlaceholder(/Gutscheincode/i).fill('PERCENT10');
await page.getByRole('button', { name: /Gutschein anwenden|Apply coupon/i }).click();
await expect(page.getByText(/Gutschein PERCENT10 aktiviert/i)).toBeVisible();
await expect(page.getByText(/Rabatt|Discount/i)).toBeVisible();
await expect(page.getByText(/Total|Gesamt/i)).toBeVisible();
});
});