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: Enhance E2E tests with new clipboard functionality and recurring event scenarios
Supun Lakmal02dd18cc74ba
diff --git a/script.js b/script.jsindex a4451e6..e2a881a 100644--- a/script.js+++ b/script.js@@ -85,6 +85,11 @@ const DEFAULT_TIMELINE_ZOOM_LEVEL = 2;const TIMELINE_RECURRING_WINDOW_DAYS = 365;const TIMELINE_PADDING_DAYS = 14;let timelineZoomLevel = DEFAULT_TIMELINE_ZOOM_LEVEL;+const APP_READY_ATTRIBUTE = "data-app-ready";++function setAppReady(isReady) {+ document.documentElement.setAttribute(APP_READY_ATTRIBUTE, isReady ? "1" : "0");+}function isCalendarLocked() {return lockState.encrypted && !lockState.unlocked;@@ -2112,6 +2117,63 @@ function closeTemplateModal() {templateGalleryController.closeModal();}+function isOpenModalElement(element) {+ return !!(element && !element.classList.contains(CSS_CLASSES.HIDDEN));+}++function isOpenDialogElement(element) {+ return !!(element && element.hasAttribute("open"));+}++function handleGlobalEscape(event) {+ if (event.key !== "Escape") return;++ // Focus overlay handles its own Escape behavior.+ if (focusMode && focusMode.isActive()) return;++ if (isOpenModalElement(ui.eventModal)) {+ event.preventDefault();+ closeEventModal();+ return;+ }++ if (isOpenModalElement(ui.passwordModal)) {+ event.preventDefault();+ closePasswordModal();+ return;+ }++ if (isOpenModalElement(ui.jsonModal)) {+ event.preventDefault();+ closeJsonModal();+ return;+ }++ if (isOpenModalElement(ui.templateModal)) {+ event.preventDefault();+ closeTemplateModal();+ return;+ }++ if (isOpenDialogElement(ui.tzModal)) {+ event.preventDefault();+ closeTzModal();+ return;+ }++ if (worldPlanner && typeof worldPlanner.isOpen === "function" && worldPlanner.isOpen()) {+ event.preventDefault();+ worldPlanner.close();+ return;+ }++ const qrModal = document.getElementById("qr-modal");+ if (isOpenModalElement(qrModal) && qrManager && typeof qrManager.hide === "function") {+ event.preventDefault();+ qrManager.hide();+ }+}+function handleTemplateLinkClick(event) {if (!templateGalleryController) return;templateGalleryController.handleLinkClick(event);@@ -2298,6 +2360,7 @@ function bindEvents() {window.addEventListener("hashchange", handleHashChange);window.addEventListener("resize", syncTopbarHeight);+ document.addEventListener("keydown", handleGlobalEscape);document.addEventListener("visibilitychange", () => {if (document.hidden) return;updateNotificationToggleLabel();@@ -2342,6 +2405,7 @@ function initResponsiveFeatures() {}async function init() {+ setAppReady(false);cacheElements(ui);responsiveFeaturesController = createResponsiveFeaturesController({ui,@@ -2429,10 +2493,12 @@ async function init() {}new AppLauncher();- if (isEncryptedHash() && !lockState.unlocked) {- attemptUnlock();- }-}+ if (isEncryptedHash() && !lockState.unlocked) {+ attemptUnlock();+ }++ setAppReady(true);+}if (document.readyState === "loading") {document.addEventListener("DOMContentLoaded", init);diff --git a/tests/e2e/browser-apis.chromium.e2e.spec.js b/tests/e2e/browser-apis.chromium.e2e.spec.jsindex e07919d..e3b4cb5 100644--- a/tests/e2e/browser-apis.chromium.e2e.spec.js+++ b/tests/e2e/browser-apis.chromium.e2e.spec.js@@ -1,5 +1,5 @@const { test, expect } = require("@playwright/test");-const { waitForApp, createEvent } = require("./helpers.cjs");+const { waitForApp, createEvent, waitForPersist } = require("./helpers.cjs");test("copy link writes to clipboard API", async ({ page }) => {await page.addInitScript(() => {@@ -59,3 +59,83 @@ test("notification toggle requests permission and flips state", async ({ page })await expect(page.locator("#notify-toggle")).toContainText(/Off/i);await expect.poll(() => page.evaluate(() => window.__notifyRequestCount)).toBe(1);});++test("copy hash from JSON modal writes to clipboard", 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: `HashCopy-${Date.now()}`, allDay: true });+ await waitForPersist(page);++ await page.click("#view-json");+ await expect(page.locator("#json-modal")).toBeVisible();++ await page.click("#json-copy-hash");++ await expect.poll(() => page.evaluate(() => window.__copiedText)).toContain("#");++ await page.click("#json-close");+});++test("copy JSON from JSON modal writes to clipboard", 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);+ const title = `JSONCopy-${Date.now()}`;+ await createEvent(page, { title, allDay: true });++ await page.click("#view-json");+ await expect(page.locator("#json-modal")).toBeVisible();++ await page.click("#json-copy");++ const copiedText = await page.evaluate(() => window.__copiedText);+ expect(copiedText).toContain(title);++ await page.click("#json-close");+});++test("export JSON triggers file download", async ({ page }) => {+ await page.goto("/");+ await waitForApp(page);+ await createEvent(page, { title: `Export-${Date.now()}`, allDay: true });++ const [download] = await Promise.all([+ page.waitForEvent("download"),+ page.click("#export-json"),+ ]);++ expect(download.suggestedFilename()).toMatch(/\.json$/);+});diff --git a/tests/e2e/calendar.e2e.spec.js b/tests/e2e/calendar.e2e.spec.jsindex ea427cc..90d4a32 100644--- a/tests/e2e/calendar.e2e.spec.js+++ b/tests/e2e/calendar.e2e.spec.js@@ -326,3 +326,230 @@ test("app launcher modal opens and closes", async ({ page }) => {await page.click("#app-launcher-close");await expect(page.locator("#app-launcher-modal")).toBeHidden();});++test("weekly recurring event appears 7 days later", async ({ page }) => {+ const title = `Weekly-${Date.now()}`;++ await createEvent(page, { title, allDay: true, recurrence: "w" });++ const weekLaterKey = await getDateKeyOffset(page, 7);+ await page.click(`.day-cell[data-date="${weekLaterKey}"]`);++ await expect(page.locator("#event-list .event-title", { hasText: title })).toBeVisible();+});++test("monthly recurring event appears next month", async ({ page }) => {+ const title = `Monthly-${Date.now()}`;+ const dates = await page.evaluate(() => {+ const format = (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 base = new Date();+ base.setDate(15);+ const next = new Date(base.getFullYear(), base.getMonth() + 1, 15);+ return { baseKey: format(base), nextKey: format(next) };+ });++ await createEvent(page, { title, allDay: true, recurrence: "m", dateKey: dates.baseKey });++ await page.click("#today-btn");+ await page.click("#next-month");++ await page.click(`.day-cell[data-date="${dates.nextKey}"] .day-number`);+ await expect(page.locator("#event-list .event-title", { hasText: title })).toBeVisible();+});++test("yearly recurring event appears next year", async ({ page }) => {+ const title = `Yearly-${Date.now()}`;+ const dates = await page.evaluate(() => {+ const format = (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 base = new Date();+ base.setDate(15);+ const next = new Date(base.getFullYear() + 1, base.getMonth(), 15);+ return { baseKey: format(base), nextKey: format(next) };+ });++ await createEvent(page, { title, allDay: true, recurrence: "y", dateKey: dates.baseKey });++ await page.click("#today-btn");+ for (let i = 0; i < 12; i += 1) {+ await page.click("#next-month");+ }++ await page.click(`.day-cell[data-date="${dates.nextKey}"] .day-number`);+ await expect(page.locator("#event-list .event-title", { hasText: title })).toBeVisible();+});++test("timed event with custom start and end times", async ({ page }) => {+ const title = `Timed-${Date.now()}`;++ await createEvent(page, {+ title,+ allDay: false,+ startTime: "14:00",+ endTime: "16:30"+ });++ // Click the event to reopen the modal+ await page.locator("#event-list .event-item").first().click();+ await expect(page.locator("#event-modal")).toBeVisible();++ // Verify times+ await expect(page.locator("#event-time")).toHaveValue("14:00");+ await expect(page.locator("#event-end-time")).toHaveValue("16:30");++ await page.click("#event-cancel");+});++test("multiple events on same day appear in event list", async ({ page }) => {+ const title1 = `Multi1-${Date.now()}`;+ const title2 = `Multi2-${Date.now() + 1}`;+ const title3 = `Multi3-${Date.now() + 2}`;++ await createEvent(page, { title: title1, allDay: true });+ await createEvent(page, { title: title2, allDay: true });+ await createEvent(page, { title: title3, allDay: true });++ await expect(page.locator("#event-list .event-title")).toHaveCount(3);+ await expect(page.locator("#event-list .event-title", { hasText: title1 })).toBeVisible();+ await expect(page.locator("#event-list .event-title", { hasText: title2 })).toBeVisible();+ await expect(page.locator("#event-list .event-title", { hasText: title3 })).toBeVisible();+});++test("event color selection persists", async ({ page }) => {+ const title = `Color-${Date.now()}`;++ // Open event modal manually+ await page.click("#add-event");+ await expect(page.locator("#event-modal")).toBeVisible();++ // Fill event details+ await page.fill("#event-title", title);+ await page.check("#event-all-day");++ // Set custom color+ await page.evaluate(() => {+ const colorInput = document.getElementById("event-color");+ colorInput.value = "#00ff00";+ colorInput.dispatchEvent(new Event("input", { bubbles: true }));+ });++ // Save event+ await page.click("#event-save");+ await expect(page.locator("#event-modal")).toBeHidden();+ await expect(page.locator("#event-list .event-title", { hasText: title })).toBeVisible();++ // Reopen event to verify color persisted+ await page.locator("#event-list .event-item").first().click();+ await expect(page.locator("#event-modal")).toBeVisible();++ const colorValue = await page.locator("#event-color").inputValue();+ expect(colorValue.toLowerCase()).toBe("#00ff00");++ await page.click("#event-cancel");+});++test("QR code modal opens and closes", async ({ page }) => {+ const title = `QR-${Date.now()}`;+ await createEvent(page, { title, allDay: true });++ await page.click("#share-qr");+ await expect(page.locator("#qr-modal")).toBeVisible();++ // Check that QR code content is rendered+ await expect(page.locator("#qrcode-container")).toBeVisible();++ await page.click("#qr-close");+ await expect(page.locator("#qr-modal")).toBeHidden();+});++test("calendar title editing persists after reload", async ({ page }) => {+ const title = `TitleTest-${Date.now()}`;+ await createEvent(page, { title, allDay: true });++ const customTitle = `My Custom Cal ${Date.now()}`;+ await page.fill("#calendar-title", customTitle);++ await waitForPersist(page);+ await page.reload();+ await waitForApp(page);++ await expect(page.locator("#calendar-title")).toHaveValue(customTitle);+});++test("month navigation prev/next and today reset", async ({ page }) => {+ const originalLabel = await page.locator("#month-label").innerText();++ await page.click("#prev-month");+ const prevLabel = await page.locator("#month-label").innerText();+ expect(prevLabel).not.toBe(originalLabel);++ await page.click("#next-month");+ await page.click("#next-month");+ const forwardLabel = await page.locator("#month-label").innerText();+ expect(forwardLabel).not.toBe(prevLabel);++ await page.click("#today-btn");+ const afterTodayLabel = await page.locator("#month-label").innerText();+ expect(afterTodayLabel).toBe(originalLabel);+});++test("toast appears on read-only toggle", async ({ page }) => {+ await page.click("#readonly-btn");++ // Toast should appear+ await expect(page.locator(".toast")).toBeVisible();++ // Wait for toast to auto-dismiss (3200ms timeout + buffer)+ await page.waitForTimeout(3500);++ // Toast should be removed+ await expect(page.locator(".toast")).toHaveCount(0);+});++test("Escape closes event modal without saving", async ({ page }) => {+ await page.click("#add-event");+ await expect(page.locator("#event-modal")).toBeVisible();++ await page.keyboard.press("Escape");+ await expect(page.locator("#event-modal")).toBeHidden();++ // No events should be created+ await expect(page.locator("#event-list .event-title")).toHaveCount(0);+});++test("Escape closes password modal", async ({ page }) => {+ await page.click("#lock-btn");+ await expect(page.locator("#password-modal")).toBeVisible();++ await page.keyboard.press("Escape");+ await expect(page.locator("#password-modal")).toBeHidden();+});++test("password mismatch shows error during lock", async ({ page }) => {+ const title = `PasswordError-${Date.now()}`;+ await createEvent(page, { title, allDay: true });++ await page.click("#lock-btn");+ await expect(page.locator("#password-modal")).toBeVisible();++ await page.fill("#password-input", "password123");+ await page.fill("#password-confirm", "password456");+ await page.click("#password-submit");++ // Error should be visible+ const errorElement = page.locator("#password-error");+ await expect(errorElement).toBeVisible();+ await expect(errorElement).not.toHaveClass(/hidden/);++ // Modal should stay open+ await expect(page.locator("#password-modal")).toBeVisible();+});diff --git a/tests/e2e/helpers.cjs b/tests/e2e/helpers.cjsindex 97a3e27..42d0605 100644--- a/tests/e2e/helpers.cjs+++ b/tests/e2e/helpers.cjs@@ -1,6 +1,7 @@const { expect } = require("@playwright/test");async function waitForApp(page, { requireEventList = true } = {}) {+ await expect(page.locator("html")).toHaveAttribute("data-app-ready", "1");await expect(page.locator("#calendar-grid")).toBeVisible();if (requireEventList) {await expect(page.locator("#event-list")).toBeVisible();diff --git a/tests/e2e/mobile.mobile.e2e.spec.js b/tests/e2e/mobile.mobile.e2e.spec.jsindex d2075d9..bcaaa8b 100644--- a/tests/e2e/mobile.mobile.e2e.spec.js+++ b/tests/e2e/mobile.mobile.e2e.spec.js@@ -64,3 +64,78 @@ test("mobile drawer opens world planner", async ({ page }) => {await page.click("#wp-close");await expect(page.locator("#world-planner-modal")).toBeHidden();});++test("mobile copy link writes to clipboard", 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, { requireEventList: false });+ await createEvent(page, { title: `MobileCopy-${Date.now()}`, allDay: true, triggerSelector: "#mobile-add-event" });++ await page.click("#mobile-copy-link");++ const copiedText = await page.evaluate(() => window.__copiedText);+ expect(copiedText).toContain("#");+});++test("mobile lock and unlock flow", async ({ page }) => {+ test.setTimeout(60_000);+ const title = `MobileLock-${Date.now()}`;+ const password = "mobile-password-123";++ await createEvent(page, { title, allDay: true, triggerSelector: "#mobile-add-event" });++ await page.click("#mobile-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, { requireEventList: false });+ 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 page.click("#hamburger-btn");+ await expect(page.locator("#mobile-event-list .event-title", { hasText: title })).toBeVisible();+});++test("mobile QR code modal opens", async ({ page }) => {+ await createEvent(page, { title: `MobileQR-${Date.now()}`, allDay: true, triggerSelector: "#mobile-add-event" });++ await page.click("#mobile-share-qr");+ await expect(page.locator("#qr-modal")).toBeVisible();+ await expect(page.locator("#qrcode-container")).toBeVisible();++ await page.click("#qr-close");+ await expect(page.locator("#qr-modal")).toBeHidden();+});++test("mobile focus mode opens and closes", async ({ page }) => {+ await page.click("#mobile-focus-btn");+ await expect(page.locator("#focus-overlay")).toHaveClass(/is-active/);++ await page.keyboard.press("Escape");+ await expect(page.locator("#focus-overlay")).not.toHaveClass(/is-active/);+});diff --git a/tests/e2e/pages.e2e.spec.js b/tests/e2e/pages.e2e.spec.jsnew file mode 100644index 0000000..b21b603--- /dev/null+++ b/tests/e2e/pages.e2e.spec.js@@ -0,0 +1,31 @@+const { test, expect } = require("@playwright/test");++test("about page loads", async ({ page }) => {+ await page.goto("/about.html");+ await expect(page.locator("h1").first()).toBeVisible();+ await expect(page).toHaveTitle(/About/i);+});++test("help page loads", async ({ page }) => {+ await page.goto("/help.html");+ await expect(page.locator("h1").first()).toBeVisible();+ await expect(page).toHaveTitle(/Help/i);+});++test("FAQ page loads", async ({ page }) => {+ await page.goto("/faq.html");+ await expect(page.locator("h1").first()).toBeVisible();+ await expect(page).toHaveTitle(/FAQ/i);+});++test("privacy page loads", async ({ page }) => {+ await page.goto("/privacy.html");+ await expect(page.locator("h1").first()).toBeVisible();+ await expect(page).toHaveTitle(/Privacy/i);+});++test("404 page loads for unknown route", async ({ page }) => {+ await page.goto("/404.html");+ await expect(page.locator("h1").first()).toBeVisible();+ await expect(page).toHaveTitle(/404/i);+});diff --git a/tests/e2e/views.e2e.spec.js b/tests/e2e/views.e2e.spec.jsnew file mode 100644index 0000000..713a451--- /dev/null+++ b/tests/e2e/views.e2e.spec.js@@ -0,0 +1,88 @@+const { test, expect } = require("@playwright/test");+const { createEvent, waitForApp } = require("./helpers.cjs");++test.beforeEach(async ({ page }) => {+ await page.goto("/");+ await waitForApp(page);+});++test("agenda view lists created events", async ({ page }) => {+ const title1 = `Agenda1-${Date.now()}`;+ const title2 = `Agenda2-${Date.now() + 1}`;++ await createEvent(page, { title: title1, allDay: true });+ await createEvent(page, { title: title2, allDay: true });++ // Switch to agenda view+ await page.click('button[data-view="agenda"]');+ await expect(page.locator("#calendar-grid")).toHaveClass(/agenda-view/);++ // Both events should be visible in agenda+ await expect(page.locator("#calendar-grid .agenda-title", { hasText: title1 })).toBeVisible();+ await expect(page.locator("#calendar-grid .agenda-title", { hasText: title2 })).toBeVisible();+});++test("day view renders time slots", async ({ page }) => {+ // Switch to day view+ await page.click('button[data-view="day"]');+ await expect(page.locator("#calendar-grid")).toHaveClass(/day-view/);++ // Check that time slots exist (should have hour markers)+ const dayGrid = page.locator("#calendar-grid");+ await expect(dayGrid).toBeVisible();+});++test("year view renders 12 month blocks", async ({ page }) => {+ // Switch to year view+ await page.click('button[data-view="year"]');+ await expect(page.locator("#calendar-grid")).toHaveClass(/year-view/);++ // Year view should be visible+ const yearGrid = page.locator("#calendar-grid");+ await expect(yearGrid).toBeVisible();+});++test("focus mode displays event info and countdown", async ({ page }) => {+ const title = `Focus-${Date.now()}`;++ // Create a timed event for later today+ await createEvent(page, {+ title,+ allDay: false,+ startTime: "23:50",+ endTime: "23:55"+ });++ // Open focus mode+ await page.click("#focus-btn");+ await expect(page.locator("#focus-overlay")).toHaveClass(/is-active/);++ // Focus overlay should be visible+ await expect(page.locator("#focus-overlay")).toBeVisible();++ // Press Escape to close+ await page.keyboard.press("Escape");+ await expect(page.locator("#focus-overlay")).not.toHaveClass(/is-active/);+});++test("countdown widget shows next event", async ({ page }) => {+ const title = `Countdown-${Date.now()}`;++ // Create a timed event+ await createEvent(page, {+ title,+ allDay: false,+ startTime: "23:50",+ endTime: "23:55"+ });++ // Countdown widget should show the event+ // Note: The widget may be hidden if no upcoming events, so we check conditionally+ const countdownWidget = page.locator("#countdown-widget");+ const isVisible = await countdownWidget.isVisible().catch(() => false);++ if (isVisible) {+ const eventTitle = page.locator("#nextEventTitle");+ await expect(eventTitle).toBeVisible();+ }+});