Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions src/Bermuda.Web/e2e/panes.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import type { Page } from '@playwright/test'
import { test, expect } from './fixtures'
import { mapCollapsedKey, sidebarCollapsedKey } from '../src/components/useCollapsiblePane'

const sidebarToggle = (page: Page) => page.getByRole('button', { name: /sidebar/i })
const mapToggle = (page: Page) => page.getByRole('button', { name: /map/i })

async function resetPanes(page: Page) {
await page.evaluate(([sidebarKey, mapKey]) => {
localStorage.removeItem(sidebarKey)
localStorage.removeItem(mapKey)
}, [sidebarCollapsedKey, mapCollapsedKey] as const)
await page.reload()
await page.waitForSelector('tbody tr')
await page.waitForSelector('.leaflet-container')
}

test.describe('collapsible panes', () => {
test.beforeEach(async ({ page }) => {
await resetPanes(page)
await expect(sidebarToggle(page)).toHaveAttribute('aria-expanded', 'true')
await expect(mapToggle(page)).toHaveAttribute('aria-expanded', 'true')
})

// The shared WebView2 keeps localStorage. Leave both panes open for the rest of the suite.
test.afterEach(async ({ page }) => {
await resetPanes(page)
})

test('collapses and expands the sidebar and the map', async ({ page }) => {
const sidebar = page.locator('[data-pane="sidebar"]')
const map = page.locator('[data-pane="map"]')
const sidebarButton = sidebarToggle(page)
const mapButton = mapToggle(page)

expect(await sidebar.evaluate(el => getComputedStyle(el).transitionProperty)).toContain('width')
expect(await map.evaluate(el => getComputedStyle(el).transitionProperty)).toMatch(/width|flex-basis/)

// Focus was inside the sidebar, so collapsing with Ctrl+B moves it to the toggle.
await page.getByRole('button', { name: 'New window' }).focus()
await page.evaluate(() => {
const el = document.querySelector('[data-pane="sidebar"]')
const widths: number[] = []
;(window as unknown as { __paneWidths?: number[] }).__paneWidths = widths
if (!el) return
const start = performance.now()
const tick = () => {
widths.push(el.getBoundingClientRect().width)
if (performance.now() - start < 420) requestAnimationFrame(tick)
}
requestAnimationFrame(tick)
})
await page.keyboard.press('Control+b')
await page.waitForTimeout(450)
const duration = await sidebar.evaluate(el => getComputedStyle(el).transitionDuration)
if (!duration.split(',').every(part => part.trim() === '0s')) {
const widths = await page.evaluate(() => (window as unknown as { __paneWidths: number[] }).__paneWidths)
const openWidth = Math.max(...widths)
expect(widths.some(width => width < openWidth - 24 && width > 56)).toBe(true)
}
await expect(sidebarButton).toHaveAttribute('aria-expanded', 'false')
await expect(sidebarButton).toBeFocused()
await expect(page.locator('#app-sidebar')).toBeHidden()
await expect.poll(() => sidebar.evaluate(el => el.getBoundingClientRect().width)).toBeLessThan(56)
await expect(page.locator('tbody tr')).toHaveCount(8)
await expect(mapButton).toHaveAttribute('aria-expanded', 'true')

await page.locator('.leaflet-control-zoom-in').focus()
await page.keyboard.press('Control+Backslash')
await expect(mapButton).toHaveAttribute('aria-expanded', 'false')
await expect(mapButton).toBeFocused()
await expect(page.locator('#incident-map')).toBeHidden()
await expect.poll(async () => {
const rect = await map.evaluate(el => el.getBoundingClientRect())
return Math.min(rect.width, rect.height)
}).toBeLessThan(56)

await sidebarButton.click()
await expect(sidebarButton).toHaveAttribute('aria-expanded', 'true')
await expect(page.locator('#app-sidebar')).toBeVisible()
await expect(page.getByRole('button', { name: 'Open probe' })).toBeVisible()
await expect.poll(() => sidebar.evaluate(el => el.getBoundingClientRect().width)).toBeGreaterThan(200)

await mapButton.click()
await expect(mapButton).toHaveAttribute('aria-expanded', 'true')
await expect(page.locator('.leaflet-container')).toBeVisible()
await expect(page.locator('.leaflet-interactive')).toHaveCount(8)
})

test('keeps each pane collapsed after reload', async ({ page }) => {
await sidebarToggle(page).click()
await mapToggle(page).click()
await expect(sidebarToggle(page)).toHaveAttribute('aria-expanded', 'false')
await expect(mapToggle(page)).toHaveAttribute('aria-expanded', 'false')
await expect.poll(() => page.evaluate(([sidebarKey, mapKey]) => ({
sidebar: localStorage.getItem(sidebarKey),
map: localStorage.getItem(mapKey),
}), [sidebarCollapsedKey, mapCollapsedKey] as const)).toEqual({ sidebar: 'true', map: 'true' })

await page.reload()
await page.waitForSelector('tbody tr')
await expect(sidebarToggle(page)).toHaveAttribute('aria-expanded', 'false')
await expect(mapToggle(page)).toHaveAttribute('aria-expanded', 'false')
await expect(page.locator('#app-sidebar')).toBeHidden()
await expect(page.locator('#incident-map')).toBeHidden()

await sidebarToggle(page).click()
await mapToggle(page).click()
await expect.poll(() => page.evaluate(([sidebarKey, mapKey]) => ({
sidebar: localStorage.getItem(sidebarKey),
map: localStorage.getItem(mapKey),
}), [sidebarCollapsedKey, mapCollapsedKey] as const)).toEqual({ sidebar: 'false', map: 'false' })

await page.reload()
await page.waitForSelector('tbody tr')
await page.waitForSelector('.leaflet-container')
await expect(sidebarToggle(page)).toHaveAttribute('aria-expanded', 'true')
await expect(mapToggle(page)).toHaveAttribute('aria-expanded', 'true')
})
})
22 changes: 1 addition & 21 deletions src/Bermuda.Web/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
color-scheme: dark;
color: rgba(255, 255, 255, 0.87);
flex: 1;
min-width: 0;
min-height: 0;
overflow: hidden;
box-sizing: border-box;
Expand All @@ -24,27 +25,13 @@
flex-direction: column;
}

