Files
klz-cables.com/tests/brochure-modal.test.ts
Marc Mintel 02be8e59b2
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 8s
Build & Deploy / 🧪 QA (push) Failing after 1m53s
Build & Deploy / 🏗️ Build (push) Has been skipped
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 2s
feat: auto-opening brochure modal with mintel/mail delivery
- implemented BrochureDeliveryEmail template

- created AutoBrochureModal wrapper with 5s delay

- updated layout.tsx and BrochureCTA to use new success state

- added tests/brochure-modal.test.ts e2e test
2026-03-02 23:08:05 +01:00

66 lines
2.1 KiB
TypeScript

import { test, expect, beforeAll, afterAll } from 'vitest';
import puppeteer, { Browser, Page } from 'puppeteer';
import { createServer } from 'http';
import { parse } from 'url';
import next from 'next';
let browser: Browser;
let page: Page;
// The URL of the local Next.js server we are testing against.
// In CI, we expect the server to already be running at http://127.0.0.1:3000
const BASE_URL = process.env.TEST_URL || 'http://127.0.0.1:3000';
beforeAll(async () => {
browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
});
});
afterAll(async () => {
if (browser) {
await browser.close();
}
});
test('AutoBrochureModal should open after 5 seconds and submit email', async () => {
// Set a long timeout for the test to prevent premature failure
page = await browser.newPage();
// Clear localStorage to ensure the auto-open logic fires
await page.goto(BASE_URL);
await page.evaluate(() => {
localStorage.clear();
});
// Reload page to start the timer fresh
await page.goto(BASE_URL, { waitUntil: 'networkidle0' });
// Wait for auto-trigger (set to 5s in code, we wait up to 10s here)
const modal = await page.waitForSelector('div[role="dialog"]', { timeout: 10000 });
expect(modal).not.toBeNull();
// Ensure the email input is present inside the modal (using the placeholder to be sure)
const emailInput = await page.waitForSelector('input[name="email"]', { visible: true });
expect(emailInput).not.toBeNull();
// Fill the form matching BrochureCTA.tsx id=brochure-email
await page.type('input[name="email"]', 'test-brochure@mintel.me');
// Submit the form
await page.click('button[type="submit"]');
// Wait for the success state UI to appear
await page.waitForFunction(
() =>
document.body.innerText.includes('Successfully sent') ||
document.body.innerText.includes('Erfolgreich gesendet'),
{ timeout: 10000 },
);
// Verify localStorage was set correctly so it doesn't open again
const hasSeenModal = await page.evaluate(() => localStorage.getItem('klz_brochure_modal_seen'));
expect(hasSeenModal).toBe('true');
}, 30000);