|
3 | 3 | // (radio :has() + prefers-color-scheme), and the inline bootstrap script |
4 | 4 | // persists the choice across hard loads. |
5 | 5 | import { test, expect } from '@playwright/test'; |
| 6 | +import { readFileSync } from 'node:fs'; |
| 7 | +import { fileURLToPath } from 'node:url'; |
| 8 | +import { dirname, join } from 'node:path'; |
| 9 | + |
| 10 | +const SAMPLE_REPORT = readFileSync( |
| 11 | + join(dirname(fileURLToPath(import.meta.url)), '../fixtures/junit4-report.json'), |
| 12 | + 'utf8' |
| 13 | +); |
6 | 14 |
|
7 | 15 | const LIGHT_BG = 'rgb(255, 255, 255)'; |
8 | 16 | const DARK_BG = 'rgb(16, 22, 29)'; |
@@ -119,3 +127,38 @@ test('dark mode keeps rendering dark on report pages after navigation', async ({ |
119 | 127 | expect(await bodyBackground(page)).toBe(DARK_BG); |
120 | 128 | expect(await page.evaluate(() => localStorage.getItem('rf-theme'))).toBe('dark'); |
121 | 129 | }); |
| 130 | + |
| 131 | +test('breadcrumbs and the toggle share one vertically centered row on report pages', async ({ page }) => { |
| 132 | + test.skip(test.info().project.name !== 'chromium', 'geometry check runs once'); |
| 133 | + // Mock GitHub raw content so the report page never hits the network. |
| 134 | + await page.route('**/raw.githubusercontent.com/**', route => { |
| 135 | + if (route.request().url().endsWith('refactor-first.json')) { |
| 136 | + route.fulfill({ status: 200, contentType: 'application/json', body: SAMPLE_REPORT }); |
| 137 | + } else { |
| 138 | + route.continue(); |
| 139 | + } |
| 140 | + }); |
| 141 | + await page.goto('/refactorfirst/refactorfirst/master/'); |
| 142 | + await page.waitForLoadState('networkidle'); |
| 143 | + const edges = await page.evaluate(() => { |
| 144 | + const crumb = document.querySelector('nav[aria-label="Breadcrumb"] ol li a'); |
| 145 | + const crumbBox = crumb.getBoundingClientRect(); |
| 146 | + const toggle = document.querySelector('.theme-toggle').getBoundingClientRect(); |
| 147 | + const bar = document.querySelector('.menu-bar').getBoundingClientRect(); |
| 148 | + return { |
| 149 | + crumbGlyphLeft: crumbBox.left + parseFloat(getComputedStyle(crumb).paddingLeft), |
| 150 | + brandLeft: document.querySelector('.brand').getBoundingClientRect().left, |
| 151 | + sameRow: crumbBox.top < toggle.bottom && toggle.top < crumbBox.bottom, |
| 152 | + centerDelta: Math.abs((crumbBox.top + crumbBox.bottom) / 2 - (toggle.top + toggle.bottom) / 2), |
| 153 | + toggleRight: toggle.right, |
| 154 | + barContentRight: bar.right - parseFloat(getComputedStyle(document.querySelector('.menu-bar')).paddingRight) |
| 155 | + }; |
| 156 | + }); |
| 157 | + // The first crumb's glyph keeps the menu column's left content edge… |
| 158 | + expect(Math.abs(edges.crumbGlyphLeft - edges.brandLeft)).toBeLessThanOrEqual(1); |
| 159 | + // …the toggle keeps the right content edge… |
| 160 | + expect(Math.abs(edges.toggleRight - edges.barContentRight)).toBeLessThanOrEqual(1); |
| 161 | + // …and the two share one vertically centered line. |
| 162 | + expect(edges.sameRow).toBe(true); |
| 163 | + expect(edges.centerDelta).toBeLessThanOrEqual(1); |
| 164 | +}); |
0 commit comments