lightweight, client-only calendar web application. All data persists in the URL hash for instant sharing, No backend required. Optional AES-GCM password protection keeps shared links locked without a server
JavaScript
feat: Add end-to-end testing setup with Playwright and implement various E2E tests
Supun Lakmal75efe2b5ed60
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.ymlnew file mode 100644index 0000000..884ee4c--- /dev/null+++ b/.github/workflows/e2e.yml@@ -0,0 +1,58 @@+name: E2E Tests++on:+ pull_request:+ push:+ branches: ["main"]+ workflow_dispatch:++jobs:+ playwright:+ runs-on: ubuntu-latest+ strategy:+ fail-fast: false+ matrix:+ include:+ - project: chromium+ browser: chromium+ - project: firefox+ browser: firefox+ - project: webkit+ browser: webkit+ - project: mobile-chromium+ browser: chromium++ steps:+ - name: Checkout repository+ uses: actions/checkout@v4++ - name: Set up Node.js+ uses: actions/setup-node@v4+ with:+ node-version: 20+ cache: npm++ - name: Install dependencies+ run: npm ci++ - name: Install Playwright browser+ run: npx playwright install --with-deps ${{ matrix.browser }}++ - name: Run E2E suite+ run: npx playwright test --project=${{ matrix.project }}++ - name: Upload Playwright report+ if: ${{ always() }}+ uses: actions/upload-artifact@v4+ with:+ name: playwright-report-${{ matrix.project }}+ path: playwright-report+ if-no-files-found: ignore++ - name: Upload raw test results+ if: ${{ always() }}+ uses: actions/upload-artifact@v4+ with:+ name: test-results-${{ matrix.project }}+ path: test-results+ if-no-files-found: ignorediff --git a/.gitignore b/.gitignoreindex ba1cc2e..290f4c8 100644--- a/.gitignore+++ b/.gitignore@@ -1,2 +1,5 @@-.env-.vscode\ No newline at end of file+.env+.vscode+node_modules+playwright-report+test-resultsdiff --git a/README.md b/README.mdindex 6529c33..b535558 100644--- a/README.md+++ b/README.md@@ -121,6 +121,38 @@ docker compose up --buildDefault ports are `80` and `443` (override with `HOST_PORT_HTTP` / `HOST_PORT_HTTPS`).+## E2E testing (Playwright)++Install dependencies and browsers once:++```bash+npm install+npm run test:e2e:install+```++Run the E2E suite:++```bash+npm run test:e2e+```++Useful local modes:++```bash+npm run test:e2e:chromium+npm run test:e2e:mobile+npm run test:e2e:cross+npm run test:e2e:headed+npm run test:e2e:ui+npm run test:e2e:debug+```++Notes:++- `test:e2e` runs all configured Playwright projects.+- Firefox/WebKit run the cross-browser smoke suite (`tests/e2e/smoke.cross.e2e.spec.js`).+- Full feature coverage runs on Chromium desktop, plus mobile-focused coverage on the mobile Chromium project.+## JSON bridge (`json.html`)Use `json.html` to pass JSON payloads via query params (`json`, `data`, `state`, `payload`) and auto-redirect to a compressed hash URL.diff --git a/modules/modalManager.js b/modules/modalManager.jsindex d03ee34..c8bac3c 100644--- a/modules/modalManager.js+++ b/modules/modalManager.js@@ -76,14 +76,7 @@ export function createPasswordModalController({ ui, hiddenClass, t }) {return { open, close, submit };}-export function createJsonModalController({- ui,- hiddenClass,- t,- showToast,- getState,- getHash,-} = {}) {+export function createJsonModalController({ ui, hiddenClass, t, showToast, getState, getHash } = {}) {const safeHiddenClass = hiddenClass || "hidden";function isOpen() {diff --git a/package-lock.json b/package-lock.jsonnew file mode 100644index 0000000..a97b6ce--- /dev/null+++ b/package-lock.json@@ -0,0 +1,78 @@+{+ "name": "hash-calendar",+ "version": "1.0.0",+ "lockfileVersion": 3,+ "requires": true,+ "packages": {+ "": {+ "name": "hash-calendar",+ "version": "1.0.0",+ "devDependencies": {+ "@playwright/test": "^1.52.0"+ }+ },+ "node_modules/@playwright/test": {+ "version": "1.58.2",+ "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.58.2.tgz",+ "integrity": "sha512-akea+6bHYBBfA9uQqSYmlJXn61cTa+jbO87xVLCWbTqbWadRVmhxlXATaOjOgcBaWU4ePo0wB41KMFv3o35IXA==",+ "dev": true,+ "license": "Apache-2.0",+ "dependencies": {+ "playwright": "1.58.2"+ },+ "bin": {+ "playwright": "cli.js"+ },+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/fsevents": {+ "version": "2.3.2",+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",+ "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",+ "dev": true,+ "hasInstallScript": true,+ "license": "MIT",+ "optional": true,+ "os": [+ "darwin"+ ],+ "engines": {+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"+ }+ },+ "node_modules/playwright": {+ "version": "1.58.2",+ "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.58.2.tgz",+ "integrity": "sha512-vA30H8Nvkq/cPBnNw4Q8TWz1EJyqgpuinBcHET0YVJVFldr8JDNiU9LaWAE1KqSkRYazuaBhTpB5ZzShOezQ6A==",+ "dev": true,+ "license": "Apache-2.0",+ "dependencies": {+ "playwright-core": "1.58.2"+ },+ "bin": {+ "playwright": "cli.js"+ },+ "engines": {+ "node": ">=18"+ },+ "optionalDependencies": {+ "fsevents": "2.3.2"+ }+ },+ "node_modules/playwright-core": {+ "version": "1.58.2",+ "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.58.2.tgz",+ "integrity": "sha512-yZkEtftgwS8CsfYo7nm0KE8jsvm6i/PTgVtB8DL726wNf6H2IMsDuxCpJj59KDaxCtSnrWan2AeDqM7JBaultg==",+ "dev": true,+ "license": "Apache-2.0",+ "bin": {+ "playwright-core": "cli.js"+ },+ "engines": {+ "node": ">=18"+ }+ }+ }+}diff --git a/package.json b/package.jsonnew file mode 100644index 0000000..7f4f730--- /dev/null+++ b/package.json@@ -0,0 +1,20 @@+{+ "name": "hash-calendar",+ "version": "1.0.0",+ "private": true,+ "description": "Privacy-first client-side calendar",+ "scripts": {+ "test:e2e": "playwright test",+ "test:e2e:chromium": "playwright test --project=chromium",+ "test:e2e:mobile": "playwright test --project=mobile-chromium",+ "test:e2e:cross": "playwright test --project=firefox --project=webkit",+ "test:e2e:headed": "playwright test --headed",+ "test:e2e:ui": "playwright test --ui",+ "test:e2e:debug": "playwright test --debug",+ "test:e2e:report": "playwright show-report",+ "test:e2e:install": "playwright install chromium firefox webkit"+ },+ "devDependencies": {+ "@playwright/test": "^1.52.0"+ }+}diff --git a/playwright.config.cjs b/playwright.config.cjsnew file mode 100644index 0000000..062855b--- /dev/null+++ b/playwright.config.cjs@@ -0,0 +1,58 @@+const { defineConfig, devices } = require("@playwright/test");++const PORT = Number(process.env.PORT || 4173);+const baseURL = process.env.PLAYWRIGHT_BASE_URL || `http://127.0.0.1:${PORT}`;++module.exports = defineConfig({+ testDir: "./tests/e2e",+ timeout: 45_000,+ expect: {+ timeout: 5_000,+ },+ fullyParallel: true,+ forbidOnly: !!process.env.CI,+ retries: process.env.CI ? 2 : 0,+ workers: process.env.CI ? 1 : 3,+ reporter: process.env.CI+ ? [["github"], ["html", { open: "never" }]]+ : [["list"], ["html", { open: "never" }]],+ use: {+ baseURL,+ trace: "on-first-retry",+ screenshot: "only-on-failure",+ video: "retain-on-failure",+ serviceWorkers: "block",+ locale: "en-US",+ timezoneId: "UTC",+ },+ webServer: process.env.PLAYWRIGHT_BASE_URL+ ? undefined+ : {+ command: `node tests/e2e/static-server.cjs ${PORT}`,+ port: PORT,+ reuseExistingServer: !process.env.CI,+ timeout: 120_000,+ },+ projects: [+ {+ name: "chromium",+ use: { ...devices["Desktop Chrome"] },+ testIgnore: ["**/*.mobile.e2e.spec.js"],+ },+ {+ name: "firefox",+ use: { ...devices["Desktop Firefox"] },+ testMatch: ["**/*.cross.e2e.spec.js"],+ },+ {+ name: "webkit",+ use: { ...devices["Desktop Safari"] },+ testMatch: ["**/*.cross.e2e.spec.js"],+ },+ {+ name: "mobile-chromium",+ use: { ...devices["Pixel 7"] },+ testMatch: ["**/*.mobile.e2e.spec.js"],+ },+ ],+});diff --git a/tests/e2e/browser-apis.chromium.e2e.spec.js b/tests/e2e/browser-apis.chromium.e2e.spec.jsnew file mode 100644index 0000000..e07919d--- /dev/null+++ b/tests/e2e/browser-apis.chromium.e2e.spec.js@@ -0,0 +1,61 @@+const { test, expect } = require("@playwright/test");+const { waitForApp, createEvent } = require("./helpers.cjs");++test("copy link writes to clipboard API", async ({ page }) => {+ await page.addInitScript(() => {+ window.__copiedText = "";+ const clipboard = {+ writeText: async (text) => {+ window.__copiedText = String(text || "");+ },+ };+ try {+ Object.defineProperty(navigator, "clipboard", {+ configurable: true,+ value: clipboard,+ });+ } catch (error) {+ navigator.clipboard = clipboard;+ }+ });++ await page.goto("/");+ await waitForApp(page);+ await createEvent(page, { title: `Clipboard-${Date.now()}`, allDay: true });++ await page.click("#copy-link");++ await expect.poll(() => page.evaluate(() => window.__copiedText)).toContain("#");+});++test("notification toggle requests permission and flips state", async ({ page }) => {+ await page.addInitScript(() => {+ window.__notifyRequestCount = 0;++ function MockNotification() {+ this.close = () => {};+ this.onclick = null;+ }++ MockNotification.permission = "default";+ MockNotification.requestPermission = async () => {+ window.__notifyRequestCount += 1;+ MockNotification.permission = "granted";+ return "granted";+ };++ window.Notification = MockNotification;+ });++ await page.goto("/");+ await waitForApp(page);+ await createEvent(page, { title: `Notify-${Date.now()}`, allDay: true });++ await page.click("#notify-toggle");+ await expect(page.locator("#notify-toggle")).toContainText(/On/i);+ await expect.poll(() => page.evaluate(() => window.__notifyRequestCount)).toBe(1);++ await page.click("#notify-toggle");+ await expect(page.locator("#notify-toggle")).toContainText(/Off/i);+ await expect.poll(() => page.evaluate(() => window.__notifyRequestCount)).toBe(1);+});diff --git a/tests/e2e/calendar.e2e.spec.js b/tests/e2e/calendar.e2e.spec.jsnew file mode 100644index 0000000..ea427cc--- /dev/null+++ b/tests/e2e/calendar.e2e.spec.js@@ -0,0 +1,328 @@+const { test, expect } = require("@playwright/test");+const { createEvent, getDateKeyOffset, waitForApp, waitForPersist } = require("./helpers.cjs");++test.beforeEach(async ({ page }) => {+ await page.goto("/");+ await waitForApp(page);+});++test("creates an event and restores it after reload", async ({ page }) => {+ const title = `E2E-${Date.now()}`;++ await createEvent(page, { title, allDay: true });+ await expect(page).toHaveURL(/#.+/);++ await page.reload();+ await waitForApp(page);+ await expect(page.locator("#event-list .event-title", { hasText: title })).toBeVisible();+});++test("edits and deletes an event", async ({ page }) => {+ const title = `EditMe-${Date.now()}`;+ const updated = `${title}-Updated`;++ await createEvent(page, { title, allDay: true });++ await page.locator("#event-list .event-item").first().click();+ await expect(page.locator("#event-modal")).toBeVisible();+ await expect(page.locator("#event-delete")).toBeVisible();++ await page.fill("#event-title", updated);+ await page.click("#event-save");+ await expect(page.locator("#event-list .event-title", { hasText: updated })).toBeVisible();++ await page.locator("#event-list .event-item").first().click();+ page.once("dialog", (dialog) => dialog.accept());+ await page.click("#event-delete");++ await expect(page.locator("#event-list .event-title", { hasText: updated })).toHaveCount(0);+});++test("clear calendar removes all events", async ({ page }) => {+ await createEvent(page, { title: `A-${Date.now()}`, allDay: true });+ await createEvent(page, { title: `B-${Date.now()}`, allDay: true });+ await expect(page.locator("#event-list .event-title")).toHaveCount(2);++ page.once("dialog", (dialog) => dialog.accept());+ await page.click("#clear-all");++ await expect(page.locator("#event-list .event-title")).toHaveCount(0);+});++test("daily recurring event appears on the next day", async ({ page }) => {+ const title = `Recurring-${Date.now()}`;++ await createEvent(page, { title, allDay: true, recurrence: "d" });++ const tomorrowKey = await getDateKeyOffset(page, 1);+ await page.click(`.day-cell[data-date="${tomorrowKey}"]`);++ await expect(page.locator("#event-list .event-title", { hasText: title })).toBeVisible();+});++test("read-only mode hides edit controls and persists", async ({ page }) => {+ await page.click("#readonly-btn");+ await expect(page.locator("#readonly-btn")).toHaveAttribute("aria-pressed", "true");+ await expect(page.locator("#add-event")).toBeHidden();+ await expect(page.locator("#share-export-section")).toBeHidden();+ await expect(page.locator("#danger-zone-section")).toBeHidden();++ await waitForPersist(page);+ await page.reload();+ await waitForApp(page);++ await expect(page.locator("#readonly-btn")).toHaveAttribute("aria-pressed", "true");+ await expect(page.locator("#add-event")).toBeHidden();+});++test("theme toggle persists after reload", async ({ page }) => {+ await createEvent(page, { title: `ThemeSeed-${Date.now()}`, allDay: true });+ await expect(page.locator("body")).toHaveAttribute("data-theme", "light");++ await page.click("#theme-toggle");+ await expect(page.locator("body")).toHaveAttribute("data-theme", "dark");++ await waitForPersist(page);+ await page.reload();+ await waitForApp(page);+ await expect(page.locator("body")).toHaveAttribute("data-theme", "dark");+});++test("week start setting persists after reload", async ({ page }) => {+ await createEvent(page, { title: `WeekSeed-${Date.now()}`, allDay: true });+ await page.click("#weekstart-toggle");+ await expect(page.locator("#weekstart-toggle")).toContainText(/Monday/i);++ await waitForPersist(page);+ await page.reload();+ await waitForApp(page);+ await expect(page.locator("#weekstart-toggle")).toContainText(/Monday/i);+});++test("language selection persists after reload", async ({ page }) => {+ await createEvent(page, { title: `LangSeed-${Date.now()}`, allDay: true });+ await page.click("#language-btn");+ await page.click('#language-list .dropdown-item[data-lang="it"]');++ await expect(page.locator("html")).toHaveAttribute("lang", "it");+ await expect(page.locator("body")).toHaveAttribute("lang", "it");++ await waitForPersist(page);+ await page.reload();+ await waitForApp(page);+ await expect(page.locator("html")).toHaveAttribute("lang", "it");+});++test("view switching and timeline controls work", async ({ page }) => {+ const grid = page.locator("#calendar-grid");++ await page.click('.view-toggle button[data-view="week"]');+ await expect(grid).toHaveClass(/week-view/);++ await page.click('.view-toggle button[data-view="day"]');+ await expect(grid).toHaveClass(/day-view/);++ await page.click('.view-toggle button[data-view="agenda"]');+ await expect(grid).toHaveClass(/agenda-view/);++ await page.click('.view-toggle button[data-view="year"]');+ await expect(grid).toHaveClass(/year-view/);++ await page.click('.view-toggle button[data-view="timeline"]');+ await expect(grid).toHaveClass(/timeline-view/);+ await expect(page.locator("#timeline-controls")).toBeVisible();++ const beforeZoom = (await page.locator("#timeline-zoom-value").innerText()).trim();+ await page.click("#timeline-zoom-in");+ await expect.poll(async () => (await page.locator("#timeline-zoom-value").innerText()).trim()).not.toBe(beforeZoom);++ await page.click('.view-toggle button[data-view="month"]');+ await expect(grid).toHaveClass(/month-view/);+ await expect(page.locator("#timeline-controls")).toBeHidden();+});++test("focus mode opens and closes with Escape", async ({ page }) => {+ await page.click("#focus-btn");+ await expect(page.locator("#focus-overlay")).toHaveClass(/is-active/);+ await expect(page.locator("#focus-overlay")).toHaveAttribute("aria-hidden", "false");++ await page.keyboard.press("Escape");+ await expect(page.locator("#focus-overlay")).not.toHaveClass(/is-active/);+ await expect(page.locator("#focus-overlay")).toHaveAttribute("aria-hidden", "true");+});++test("timezone modal can add and remove a timezone", async ({ page }) => {+ await page.click("#add-tz-btn");+ await page.fill("#tz-search", "london");++ let option = page.locator('#tz-results button[data-zone="Europe/London"]');+ if ((await option.count()) === 0) {+ option = page.locator("#tz-results button", { hasText: /London/i }).first();+ }++ await expect(option).toBeVisible();+ const zone = await option.getAttribute("data-zone");+ await option.click();++ await expect(page.locator("#tz-list")).toContainText(/London/i);++ if (zone) {+ const removeButton = page.locator(`#tz-list button[data-zone="${zone}"]`);+ await expect(removeButton).toBeVisible();+ await removeButton.click();+ await expect(removeButton).toHaveCount(0);+ } else {+ const removeFallback = page.locator("#tz-list .tz-remove").first();+ await removeFallback.click();+ await expect(page.locator("#tz-list")).not.toContainText(/London/i);+ }+});++test("world planner supports zone add/remove and time format toggle", async ({ page }) => {+ await page.click("#world-planner-btn");+ await expect(page.locator("#world-planner-modal")).toBeVisible();+ await expect.poll(async () => await page.locator("#wp-grid .wp-row-header").count()).toBeGreaterThan(0);++ await page.fill("#wp-add-zone", "tokyo");+ const tokyoOption = page.locator("#wp-tz-results button", { hasText: /Tokyo/i }).first();+ await expect(tokyoOption).toBeVisible();+ await tokyoOption.click();++ await expect(page.locator("#wp-grid")).toContainText(/Tokyo/i);++ await page.click("#wp-format-toggle");+ await expect(page.locator("#wp-format-toggle")).toHaveText("24h");++ const tokyoRow = page.locator('#wp-grid .wp-row-header:has(.wp-city-name:has-text("Tokyo"))').first();+ await tokyoRow.hover();+ const removeButton = tokyoRow.locator('.wp-control-btn[data-action="remove"]');+ await removeButton.click();+ await expect(page.locator("#wp-grid .wp-city-name", { hasText: /Tokyo/i })).toHaveCount(0);++ await page.click("#wp-close");+ await expect(page.locator("#world-planner-modal")).toBeHidden();+});++test("template gallery loads cards", async ({ page }) => {+ await page.click("#open-template-gallery");+ await expect(page.locator("#template-modal")).toBeVisible();++ await expect.poll(async () => await page.locator("#template-links .template-card").count()).toBeGreaterThan(0);++ await page.click("#template-close");+ await expect(page.locator("#template-modal")).toBeHidden();+});++test("json modal displays serialized state and hash", async ({ page }) => {+ const title = `Json-${Date.now()}`;+ await createEvent(page, { title, allDay: true });+ await waitForPersist(page);++ await page.click("#view-json");+ await expect(page.locator("#json-modal")).toBeVisible();++ const json = await page.locator("#json-output").inputValue();+ const hash = await page.locator("#json-hash").inputValue();++ expect(json).toContain(title);+ expect(hash.startsWith("#")).toBeTruthy();++ await page.click("#json-close");+ await expect(page.locator("#json-modal")).toBeHidden();+});++test("lock and unlock flow restores encrypted calendar data", async ({ page }) => {+ test.setTimeout(60_000);+ const title = `Locked-${Date.now()}`;+ const password = "e2e-password-123";++ await createEvent(page, { title, allDay: true });++ await page.click("#lock-btn");+ await expect(page.locator("#password-modal")).toBeVisible();+ await page.fill("#password-input", password);+ await page.fill("#password-confirm", password);+ await page.click("#password-submit");++ await expect.poll(() => page.url()).toContain("#ENC:");++ await page.reload();+ await waitForApp(page);+ await expect(page.locator("#locked-overlay")).toBeVisible();++ await expect(page.locator("#password-modal")).toBeVisible();+ await page.fill("#password-input", password);+ await page.click("#password-submit");++ await expect(page.locator("#locked-overlay")).toBeHidden();+ await expect(page.locator("#event-list .event-title", { hasText: title })).toBeVisible();+});++test("imports events from .ics file", async ({ page }) => {+ const title = `ICS-${Date.now()}`;+ const dates = await page.evaluate(() => {+ const toYmd = (d) => {+ const yyyy = d.getFullYear();+ const mm = String(d.getMonth() + 1).padStart(2, "0");+ const dd = String(d.getDate()).padStart(2, "0");+ return `${yyyy}${mm}${dd}`;+ };++ const start = new Date();+ const end = new Date(start.getTime());+ end.setDate(end.getDate() + 1);++ return { start: toYmd(start), end: toYmd(end) };+ });++ const ics = [+ "BEGIN:VCALENDAR",+ "VERSION:2.0",+ "BEGIN:VEVENT",+ `SUMMARY:${title}`,+ `DTSTART;VALUE=DATE:${dates.start}`,+ `DTEND;VALUE=DATE:${dates.end}`,+ "END:VEVENT",+ "END:VCALENDAR",+ "",+ ].join("\n");++ await page.setInputFiles("#ics-input", {+ name: "import.ics",+ mimeType: "text/calendar",+ buffer: Buffer.from(ics),+ });++ await expect(page.locator("#event-list .event-title", { hasText: title })).toBeVisible();+});++test("imports a hash-path event once and rewrites the hash", async ({ page }) => {+ const today = await page.evaluate(() => {+ const d = new Date();+ return {+ year: d.getFullYear(),+ month: d.getMonth() + 1,+ day: d.getDate(),+ };+ });+ const title = `PathEvent${Date.now()}`;++ await page.goto(`/#/${today.year}/${today.month}/${today.day}/10/30/${title}`);+ await waitForApp(page);++ await expect(page.locator("#event-list .event-title", { hasText: title })).toBeVisible();+ await expect.poll(() => page.url()).not.toContain("#/");++ await page.reload();+ await waitForApp(page);+ await expect(page.locator("#event-list .event-title", { hasText: title })).toHaveCount(1);+});++test("app launcher modal opens and closes", async ({ page }) => {+ await page.click("#app-launcher-btn");+ await expect(page.locator("#app-launcher-modal")).toBeVisible();+ await expect(page.locator("#app-launcher-iframe")).toHaveAttribute("src", /open-edit\.netlify\.app/);++ await page.click("#app-launcher-close");+ await expect(page.locator("#app-launcher-modal")).toBeHidden();+});diff --git a/tests/e2e/helpers.cjs b/tests/e2e/helpers.cjsnew file mode 100644index 0000000..97a3e27--- /dev/null+++ b/tests/e2e/helpers.cjs@@ -0,0 +1,74 @@+const { expect } = require("@playwright/test");++async function waitForApp(page, { requireEventList = true } = {}) {+ await expect(page.locator("#calendar-grid")).toBeVisible();+ if (requireEventList) {+ await expect(page.locator("#event-list")).toBeVisible();+ }+}++async function waitForPersist(page, ms = 800) {+ await page.waitForTimeout(ms);+}++async function getDateKeyOffset(page, offsetDays = 0) {+ return page.evaluate((offset) => {+ const target = new Date();+ target.setDate(target.getDate() + offset);+ const yyyy = target.getFullYear();+ const mm = String(target.getMonth() + 1).padStart(2, "0");+ const dd = String(target.getDate()).padStart(2, "0");+ return `${yyyy}-${mm}-${dd}`;+ }, offsetDays);+}++async function createEvent(+ page,+ {+ title,+ allDay = true,+ recurrence = "",+ dateKey = null,+ startTime = "09:00",+ endTime = "10:00",+ triggerSelector = "#add-event",+ } = {}+) {+ await page.click(triggerSelector);+ await expect(page.locator("#event-modal")).toBeVisible();++ if (title) {+ await page.fill("#event-title", title);+ }++ if (dateKey) {+ await page.fill("#event-date", dateKey);+ await page.fill("#event-end-date", dateKey);+ }++ if (allDay) {+ await page.check("#event-all-day");+ } else {+ await page.uncheck("#event-all-day");+ await page.fill("#event-time", startTime);+ await page.fill("#event-end-time", endTime);+ }++ if (recurrence) {+ await page.selectOption("#event-recurrence", recurrence);+ }++ await page.click("#event-save");+ await expect(page.locator("#event-modal")).toBeHidden();++ if (title) {+ await expect(page.locator("#event-list .event-title", { hasText: title })).toBeVisible();+ }+}++module.exports = {+ createEvent,+ getDateKeyOffset,+ waitForApp,+ waitForPersist,+};diff --git a/tests/e2e/mobile.mobile.e2e.spec.js b/tests/e2e/mobile.mobile.e2e.spec.jsnew file mode 100644index 0000000..d2075d9--- /dev/null+++ b/tests/e2e/mobile.mobile.e2e.spec.js@@ -0,0 +1,66 @@+const { test, expect } = require("@playwright/test");+const { waitForApp, createEvent, waitForPersist } = require("./helpers.cjs");++test.beforeEach(async ({ page }) => {+ await page.goto("/");+ await waitForApp(page, { requireEventList: false });+});++test("mobile drawer opens and switches calendar view", async ({ page }) => {+ await page.click("#hamburger-btn");+ await expect(page.locator("#mobile-drawer")).toHaveClass(/is-active/);++ await page.click('#mobile-drawer [data-view="week"]');+ await expect(page.locator("#mobile-drawer")).not.toHaveClass(/is-active/);+ await expect(page.locator("#calendar-grid")).toHaveClass(/week-view/);+});++test("mobile quick add event flow works", async ({ page }) => {+ const title = `Mobile-${Date.now()}`;++ await page.click("#mobile-add-event");+ await expect(page.locator("#event-modal")).toBeVisible();+ await page.fill("#event-title", title);+ await page.check("#event-all-day");+ await page.click("#event-save");++ await page.click("#hamburger-btn");+ await expect(page.locator("#mobile-drawer")).toHaveClass(/is-active/);+ await expect(page.locator("#mobile-event-list .event-title", { hasText: title })).toBeVisible();+});++test("mobile drawer opens template and json modals", async ({ page }) => {+ await page.click("#hamburger-btn");+ await page.click("#mobile-open-template-gallery");+ await expect(page.locator("#template-modal")).toBeVisible();+ await page.click("#template-close");+ await expect(page.locator("#template-modal")).toBeHidden();++ await page.click("#hamburger-btn");+ await page.click("#mobile-view-json");+ await expect(page.locator("#json-modal")).toBeVisible();+ await page.click("#json-close");+ await expect(page.locator("#json-modal")).toBeHidden();+});++test("mobile read-only toggle hides quick add and persists", async ({ page }) => {+ await createEvent(page, { title: `MobileSeed-${Date.now()}`, allDay: true, triggerSelector: "#mobile-add-event" });++ await page.click("#hamburger-btn");+ await page.click("#mobile-readonly-btn");++ await expect(page.locator("#mobile-add-event")).toBeHidden();+ await waitForPersist(page);++ await page.reload();+ await waitForApp(page, { requireEventList: false });+ await expect(page.locator("#mobile-add-event")).toBeHidden();+});++test("mobile drawer opens world planner", async ({ page }) => {+ await page.click("#hamburger-btn");+ await page.click("#mobile-world-planner-btn");+ await expect(page.locator("#world-planner-modal")).toBeVisible();+ await page.click("#wp-close");+ await expect(page.locator("#world-planner-modal")).toBeHidden();+});diff --git a/tests/e2e/smoke.cross.e2e.spec.js b/tests/e2e/smoke.cross.e2e.spec.jsnew file mode 100644index 0000000..b5d23ba--- /dev/null+++ b/tests/e2e/smoke.cross.e2e.spec.js@@ -0,0 +1,25 @@+const { test, expect } = require("@playwright/test");+const { waitForApp, createEvent } = require("./helpers.cjs");++test.beforeEach(async ({ page }) => {+ await page.goto("/");+ await waitForApp(page, { requireEventList: false });+});++test("core app shell renders and navigation works", async ({ page }) => {+ await expect(page.locator("#month-label")).toBeVisible();+ const before = (await page.locator("#month-label").innerText()).trim();++ await page.click("#next-month");+ const after = (await page.locator("#month-label").innerText()).trim();+ expect(after).not.toBe(before);++ await page.click("#today-btn");+ await expect(page.locator("#calendar-grid")).toHaveClass(/month-view/);+});++test("can create a basic all-day event", async ({ page }) => {+ const title = `Smoke-${Date.now()}`;+ await createEvent(page, { title, allDay: true });+ await expect(page.locator("#event-list .event-title", { hasText: title })).toBeVisible();+});diff --git a/tests/e2e/static-server.cjs b/tests/e2e/static-server.cjsnew file mode 100644index 0000000..e29aa40--- /dev/null+++ b/tests/e2e/static-server.cjs@@ -0,0 +1,80 @@+const http = require("http");+const fs = require("fs/promises");+const path = require("path");+const { URL } = require("url");++const ROOT = path.resolve(__dirname, "..", "..");+const PORT = Number(process.argv[2] || process.env.PORT || 4173);++const MIME_TYPES = {+ ".css": "text/css; charset=utf-8",+ ".html": "text/html; charset=utf-8",+ ".ico": "image/x-icon",+ ".jpg": "image/jpeg",+ ".jpeg": "image/jpeg",+ ".js": "text/javascript; charset=utf-8",+ ".json": "application/json; charset=utf-8",+ ".md": "text/markdown; charset=utf-8",+ ".png": "image/png",+ ".svg": "image/svg+xml",+ ".txt": "text/plain; charset=utf-8",+ ".webmanifest": "application/manifest+json; charset=utf-8",+ ".xml": "application/xml; charset=utf-8",+};++function getContentType(filePath) {+ const ext = path.extname(filePath).toLowerCase();+ return MIME_TYPES[ext] || "application/octet-stream";+}++function resolveFilePath(requestUrl) {+ const parsed = new URL(requestUrl, `http://127.0.0.1:${PORT}`);+ let pathname = decodeURIComponent(parsed.pathname);+ if (pathname === "/") pathname = "/index.html";+ if (pathname.endsWith("/")) pathname += "index.html";++ const candidate = path.resolve(ROOT, `.${pathname}`);+ const relative = path.relative(ROOT, candidate);+ if (relative.startsWith("..") || path.isAbsolute(relative)) {+ return null;+ }+ return candidate;+}++async function tryReadFile(filePath) {+ try {+ const stat = await fs.stat(filePath);+ if (stat.isDirectory()) {+ return await fs.readFile(path.join(filePath, "index.html"));+ }+ return await fs.readFile(filePath);+ } catch {+ return null;+ }+}++const server = http.createServer(async (req, res) => {+ const filePath = resolveFilePath(req.url || "/");+ if (!filePath) {+ res.writeHead(400, { "content-type": "text/plain; charset=utf-8" });+ res.end("Bad request");+ return;+ }++ const data = await tryReadFile(filePath);+ if (!data) {+ res.writeHead(404, { "content-type": "text/plain; charset=utf-8" });+ res.end("Not found");+ return;+ }++ res.writeHead(200, {+ "cache-control": "no-store",+ "content-type": getContentType(filePath),+ });+ res.end(data);+});++server.listen(PORT, "127.0.0.1", () => {+ console.log(`Static server running at http://127.0.0.1:${PORT}`);+});