mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 17:26:24 +00:00
feat(tours): via ferrata layer mounted on the tours map (2D and 3D)
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
// FE-COMP-MAPLAYER-001 to FE-COMP-MAPLAYER-010
|
||||
// FE-COMP-MAPLAYER-001 to FE-COMP-MAPLAYER-014
|
||||
import React from 'react'
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen, fireEvent } from '../../../tests/helpers/render'
|
||||
import { MapLayerSwitcher, TourMapLayerSwitcher, MAP_ROUND_CONTROL_SIZE } from './MapLayerSwitcher'
|
||||
import type { FerrataMapLayer } from '../Ferratas/useFerrataMapLayer'
|
||||
|
||||
describe('MapLayerSwitcher', () => {
|
||||
it('FE-COMP-MAPLAYER-001: on the default layer, offers the switch to satellite', () => {
|
||||
@@ -97,3 +98,61 @@ describe('TourMapLayerSwitcher 3D switch', () => {
|
||||
expect(screen.getByRole('button', { name: 'Topo' })).toHaveAttribute('aria-pressed', 'true')
|
||||
})
|
||||
})
|
||||
|
||||
const ferrataLayer = (overrides: Partial<FerrataMapLayer> = {}): FerrataMapLayer => ({
|
||||
active: false,
|
||||
onToggle: vi.fn(),
|
||||
status: 'idle',
|
||||
ferratas: [],
|
||||
onSelect: vi.fn(),
|
||||
...overrides,
|
||||
})
|
||||
|
||||
describe('TourMapLayerSwitcher via ferrata switch', () => {
|
||||
it('FE-COMP-MAPLAYER-011: offers no via ferrata switch without a layer, and no status row either', () => {
|
||||
const { container } = render(<TourMapLayerSwitcher active="default" onChange={() => {}} />)
|
||||
expect(screen.queryByRole('button', { name: 'Via ferratas' })).toBeNull()
|
||||
expect(container.firstElementChild).toHaveAttribute('role', 'group')
|
||||
})
|
||||
|
||||
it('FE-COMP-MAPLAYER-012: the switch toggles the layer, pressed and in the accent while it is on', () => {
|
||||
const layer = ferrataLayer()
|
||||
const { rerender } = render(<TourMapLayerSwitcher active="topo" onChange={() => {}} ferrataLayer={layer} />)
|
||||
const off = screen.getByRole('button', { name: 'Via ferratas' })
|
||||
expect(off).toHaveAttribute('aria-pressed', 'false')
|
||||
expect(off).toHaveClass('text-content-muted')
|
||||
fireEvent.click(off)
|
||||
expect(layer.onToggle).toHaveBeenCalledTimes(1)
|
||||
|
||||
rerender(<TourMapLayerSwitcher active="topo" onChange={() => {}} ferrataLayer={ferrataLayer({ active: true, status: 'loading' })} />)
|
||||
const on = screen.getByRole('button', { name: 'Via ferratas' })
|
||||
expect(on).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(on).toHaveClass('bg-accent', 'text-accent-text')
|
||||
})
|
||||
|
||||
it('FE-COMP-MAPLAYER-013: the status pill sits in the same row, right of the pill, and says nothing while the layer is off', () => {
|
||||
const { rerender } = render(<TourMapLayerSwitcher active="default" onChange={() => {}} ferrataLayer={ferrataLayer()} />)
|
||||
expect(screen.queryByTestId('ferrata-status-pill')).toBeNull()
|
||||
|
||||
rerender(<TourMapLayerSwitcher active="default" onChange={() => {}} ferrataLayer={ferrataLayer({ active: true, status: 'tooLarge' })} />)
|
||||
const pill = screen.getByTestId('ferrata-status-pill')
|
||||
expect(pill).toHaveTextContent('Zoom in to load via ferratas')
|
||||
const row = pill.parentElement as HTMLElement
|
||||
expect(row.style.display).toBe('flex')
|
||||
expect(row.firstElementChild).toHaveAttribute('role', 'group')
|
||||
expect(row.lastElementChild).toBe(pill)
|
||||
})
|
||||
|
||||
it('FE-COMP-MAPLAYER-014: sits beside the 3D switch behind one divider, and counts what the layer found', () => {
|
||||
const found = [{ id: 'way/1' }, { id: 'way/2' }] as unknown as FerrataMapLayer['ferratas']
|
||||
render(
|
||||
<TourMapLayerSwitcher active="default" onChange={() => {}} onToggleTerrain={() => {}}
|
||||
ferrataLayer={ferrataLayer({ active: true, status: 'ready', ferratas: found })} />
|
||||
)
|
||||
const group = screen.getByRole('group')
|
||||
expect(group.querySelectorAll('span[aria-hidden]')).toHaveLength(1)
|
||||
const buttons = Array.from(group.querySelectorAll('button')).map((button) => button.textContent)
|
||||
expect(buttons.slice(-2)).toEqual(['Via ferratas', '3D'])
|
||||
expect(screen.getByTestId('ferrata-status-pill')).toHaveTextContent('2 via ferrata routes')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user