mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 11:06:06 +00:00
31859651d7
Every help screen checked against the v5 redesign. Tours is documented for the first time, as a screen of its own with twelve screens under it, and notifications get help of their own. All pictures are taken again on a realistic demo trip, with short loops where a still cannot show the motion. The English is plain and every language is written naturally rather than word for word. The switcher shows two levels at most, a screen's overview lists its sub-screens as cards above its guides, each wiki page is linked once, and the help sidebar is wider. Fixes found along the way: Save to Collection keeps a tour's route, a track dropped on the places column opens the Tours import, tour Share on desktop, the unsaved tour draft lives on the account, a route click no longer adds an end point, Trip places leaves the trip's tours out, Escape closes a stage's day menu, confirms before destructive deletes, DWD warnings sharing one id kept apart, a booking's date moves with it, and smaller fixes across notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and the admin screens.
100 lines
4.1 KiB
TypeScript
100 lines
4.1 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { render, screen, fireEvent } from '../../../tests/helpers/render'
|
|
import { NavigationMenu } from './NavigationMenu'
|
|
import type { NavigationTarget } from '../Planner/placeNavigation'
|
|
|
|
// FE-COMP-NAVMENU-001 to FE-COMP-NAVMENU-007
|
|
|
|
const TARGETS: NavigationTarget[] = [
|
|
{ id: 'google', label: 'Google Maps', url: 'https://maps.example/g' },
|
|
{ id: 'waze', label: 'Waze', url: 'https://waze.example/w' },
|
|
]
|
|
|
|
/** A trigger at a chosen viewport position, so the flip can be provoked. */
|
|
function anchorAt(top: number, height = 30) {
|
|
const el = document.createElement('button')
|
|
document.body.appendChild(el)
|
|
el.getBoundingClientRect = () => ({
|
|
top, bottom: top + height, left: 40, right: 160, width: 120, height,
|
|
x: 40, y: top, toJSON: () => ({}),
|
|
}) as DOMRect
|
|
return el
|
|
}
|
|
|
|
/** jsdom measures everything as 0, so the menu needs a size to be placed. */
|
|
function withMenuHeight(height: number) {
|
|
vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({
|
|
top: 0, bottom: height, left: 0, right: 200, width: 200, height,
|
|
x: 0, y: 0, toJSON: () => ({}),
|
|
} as DOMRect)
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.restoreAllMocks()
|
|
document.body.innerHTML = ''
|
|
window.innerHeight = 800
|
|
window.innerWidth = 1200
|
|
})
|
|
|
|
describe('NavigationMenu', () => {
|
|
it('FE-COMP-NAVMENU-001: lists one entry per target', () => {
|
|
render(<NavigationMenu targets={TARGETS} anchor={anchorAt(100)} onClose={vi.fn()} />)
|
|
expect(screen.getByRole('menuitem', { name: 'Google Maps' })).toBeInTheDocument()
|
|
expect(screen.getByRole('menuitem', { name: 'Waze' })).toBeInTheDocument()
|
|
})
|
|
|
|
it('FE-COMP-NAVMENU-002: opening a target closes the menu', () => {
|
|
const open = vi.spyOn(window, 'open').mockImplementation(() => null)
|
|
const onClose = vi.fn()
|
|
render(<NavigationMenu targets={TARGETS} anchor={anchorAt(100)} onClose={onClose} />)
|
|
|
|
fireEvent.click(screen.getByRole('menuitem', { name: 'Waze' }))
|
|
|
|
expect(open).toHaveBeenCalledWith('https://waze.example/w', '_blank', 'noopener,noreferrer')
|
|
expect(onClose).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('FE-COMP-NAVMENU-003: sits below the trigger when there is room', () => {
|
|
withMenuHeight(120)
|
|
render(<NavigationMenu targets={TARGETS} anchor={anchorAt(100)} onClose={vi.fn()} />)
|
|
// Trigger ends at 130, so the menu starts just under it.
|
|
expect(screen.getByRole('menu')).toHaveStyle({ top: '136px' })
|
|
})
|
|
|
|
it('FE-COMP-NAVMENU-004: flips above the trigger when the bottom edge is close', () => {
|
|
// Trigger ends at 780 with a viewport of 800: a 120px menu would be cut off.
|
|
withMenuHeight(120)
|
|
render(<NavigationMenu targets={TARGETS} anchor={anchorAt(750)} onClose={vi.fn()} />)
|
|
expect(screen.getByRole('menu')).toHaveStyle({ top: '624px' })
|
|
})
|
|
|
|
it('FE-COMP-NAVMENU-005: never leaves the viewport, even when neither side fits', () => {
|
|
// Taller than the window: clamped to the top margin rather than negative.
|
|
withMenuHeight(900)
|
|
render(<NavigationMenu targets={TARGETS} anchor={anchorAt(700)} onClose={vi.fn()} />)
|
|
expect(screen.getByRole('menu')).toHaveStyle({ top: '8px' })
|
|
})
|
|
|
|
it('FE-COMP-NAVMENU-006: Escape closes it', () => {
|
|
const onClose = vi.fn()
|
|
render(<NavigationMenu targets={TARGETS} anchor={anchorAt(100)} onClose={onClose} />)
|
|
fireEvent.keyDown(document, { key: 'Escape' })
|
|
expect(onClose).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('FE-COMP-NAVMENU-008: Escape is prevented before a dialog behind the menu sees it', () => {
|
|
render(<NavigationMenu targets={TARGETS} anchor={anchorAt(100)} onClose={vi.fn()} />)
|
|
let seenPrevented = false
|
|
const behind = (e: KeyboardEvent) => { seenPrevented = e.defaultPrevented }
|
|
document.addEventListener('keydown', behind)
|
|
fireEvent.keyDown(document, { key: 'Escape' })
|
|
document.removeEventListener('keydown', behind)
|
|
expect(seenPrevented).toBe(true)
|
|
})
|
|
|
|
it('FE-COMP-NAVMENU-007: renders nothing without targets', () => {
|
|
render(<NavigationMenu targets={[]} anchor={anchorAt(100)} onClose={vi.fn()} />)
|
|
expect(screen.queryByRole('menu')).not.toBeInTheDocument()
|
|
})
|
|
})
|