.heading-logo {
width: 2.25rem;
height: 2.25rem;
}

/* Narrow windows: the dashboard stacks (see IncidentsDashboard.module.css), so let the page scroll. */
@media (max-width: 900px) {
.content {
overflow-y: auto;
}
}

.content h1 {
display: flex;
align-items: center;
gap: 0.6rem;
flex-shrink: 0;
margin: 0 0 1.25rem;
font-size: 2rem;
}

.logo {
height: 6em;
padding: 1.5em;
Expand Down Expand Up @@ -80,10 +67,3 @@
.read-the-docs {
color: #888;
}

.app-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
}
97 changes: 97 additions & 0 deletions src/Bermuda.Web/src/App.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
.shell {
display: flex;
flex: 1 1 auto;
min-height: 0;
min-width: 0;
align-items: stretch;
}

.sidebar {
display: flex;
flex-direction: row;
align-items: stretch;
flex: 0 0 17rem;
width: 17rem;
min-width: 0;
min-height: 0;
overflow: hidden;
box-sizing: border-box;
background: #242424;
color: rgba(255, 255, 255, 0.87);
color-scheme: dark;
border-right: 1px solid #1e293b;
transition: flex-basis 200ms ease, width 200ms ease;
}

.sidebar[data-collapsed='true'] {
flex-basis: 2.75rem;
width: 2.75rem;
}

.pane {
flex: 1 1 auto;
align-self: stretch;
min-width: 0;
min-height: 0;
overflow: auto;
display: flex;
flex-direction: column;
gap: 0.9rem;
padding: 0.25rem 0.85rem 1rem 0.15rem;
box-sizing: border-box;
opacity: 1;
visibility: visible;
transition: opacity 200ms ease, visibility 0s linear;
}

.sidebar[data-collapsed='true'] .pane {
overflow: hidden;
opacity: 0;
visibility: hidden;
pointer-events: none;
transition: opacity 200ms ease, visibility 0s linear 200ms;
}

