|
| 1 | +import { test, expect } from '@playwright/test' |
| 2 | +import { loginAsStudent, loginAsTeacher } from '../utils/auth' |
| 3 | +import { BASE, LOCALE } from '../utils/constants' |
| 4 | + |
| 5 | +/** |
| 6 | + * Issue #586 — the dashboard shell scrolls horizontally between 768px and ~890px. |
| 7 | + * |
| 8 | + * `SidebarInset` is `w-full flex-1` with no `min-w-0`, so it cannot shrink below |
| 9 | + * its min-content width. At `md` the 256px desktop sidebar appears at the same |
| 10 | + * moment the header's right-hand cluster stops being compact, and between them |
| 11 | + * they demand more room than the viewport has. |
| 12 | + */ |
| 13 | + |
| 14 | +const WIDTHS = [700, 768, 800, 850, 900, 1024, 1280] |
| 15 | + |
| 16 | +const PAGES = [ |
| 17 | + { name: 'student-dashboard', path: `/${LOCALE}/dashboard/student` }, |
| 18 | + { name: 'student-courses', path: `/${LOCALE}/dashboard/student/courses` }, |
| 19 | + { name: 'student-browse', path: `/${LOCALE}/dashboard/student/browse` }, |
| 20 | +] |
| 21 | + |
| 22 | +const TEACHER_PAGES = [ |
| 23 | + { name: 'teacher-dashboard', path: `/${LOCALE}/dashboard/teacher` }, |
| 24 | + { name: 'admin-dashboard', path: `/${LOCALE}/dashboard/admin` }, |
| 25 | +] |
| 26 | + |
| 27 | +type Measurement = { |
| 28 | + page: string |
| 29 | + width: number |
| 30 | + clientWidth: number |
| 31 | + scrollWidth: number |
| 32 | + overflow: number |
| 33 | +} |
| 34 | + |
| 35 | +async function measure(page: import('@playwright/test').Page) { |
| 36 | + return page.evaluate(() => { |
| 37 | + const doc = document.documentElement |
| 38 | + const main = document.querySelector('[data-slot="sidebar-inset"]') |
| 39 | + const mainRect = main?.getBoundingClientRect() |
| 40 | + return { |
| 41 | + clientWidth: doc.clientWidth, |
| 42 | + scrollWidth: doc.scrollWidth, |
| 43 | + mainLeft: mainRect ? Math.round(mainRect.left) : null, |
| 44 | + mainWidth: mainRect ? Math.round(mainRect.width) : null, |
| 45 | + } |
| 46 | + }) |
| 47 | +} |
| 48 | + |
| 49 | +test.describe('#586 dashboard shell horizontal overflow', () => { |
| 50 | + test('student pages do not scroll sideways at any width', async ({ page }) => { |
| 51 | + test.setTimeout(180_000) |
| 52 | + await loginAsStudent(page) |
| 53 | + |
| 54 | + const rows: Measurement[] = [] |
| 55 | + |
| 56 | + for (const target of PAGES) { |
| 57 | + for (const width of WIDTHS) { |
| 58 | + await page.setViewportSize({ width, height: 900 }) |
| 59 | + await page.goto(`${BASE}${target.path}`) |
| 60 | + await page.waitForLoadState('networkidle').catch(() => {}) |
| 61 | + await page.waitForTimeout(600) |
| 62 | + const m = await measure(page) |
| 63 | + rows.push({ |
| 64 | + page: target.name, |
| 65 | + width, |
| 66 | + clientWidth: m.clientWidth, |
| 67 | + scrollWidth: m.scrollWidth, |
| 68 | + overflow: m.scrollWidth - m.clientWidth, |
| 69 | + }) |
| 70 | + console.log( |
| 71 | + `${target.name} @${width}: client=${m.clientWidth} scroll=${m.scrollWidth} overflow=${m.scrollWidth - m.clientWidth} main=${m.mainLeft}/${m.mainWidth}` |
| 72 | + ) |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + console.log('\n=== SUMMARY ===') |
| 77 | + for (const r of rows) { |
| 78 | + console.log(`${r.page}\t${r.width}\t${r.clientWidth}\t${r.scrollWidth}\t${r.overflow}`) |
| 79 | + } |
| 80 | + |
| 81 | + const offenders = rows.filter((r) => r.overflow > 0) |
| 82 | + expect( |
| 83 | + offenders, |
| 84 | + `pages scrolling horizontally: ${JSON.stringify(offenders, null, 2)}` |
| 85 | + ).toEqual([]) |
| 86 | + }) |
| 87 | + |
| 88 | + test('teacher and admin pages do not scroll sideways at any width', async ({ page }) => { |
| 89 | + test.setTimeout(180_000) |
| 90 | + await loginAsTeacher(page) |
| 91 | + |
| 92 | + const rows: Measurement[] = [] |
| 93 | + |
| 94 | + for (const target of TEACHER_PAGES) { |
| 95 | + for (const width of WIDTHS) { |
| 96 | + await page.setViewportSize({ width, height: 900 }) |
| 97 | + await page.goto(`${BASE}${target.path}`) |
| 98 | + await page.waitForLoadState('networkidle').catch(() => {}) |
| 99 | + await page.waitForTimeout(600) |
| 100 | + const m = await measure(page) |
| 101 | + rows.push({ |
| 102 | + page: target.name, |
| 103 | + width, |
| 104 | + clientWidth: m.clientWidth, |
| 105 | + scrollWidth: m.scrollWidth, |
| 106 | + overflow: m.scrollWidth - m.clientWidth, |
| 107 | + }) |
| 108 | + console.log( |
| 109 | + `${target.name} @${width}: client=${m.clientWidth} scroll=${m.scrollWidth} overflow=${m.scrollWidth - m.clientWidth} main=${m.mainLeft}/${m.mainWidth}` |
| 110 | + ) |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + const offenders = rows.filter((r) => r.overflow > 0) |
| 115 | + expect( |
| 116 | + offenders, |
| 117 | + `pages scrolling horizontally: ${JSON.stringify(offenders, null, 2)}` |
| 118 | + ).toEqual([]) |
| 119 | + }) |
| 120 | + |
| 121 | + /** |
| 122 | + * The header hides the gamification card below `lg`; the avatar dropdown shows |
| 123 | + * it below `lg`. Those two gates are a pair — if they ever drift apart the |
| 124 | + * streak and coins silently vanish (or double up) in the gap. This asserts the |
| 125 | + * card is visible in exactly one place at each width. |
| 126 | + */ |
| 127 | + test('gamification card is reachable at every width, in exactly one place', async ({ |
| 128 | + page, |
| 129 | + }) => { |
| 130 | + test.setTimeout(120_000) |
| 131 | + await loginAsStudent(page) |
| 132 | + |
| 133 | + for (const width of [700, 768, 850, 1024, 1280]) { |
| 134 | + await page.setViewportSize({ width, height: 900 }) |
| 135 | + await page.goto(`${BASE}/${LOCALE}/dashboard/student`) |
| 136 | + await page.waitForLoadState('networkidle').catch(() => {}) |
| 137 | + await page.waitForTimeout(800) |
| 138 | + |
| 139 | + const headerCard = page.locator('header [data-slot="gamification-header-card"]') |
| 140 | + const headerVisible = await headerCard.isVisible().catch(() => false) |
| 141 | + |
| 142 | + // Open the avatar dropdown and look for the card inside it. Clicking a |
| 143 | + // base-ui Button through Playwright is unreliable, so dispatch it in-page. |
| 144 | + await page.evaluate(() => { |
| 145 | + const btn = document.querySelector<HTMLElement>( |
| 146 | + '[data-testid="user-nav-trigger"]' |
| 147 | + ) |
| 148 | + if (!btn) throw new Error('user-nav-trigger not found') |
| 149 | + btn.click() |
| 150 | + }) |
| 151 | + await page.waitForTimeout(700) |
| 152 | + const menuCard = page.locator( |
| 153 | + '[role="menu"] [data-slot="gamification-header-card"], [data-side] [data-slot="gamification-header-card"]' |
| 154 | + ) |
| 155 | + const menuVisible = await menuCard.first().isVisible().catch(() => false) |
| 156 | + await page.keyboard.press('Escape') |
| 157 | + |
| 158 | + console.log(`@${width}: header=${headerVisible} dropdown=${menuVisible}`) |
| 159 | + |
| 160 | + expect( |
| 161 | + headerVisible || menuVisible, |
| 162 | + `at ${width}px the gamification card is in neither the header nor the dropdown` |
| 163 | + ).toBe(true) |
| 164 | + expect( |
| 165 | + headerVisible && menuVisible, |
| 166 | + `at ${width}px the gamification card is duplicated in header and dropdown` |
| 167 | + ).toBe(false) |
| 168 | + |
| 169 | + // Above lg it belongs in the header; below lg, in the dropdown. |
| 170 | + expect(headerVisible, `header card visibility at ${width}px`).toBe(width >= 1024) |
| 171 | + } |
| 172 | + }) |
| 173 | +}) |
0 commit comments