|
| 1 | +import { test, expect } from "./fixtures/auth"; |
| 2 | + |
| 3 | +const MOBILE_VIEWPORT = { width: 375, height: 667 }; |
| 4 | +const DESKTOP_VIEWPORT = { width: 1280, height: 720 }; |
| 5 | + |
| 6 | +test.describe("Mobile header page title", () => { |
| 7 | + test("shows workspace name on workspace home at mobile viewport", async ({ |
| 8 | + authenticatedPage: page, |
| 9 | + }) => { |
| 10 | + await page.setViewportSize(MOBILE_VIEWPORT); |
| 11 | + await page.goto("/"); |
| 12 | + |
| 13 | + // Wait for the app shell to load |
| 14 | + const toggleButton = page.getByTestId("as-sidebar-toggle"); |
| 15 | + await expect(toggleButton).toBeVisible({ timeout: 15_000 }); |
| 16 | + |
| 17 | + // The mobile header title should display the workspace name |
| 18 | + const titleEl = page.getByTestId("mobile-header-title"); |
| 19 | + await expect(titleEl).toBeVisible({ timeout: 10_000 }); |
| 20 | + |
| 21 | + // The title should be non-empty (workspace name) |
| 22 | + const titleText = await titleEl.textContent(); |
| 23 | + expect(titleText).toBeTruthy(); |
| 24 | + expect(titleText!.trim().length).toBeGreaterThan(0); |
| 25 | + }); |
| 26 | + |
| 27 | + test("updates title when navigating to a page via sidebar", async ({ |
| 28 | + authenticatedPage: page, |
| 29 | + }) => { |
| 30 | + // Start at desktop to get workspace slug, then switch to mobile |
| 31 | + await page.goto("/"); |
| 32 | + await page.waitForURL((url) => !url.pathname.includes("/sign-in"), { |
| 33 | + timeout: 15_000, |
| 34 | + }); |
| 35 | + |
| 36 | + // Get workspace slug from URL |
| 37 | + const currentUrl = new URL(page.url()); |
| 38 | + const pathParts = currentUrl.pathname.split("/").filter(Boolean); |
| 39 | + const workspaceSlug = pathParts[0]; |
| 40 | + if (!workspaceSlug) { |
| 41 | + test.skip(true, "Could not determine workspace slug"); |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + // Switch to mobile viewport |
| 46 | + await page.setViewportSize(MOBILE_VIEWPORT); |
| 47 | + |
| 48 | + // Open sidebar |
| 49 | + const toggleButton = page.getByTestId("as-sidebar-toggle"); |
| 50 | + await expect(toggleButton).toBeVisible({ timeout: 10_000 }); |
| 51 | + await toggleButton.click(); |
| 52 | + |
| 53 | + const sheetContent = page.locator('[data-slot="sheet-content"]'); |
| 54 | + await expect(sheetContent).toBeVisible({ timeout: 5_000 }); |
| 55 | + |
| 56 | + // Wait for the page tree to load |
| 57 | + const treeItem = sheetContent.locator('[role="treeitem"]').first(); |
| 58 | + try { |
| 59 | + await expect(treeItem).toBeVisible({ timeout: 10_000 }); |
| 60 | + } catch { |
| 61 | + // No pages — create one via sidebar |
| 62 | + const newPageBtn = sheetContent.getByTestId("sb-new-page-btn"); |
| 63 | + if ((await newPageBtn.count()) > 0) { |
| 64 | + await newPageBtn.click(); |
| 65 | + await page.waitForURL( |
| 66 | + (url) => url.pathname.split("/").filter(Boolean).length >= 2, |
| 67 | + { timeout: 15_000 }, |
| 68 | + ); |
| 69 | + // After navigation, the mobile header title should be visible |
| 70 | + const titleEl = page.getByTestId("mobile-header-title"); |
| 71 | + await expect(titleEl).toBeVisible({ timeout: 10_000 }); |
| 72 | + return; |
| 73 | + } |
| 74 | + test.skip(true, "No pages and no new-page button available"); |
| 75 | + return; |
| 76 | + } |
| 77 | + |
| 78 | + // Record URL before clicking |
| 79 | + const urlBefore = page.url(); |
| 80 | + |
| 81 | + // Click to navigate |
| 82 | + await treeItem.click(); |
| 83 | + |
| 84 | + // Wait for URL to change |
| 85 | + await page.waitForURL((url) => url.href !== urlBefore, { |
| 86 | + timeout: 15_000, |
| 87 | + }); |
| 88 | + |
| 89 | + // The mobile header title should update to show the page title |
| 90 | + const titleEl = page.getByTestId("mobile-header-title"); |
| 91 | + await expect(titleEl).toBeVisible({ timeout: 10_000 }); |
| 92 | + |
| 93 | + // Title should be non-empty |
| 94 | + const titleText = await titleEl.textContent(); |
| 95 | + expect(titleText).toBeTruthy(); |
| 96 | + expect(titleText!.trim().length).toBeGreaterThan(0); |
| 97 | + }); |
| 98 | + |
| 99 | + test("shows Settings on settings page", async ({ |
| 100 | + authenticatedPage: page, |
| 101 | + }) => { |
| 102 | + await page.goto("/"); |
| 103 | + await page.waitForURL((url) => !url.pathname.includes("/sign-in"), { |
| 104 | + timeout: 15_000, |
| 105 | + }); |
| 106 | + |
| 107 | + // Get workspace slug from URL |
| 108 | + const currentUrl = new URL(page.url()); |
| 109 | + const pathParts = currentUrl.pathname.split("/").filter(Boolean); |
| 110 | + const workspaceSlug = pathParts[0]; |
| 111 | + if (!workspaceSlug) { |
| 112 | + test.skip(true, "Could not determine workspace slug"); |
| 113 | + return; |
| 114 | + } |
| 115 | + |
| 116 | + await page.setViewportSize(MOBILE_VIEWPORT); |
| 117 | + |
| 118 | + // Navigate to settings |
| 119 | + await page.goto(`/${workspaceSlug}/settings`); |
| 120 | + |
| 121 | + // Wait for the settings page to load |
| 122 | + const titleEl = page.getByTestId("mobile-header-title"); |
| 123 | + await expect(titleEl).toBeVisible({ timeout: 15_000 }); |
| 124 | + |
| 125 | + // Title should contain "Settings" |
| 126 | + await expect(titleEl).toContainText("Settings", { timeout: 10_000 }); |
| 127 | + }); |
| 128 | + |
| 129 | + test("header is hidden on desktop viewport", async ({ |
| 130 | + authenticatedPage: page, |
| 131 | + }) => { |
| 132 | + await page.setViewportSize(DESKTOP_VIEWPORT); |
| 133 | + await page.goto("/"); |
| 134 | + |
| 135 | + await page.waitForURL((url) => !url.pathname.includes("/sign-in"), { |
| 136 | + timeout: 15_000, |
| 137 | + }); |
| 138 | + |
| 139 | + // The entire mobile header (including the title) should be hidden on desktop |
| 140 | + // because the header has md:hidden class |
| 141 | + const mobileHeader = page.locator("header").filter({ |
| 142 | + has: page.getByTestId("as-sidebar-toggle"), |
| 143 | + }); |
| 144 | + |
| 145 | + await expect(mobileHeader).toBeHidden({ timeout: 5_000 }); |
| 146 | + }); |
| 147 | + |
| 148 | + test("title element has truncation styles", async ({ |
| 149 | + authenticatedPage: page, |
| 150 | + }) => { |
| 151 | + await page.setViewportSize(MOBILE_VIEWPORT); |
| 152 | + await page.goto("/"); |
| 153 | + |
| 154 | + const toggleButton = page.getByTestId("as-sidebar-toggle"); |
| 155 | + await expect(toggleButton).toBeVisible({ timeout: 15_000 }); |
| 156 | + |
| 157 | + const titleEl = page.getByTestId("mobile-header-title"); |
| 158 | + await expect(titleEl).toBeVisible({ timeout: 10_000 }); |
| 159 | + |
| 160 | + // Verify the element has overflow hidden via the truncate class |
| 161 | + const overflow = await titleEl.evaluate( |
| 162 | + (el) => window.getComputedStyle(el).overflow, |
| 163 | + ); |
| 164 | + expect(overflow).toBe("hidden"); |
| 165 | + |
| 166 | + const textOverflow = await titleEl.evaluate( |
| 167 | + (el) => window.getComputedStyle(el).textOverflow, |
| 168 | + ); |
| 169 | + expect(textOverflow).toBe("ellipsis"); |
| 170 | + }); |
| 171 | +}); |
0 commit comments