.brand {
display: flex;
align-items: center;
gap: 0.6rem;
margin: 0;
min-height: 2.25rem;
font-size: 1.25rem;
font-weight: 600;
line-height: 1.2;
white-space: nowrap;
}

.logo {
width: 2rem;
height: 2rem;
flex: 0 0 auto;
}

.nav {
display: flex;
flex-direction: column;
gap: 0.75rem;
min-width: 0;
}

.windows button {
width: 100%;
box-sizing: border-box;
padding: 0.4em 0.75em;
font-size: 0.875rem;
text-align: left;
/* Explicit: the global button rule uses a light background under a light OS theme. */
background-color: #1a1a1a;
color: rgba(255, 255, 255, 0.87);
}

@media (prefers-reduced-motion: reduce) {
.sidebar,
.pane {
transition-duration: 0s;
transition-delay: 0s;
}
}
81 changes: 67 additions & 14 deletions src/Bermuda.Web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,29 @@ import { OpenWindows } from './components/OpenWindows'
import logo from './assets/bermuda.svg'
import { IncidentsDashboard } from './components/IncidentsDashboard'
import { UpdateBanner } from './components/UpdateBanner'
import { sidebarCollapsedKey, useCollapsiblePane } from './components/useCollapsiblePane'
import { bermudaHost } from './bridge'
import styles from './App.module.css'
import toggleStyles from './components/paneToggle.module.css'
import './App.css'

function SidebarIcon() {
return (
<svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<rect x="3" y="3" width="18" height="18" rx="2" />
<path d="M9 3v18" />
</svg>
)
}

function App() {
const {
collapsed: sidebarCollapsed,
toggle: toggleSidebar,
paneRef: sidebarPaneRef,
toggleRef: sidebarToggleRef,
} = useCollapsiblePane(sidebarCollapsedKey, 'KeyB')

// Indeterminate taskbar progress while the initial incidents query is in
// flight; IncidentsDashboard clears it once it mounts (data is ready, since
// it only renders past the Suspense boundary below).
Expand All @@ -17,21 +36,55 @@ function App() {
}
}, [])

const sidebarLabel = sidebarCollapsed ? 'Expand sidebar' : 'Collapse sidebar'

return (
<main className="content">
<header className="app-header">
<h1>
<img className="heading-logo" src={logo} alt="" />
Bermuda
</h1>
<ChannelPicker />
<OpenWindows />
</header>
<UpdateBanner />
<Suspense fallback={<p>Loading incidents…</p>}>
<IncidentsDashboard />
</Suspense>
</main>
<div className={styles.shell}>
<div
className={styles.sidebar}
data-pane="sidebar"
data-collapsed={sidebarCollapsed ? 'true' : undefined}
>
<button
ref={sidebarToggleRef}
type="button"
className={toggleStyles.toggle}
aria-expanded={!sidebarCollapsed}
aria-controls="app-sidebar"
aria-keyshortcuts="Control+B"
aria-label={sidebarLabel}
title={`${sidebarLabel} (Ctrl+B)`}
onClick={toggleSidebar}
>
<SidebarIcon />
</button>
<aside
id="app-sidebar"
ref={sidebarPaneRef}
className={styles.pane}
aria-label="Sidebar"
inert={sidebarCollapsed ? true : undefined}
aria-hidden={sidebarCollapsed ? true : undefined}
>
<h1 className={styles.brand}>
<img className={styles.logo} src={logo} alt="" />
Bermuda
</h1>
<div className={styles.nav}>
<ChannelPicker />
<div className={styles.windows}>
<OpenWindows />
</div>
</div>
</aside>
</div>
<main className="content">
<UpdateBanner />
<Suspense fallback={<p>Loading incidents…</p>}>
<IncidentsDashboard />
</Suspense>
</main>
</div>
)
}

Expand Down
1 change: 1 addition & 0 deletions src/Bermuda.Web/src/components/ChannelPicker.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
border: 0;
min-width: 0;
display: flex;
flex-wrap: wrap;
gap: 0.375rem;
align-items: center;
}
Expand Down
Loading
Loading