From 7178ce0ef0165491bf77ee35b2a152941db28ba5 Mon Sep 17 00:00:00 2001 From: Guido Doumen Date: Mon, 9 Nov 2026 21:20:10 +0100 Subject: [PATCH 01/14] feat(pairing): show tiles dimmed while the ride falls back to another device A tile the page service marks as dimmed (the trainer is kept but not used while the ride runs on a separate power meter or speed sensor) now gets the muted look of a switched-off tile: device name and role line, the footer copy as given, no value and no switch. A tap still calls the tile's onClick. The phone's status bars use the same dimmed look and state line, and a dimmed tile is never counted as connected. --- .../CapabilityStatusBars.mock.ts | 33 ++++++ .../CapabilityStatusBars.stories.tsx | 6 +- .../CapabilityStatusBars.test.tsx | 19 +++- .../CapabilityStatusBars/utils.test.ts | 32 ++++++ src/components/CapabilityStatusBars/utils.ts | 20 +++- .../CapabilityTile/CapabilityTile.stories.tsx | 37 +++++++ .../CapabilityTile/CapabilityTile.test.tsx | 103 ++++++++++++++++++ .../CapabilityTile/CapabilityTile.tsx | 16 ++- 8 files changed, 254 insertions(+), 12 deletions(-) diff --git a/src/components/CapabilityStatusBars/CapabilityStatusBars.mock.ts b/src/components/CapabilityStatusBars/CapabilityStatusBars.mock.ts index 60036c81..8cd5b0f6 100644 --- a/src/components/CapabilityStatusBars/CapabilityStatusBars.mock.ts +++ b/src/components/CapabilityStatusBars/CapabilityStatusBars.mock.ts @@ -94,6 +94,39 @@ export const MOCK_CAPABILITIES_TRAINER_UNAVAILABLE: Capabilities = { rowLabels: { top: { text: 'TO RIDE', subtext: 'waiting for your trainer' }, bottom: OPTIONAL_LABEL }, } +const dimmedTrainerIn = (title: string, capability: CapabilityDisplayProps['capability']): CapabilityDisplayProps => ({ + ...trainerIn(title, capability, 'failed'), + trainerRole: 'via-trainer', + footerText: { full: 'Not used', short: 'Not used' }, + dimmed: true, + awaited: false, +}) + +/** + * The trainer can't be reached and the rider chose to ride on a separate power meter: Resistance and + * the other tile still holding the trainer are dimmed, and a tap on Resistance takes the trainer back. + */ +export const MOCK_CAPABILITIES_FALLBACK: Capabilities = { + top: [ + { + ...trainerIn('Resistance', 'control', 'failed'), + trainerRole: 'trainer', + roleLabel: 'Your trainer', + footerText: { full: 'Tap to use again', short: 'Tap to use again' }, + dimmed: true, + awaited: false, + }, + { title: 'Power', capability: 'power', deviceName: 'Stages Power', interface: 'ble', role: 'required', value: '154', unit: 'W', connectState: 'connected', awaited: false, onClick: noop, onUnselect: noop }, + dimmedTrainerIn('Speed', 'speed'), + ], + bottom: [ + OPTIONAL_ROW[0], + { ...dimmedTrainerIn('Cadence', 'cadence'), role: 'optional' }, + OPTIONAL_ROW[2], + ], + rowLabels: { top: { text: '✓ READY TO RIDE' }, bottom: OPTIONAL_LABEL }, +} + /** Ready: a power meter connected, Resistance switched off with its trainer remembered. */ export const MOCK_CAPABILITIES_SWITCHED_OFF: Capabilities = { top: [ diff --git a/src/components/CapabilityStatusBars/CapabilityStatusBars.stories.tsx b/src/components/CapabilityStatusBars/CapabilityStatusBars.stories.tsx index c3147f0b..eba89e9f 100644 --- a/src/components/CapabilityStatusBars/CapabilityStatusBars.stories.tsx +++ b/src/components/CapabilityStatusBars/CapabilityStatusBars.stories.tsx @@ -4,7 +4,7 @@ import type { Meta, StoryObj } from '@storybook/react-native-web-vite'; import { CapabilityStatusBars } from './CapabilityStatusBars' import { colors } from '../../theme' import { - MOCK_CAPABILITIES_HEARTRATE_ONLY, MOCK_CAPABILITIES_SEARCHING, MOCK_CAPABILITIES_SWITCHED_OFF, + MOCK_CAPABILITIES_FALLBACK, MOCK_CAPABILITIES_HEARTRATE_ONLY, MOCK_CAPABILITIES_SEARCHING, MOCK_CAPABILITIES_SWITCHED_OFF, MOCK_CAPABILITIES_TRAINER_CONNECTING, MOCK_CAPABILITIES_TRAINER_UNAVAILABLE, } from './CapabilityStatusBars.mock' @@ -44,6 +44,10 @@ export const SwitchedOff: Story = { args: { capabilities: MOCK_CAPABILITIES_SWITCHED_OFF }, } +export const Fallback: Story = { + args: { capabilities: MOCK_CAPABILITIES_FALLBACK }, +} + // the space left beside the helper panel on a 667 x 375 phone const styles = StyleSheet.create({ decorator: { diff --git a/src/components/CapabilityStatusBars/CapabilityStatusBars.test.tsx b/src/components/CapabilityStatusBars/CapabilityStatusBars.test.tsx index 2d43c96c..fc3d7607 100644 --- a/src/components/CapabilityStatusBars/CapabilityStatusBars.test.tsx +++ b/src/components/CapabilityStatusBars/CapabilityStatusBars.test.tsx @@ -1,7 +1,7 @@ import React from 'react' import { render, fireEvent } from '@testing-library/react-native' import { CapabilityStatusBars } from './CapabilityStatusBars' -import { MOCK_CAPABILITIES_HEARTRATE_ONLY, MOCK_CAPABILITIES_TRAINER_UNAVAILABLE } from './CapabilityStatusBars.mock' +import { MOCK_CAPABILITIES_FALLBACK, MOCK_CAPABILITIES_HEARTRATE_ONLY, MOCK_CAPABILITIES_TRAINER_UNAVAILABLE } from './CapabilityStatusBars.mock' describe('CapabilityStatusBars', () => { it('renders the required row as bars and the optional row as one line', () => { @@ -34,6 +34,23 @@ describe('CapabilityStatusBars', () => { expect(getAllByText('Tacx Flux · via your trainer · Via trainer')).toHaveLength(2) }) + it('while the ride falls back to another device, the dimmed bars show the copy as given', () => { + const { getByText } = render() + expect(getByText('Tacx Flux · Your trainer · Tap to use again')).toBeTruthy() + expect(getByText('154 W · Stages Power · CONNECTED')).toBeTruthy() + expect(getByText('Tacx Flux · Not used')).toBeTruthy() + // the dimmed Cadence tile isn't marked connected in the optional line + expect(getByText('OPTIONAL: HEARTRATE · CADENCE · CONTROLLER')).toBeTruthy() + }) + + it('a tap on a dimmed bar calls its onClick, as the tile does', () => { + const onClick = jest.fn() + const tiles = MOCK_CAPABILITIES_FALLBACK.top.map(t => (t.capability === 'control' ? { ...t, onClick } : t)) + const { getByText } = render() + fireEvent.press(getByText('RESISTANCE')) + expect(onClick).toHaveBeenCalledTimes(1) + }) + it('renders nothing without capabilities', () => { const { toJSON } = render() expect(toJSON()).toBeNull() diff --git a/src/components/CapabilityStatusBars/utils.test.ts b/src/components/CapabilityStatusBars/utils.test.ts index 0d0504c3..84398700 100644 --- a/src/components/CapabilityStatusBars/utils.test.ts +++ b/src/components/CapabilityStatusBars/utils.test.ts @@ -50,6 +50,27 @@ describe('getBarStateLine', () => { }) expect(getBarStateLine(t)).toBe('Tacx Flux · via your trainer · Via trainer') }) + + it('a dimmed Resistance tile: the trainer, its role and the footer copy as given, without a connect state', () => { + const t = tile({ + title: 'Resistance', capability: 'control', deviceName: 'Tacx Flux', connectState: 'failed', dimmed: true, + trainerRole: 'trainer', roleLabel: 'Your trainer', footerText: { full: 'Tap to use again', short: 'Tap again' }, + }) + expect(getBarStateLine(t)).toBe('Tacx Flux · Your trainer · Tap again') + }) + + it('a dimmed tile the trainer still holds shows no value, even if one is reported', () => { + const t = tile({ + deviceName: 'Tacx Flux', value: '120', unit: 'W', connectState: 'connected', dimmed: true, + trainerRole: 'via-trainer', footerText: { full: 'Not used', short: 'Not used' }, + }) + expect(getBarStateLine(t)).toBe('Tacx Flux · Not used') + }) + + it('a dimmed tile without footer copy falls back to its empty footer, never to the connect state', () => { + const t = tile({ deviceName: 'Tacx Flux', connectState: 'failed', dimmed: true, emptyFooter: 'Searching…' }) + expect(getBarStateLine(t)).toBe('Tacx Flux · Searching…') + }) }) describe('getBarLook', () => { @@ -61,6 +82,12 @@ describe('getBarLook', () => { expect(getBarLook(tile({ deviceName: 'Tacx Flux', connectState: 'connecting' }))).toBe('idle') }) + it('a dimmed tile gets the same muted look as a switched-off one, even if its device reports connected', () => { + expect(getBarLook(tile({ deviceName: 'Tacx Flux', connectState: 'failed', dimmed: true }))).toBe('dimmed') + expect(getBarLook(tile({ deviceName: 'Tacx Flux', connectState: 'connected', dimmed: true }))).toBe('dimmed') + expect(getBarLook(tile({ deviceName: 'Tacx Flux', connectState: 'failed', dimmed: true, awaited: true }))).toBe('dimmed') + }) + it('the amber outline follows whether the page waits for the tile', () => { expect(getBarLook(tile({ deviceName: 'Tacx Flux', connectState: 'failed', awaited: true }))).toBe('waiting') expect(getBarLook(tile({ deviceName: 'Tacx Flux', connectState: 'failed', awaited: false }))).toBe('idle') @@ -85,4 +112,9 @@ describe('getOptionalSummary', () => { const tiles = [tile({ title: 'Heartrate', capability: 'heartrate', deviceName: 'HRM', connectState: 'connected', disabled: true })] expect(getOptionalSummary(tiles)).toEqual([{ title: 'Heartrate', connected: false }]) }) + + it('a dimmed tile is never marked connected', () => { + const tiles = [tile({ title: 'Cadence', capability: 'cadence', deviceName: 'Tacx Flux', connectState: 'connected', dimmed: true })] + expect(getOptionalSummary(tiles)).toEqual([{ title: 'Cadence', connected: false }]) + }) }) diff --git a/src/components/CapabilityStatusBars/utils.ts b/src/components/CapabilityStatusBars/utils.ts index 9100d5bd..bb10ae60 100644 --- a/src/components/CapabilityStatusBars/utils.ts +++ b/src/components/CapabilityStatusBars/utils.ts @@ -9,8 +9,15 @@ export interface OptionalSummaryItem { export const isSwitchedOff = (tile: CapabilityDisplayProps): boolean => Boolean(tile.deviceName) && Boolean(tile.disabled) +/** + * A device is there but deliberately not used right now (the ride falls back to another device while + * the trainer isn't available). It looks like a switched-off tile, but it isn't switched off: it has + * no switch, and a tap does whatever the page service set as the tile's `onClick`. + */ +export const isDimmed = (tile: CapabilityDisplayProps): boolean => Boolean(tile.deviceName) && Boolean(tile.dimmed) + export const isConnected =(tile: CapabilityDisplayProps): boolean => - Boolean(tile.deviceName) && !tile.disabled && tile.connectState === 'connected' + Boolean(tile.deviceName) && !tile.disabled && !tile.dimmed && tile.connectState === 'connected' /** * The one state line of a status bar, from the same props the tile shows: the value, the device (or @@ -23,6 +30,10 @@ export const getBarStateLine = (tile: CapabilityDisplayProps): string => { if (isSwitchedOff(tile)) return [tile.deviceName, footer ?? tile.emptyFooter ?? 'Not used'].join(' · ') + // no value and no connect state: the device isn't used, the footer copy says what a tap does + if (isDimmed(tile)) + return [tile.deviceName, tile.roleLabel, footer ?? tile.emptyFooter].filter(Boolean).join(' · ') + if (!tile.deviceName) return [tile.helpText?.short, footer ?? tile.emptyFooter].filter(Boolean).join(' · ') @@ -32,11 +43,12 @@ export const getBarStateLine = (tile: CapabilityDisplayProps): string => { } /** - * The bar's look, in the tile colour language: green when connected, dimmed when switched off, the - * amber outline while the page waits for it, grey otherwise. + * The bar's look, in the tile colour language: green when connected, dimmed when switched off or not + * used while the ride falls back to another device, the amber outline while the page waits for it, + * grey otherwise. */ export const getBarLook = (tile: CapabilityDisplayProps): BarLook => { - if (isSwitchedOff(tile)) + if (isSwitchedOff(tile) || isDimmed(tile)) return 'dimmed' if (isConnected(tile)) return 'connected' diff --git a/src/components/CapabilityTile/CapabilityTile.stories.tsx b/src/components/CapabilityTile/CapabilityTile.stories.tsx index b3f0c856..7856c942 100644 --- a/src/components/CapabilityTile/CapabilityTile.stories.tsx +++ b/src/components/CapabilityTile/CapabilityTile.stories.tsx @@ -96,6 +96,43 @@ export const PhoneWithToggle: Story= { } }; +// The ride falls back to a separate power meter while the trainer isn't available: the Resistance +// tile is dimmed, without a switch, and a tap takes the trainer back into use +export const DimmedResistance: Story= { + args: { + height:160, + title:'resistance', + capability:'control', + deviceName:'Tacx Flux', + interface:'ble', + connectState:'failed', + trainerRole:'trainer', + roleLabel:'Your trainer', + footerText:{ full:'Tap to use again', short:'Tap to use again' }, + dimmed:true, + awaited:false, + onClick:fn() + } +}; + +// Another tile the trainer still holds while the ride falls back to another device +export const DimmedViaTrainerPhone: Story= { + args: { + height:90, + title:'speed', + capability:'speed', + deviceName:'Tacx Flux', + interface:'ble', + connectState:'failed', + trainerRole:'via-trainer', + footerText:{ full:'Not used', short:'Not used' }, + dimmed:true, + awaited:false, + variant:'short', + onClick:fn() + } +}; + export const UndefinedUnits: Story= { args: { height:160, diff --git a/src/components/CapabilityTile/CapabilityTile.test.tsx b/src/components/CapabilityTile/CapabilityTile.test.tsx index ee0bc691..b1c1ecdc 100644 --- a/src/components/CapabilityTile/CapabilityTile.test.tsx +++ b/src/components/CapabilityTile/CapabilityTile.test.tsx @@ -215,6 +215,109 @@ describe('CapabilityTile T16 (switched off, device remembered)', () => { }); }); +describe('CapabilityTile dimmed (the ride falls back to another device)', () => { + + afterEach(() => { + jest.clearAllMocks(); + }); + + // the shape the page service sends for a dimmed tile: a device, not disabled, no switch handlers + const buildDimmedTile = (props: Partial = {}) => buildTile({ + title: 'Resistance', capability: 'control', deviceName: 'Tacx Flux', connectState: 'failed', + value: undefined, unit: undefined, onUnselect: undefined, onUse: undefined, + dimmed: true, trainerRole: 'trainer', roleLabel: 'Your trainer', + footerText: { full: 'Tap to use again', short: 'Tap again' }, + ...props, + }); + + const fillOf = (root: ReturnType['UNSAFE_root']) => + StyleSheet.flatten(root.findByType(TouchableOpacity).props.style).backgroundColor; + + it('shows the device, its role and the footer copy as given, with no value and no connect state', () => { + const { getByText, queryByText } = render(); + + expect(getByText('Tacx Flux')).toBeTruthy(); + expect(getByText('Your trainer')).toBeTruthy(); + expect(getByText('Tap to use again')).toBeTruthy(); + expect(queryByText('120')).toBeNull(); + expect(queryByText('FAILED')).toBeNull(); + }); + + it('uses the phone footer copy on a phone', () => { + const { getByText, queryByText } = render(); + + expect(getByText('Tap again')).toBeTruthy(); + expect(queryByText('Tap to use again')).toBeNull(); + }); + + it('has no on/off switch', () => { + const { queryByLabelText } = render(); + + expect(queryByLabelText('Use Resistance')).toBeNull(); + }); + + it('gets the muted fill of a switched-off tile, even if its device reports connected', () => { + const { UNSAFE_root } = render(); + + expect(fillOf(UNSAFE_root)).toBe(colors.tileEmpty); + }); + + it('a tap on the tile calls its onClick, once, with the tile', () => { + const tile = buildDimmedTile(); + const { getByText } = render(); + + fireEvent.press(getByText('Tacx Flux')); + + expect(tile.onClick).toHaveBeenCalledTimes(1); + expect(tile.onClick).toHaveBeenCalledWith(expect.objectContaining({ capability: 'control', dimmed: true })); + }); + + it('another tile the trainer still holds is dimmed the same way', () => { + const { getByText, queryByText, queryByLabelText, UNSAFE_root } = render(); + + expect(getByText('Not used')).toBeTruthy(); + expect(queryByText('0')).toBeNull(); + expect(queryByLabelText('Use Power')).toBeNull(); + expect(fillOf(UNSAFE_root)).toBe(colors.tileEmpty); + }); +}); + +describe('CapabilityTile Resistance switch while the trainer connects or cannot be reached', () => { + + afterEach(() => { + jest.clearAllMocks(); + }); + + const buildTrainerTile = (connectState: CapabilityDisplayProps['connectState']) => buildTile({ + title: 'Resistance', capability: 'control', deviceName: 'Tacx Flux', value: undefined, unit: undefined, + connectState, trainerRole: 'trainer', roleLabel: 'Your trainer', awaited: true, + footerText: { full: 'Not connected · waiting', short: 'Waiting…' }, + }); + + it.each(['connecting', 'failed'])('switching it off (%s) calls onUnselect exactly once, and nothing else', (connectState) => { + const tile = buildTrainerTile(connectState as CapabilityDisplayProps['connectState']); + const { getByLabelText } = render(); + + fireEvent.press(getByLabelText('Use Resistance')); + + expect(tile.onUnselect).toHaveBeenCalledTimes(1); + expect(tile.onUnselect).toHaveBeenCalledWith(); + expect(tile.onClick).not.toHaveBeenCalled(); + }); + + it('the switch stays as the page service draws it: still on after the tap, until the next props arrive', () => { + const tile = buildTrainerTile('connecting'); + const { getByLabelText } = render(); + + fireEvent.press(getByLabelText('Use Resistance')); + + expect(getByLabelText('Use Resistance').props.accessibilityState).toEqual({ checked: true }); + }); +}); + describe('CapabilityTile waiting outline', () => { const borderColorOf = (root: ReturnType['UNSAFE_root']) => diff --git a/src/components/CapabilityTile/CapabilityTile.tsx b/src/components/CapabilityTile/CapabilityTile.tsx index 17b1979f..b8530241 100644 --- a/src/components/CapabilityTile/CapabilityTile.tsx +++ b/src/components/CapabilityTile/CapabilityTile.tsx @@ -47,8 +47,9 @@ export const CapabilityTile = ( props:PropsWithChildren) => const hasDevice = Boolean(props.deviceName) const switchedOff = isSwitchedOff(props) // only a connected device gets the in-use colour - the same rule as the status bars, so the grid - // and the bars always agree. A device that is still connecting or can't be reached, and a - // switched-off tile (T16), use the same muted look as an empty tile. + // and the bars always agree. A device that is still connecting or can't be reached, a + // switched-off tile, and a dimmed tile (not used while the ride falls back to another + // device) use the same muted look as an empty tile. const backgroundColor = isConnected(props) ? colors.tileActive : colors.tileEmpty // the page service decides which tiles the page waits for; the tile only renders the outline const waitingBorder = props.awaited ? { borderWidth: 3, borderColor: colors.pairingWaiting } : undefined @@ -252,6 +253,7 @@ const CapabilityTileView = React.memo ( (props: ComponentProps) => { stateText, value, disabled, + dimmed, unit, interface:ifName, size, @@ -303,7 +305,7 @@ const CapabilityTileView = React.memo ( (props: ComponentProps) => { return capabilityIconSize === undefined ? undefined : { width: capabilityIconSize, height: capabilityIconSize } } - if ( deviceName && !disabled) { + if ( deviceName && !disabled && !dimmed) { const activeFooter = getActiveFooter(footer, stateText, connectState) // a connected tile keeps its value column even before the first value arrives, so the icon // doesn't jump; any other tile has no value, and its icon has the row to itself, centred @@ -360,9 +362,11 @@ const CapabilityTileView = React.memo ( (props: ComponentProps) => { ) } - // T16: switched off, but a device is remembered - shown dimmed (muted tile colour, set by the - // parent), with the device name and no value, and the toggle to turn it straight back on - if ( deviceName && disabled) { + // switched off, but a device is remembered - shown dimmed (muted tile colour, set by the + // parent), with the device name and no value, and the toggle to turn it straight back on. + // A dimmed tile (not used while the ride falls back to another device) looks the same; the page + // service sends it without switch handlers, so it gets no toggle, and its footer copy as given. + if ( deviceName && (disabled || dimmed)) { return ( Date: Mon, 9 Nov 2026 21:28:46 +0100 Subject: [PATCH 02/14] refactor(pairing): share the helper panel's shell, and cover its fallback action The header with title and close button, and the pinned area at the bottom, move into PairingSidePanel, so another panel can take the same slot beside the tiles with the same look. The helper renders as before. New fixtures and tests cover the helper offering to ride on a separate power meter: the action label comes from the page service as given, pinned below the tip. --- .../PairingHelperPanel.mock.ts | 12 ++ .../PairingHelperPanel.stories.tsx | 10 +- .../PairingHelperPanel.test.tsx | 30 ++++- .../PairingHelperPanel/PairingHelperPanel.tsx | 109 +++--------------- .../PairingSidePanel.stories.tsx | 62 ++++++++++ .../PairingSidePanel.test.tsx | 46 ++++++++ .../PairingSidePanel/PairingSidePanel.tsx | 91 +++++++++++++++ .../PairingSidePanelAction.tsx | 42 +++++++ src/components/PairingSidePanel/index.ts | 3 + src/components/PairingSidePanel/types.ts | 21 ++++ src/components/index.ts | 1 + 11 files changed, 332 insertions(+), 95 deletions(-) create mode 100644 src/components/PairingSidePanel/PairingSidePanel.stories.tsx create mode 100644 src/components/PairingSidePanel/PairingSidePanel.test.tsx create mode 100644 src/components/PairingSidePanel/PairingSidePanel.tsx create mode 100644 src/components/PairingSidePanel/PairingSidePanelAction.tsx create mode 100644 src/components/PairingSidePanel/index.ts create mode 100644 src/components/PairingSidePanel/types.ts diff --git a/src/components/PairingHelperPanel/PairingHelperPanel.mock.ts b/src/components/PairingHelperPanel/PairingHelperPanel.mock.ts index 87e87229..eff7af9a 100644 --- a/src/components/PairingHelperPanel/PairingHelperPanel.mock.ts +++ b/src/components/PairingHelperPanel/PairingHelperPanel.mock.ts @@ -83,6 +83,18 @@ export const buildTrainerUnavailableHelper = (h: MockHelperHandlers = {}): Pairi onDismiss: h.onDismiss ?? noop, }) +export const MOCK_TIP_FALLBACK_POWER = { + text: "You can ride with your power meter instead. Normally Incyclist changes your trainer's resistance, so you feel hills and workouts get harder or easier by themselves. With only a power meter that doesn't happen: you set the effort with your gears. This lasts until you next open Devices.", + shortText: "Ride with your power meter instead. You won't feel hills or workout changes; use your gears. Until you next open Devices.", +} + +/** The configured trainer can't be reached, "my trainer isn't available today" picked, a separate power meter connected: the ride can fall back to it. */ +export const buildFallbackHelper = (h: MockHelperHandlers = {}): PairingHelperDisplayProps => ({ + ...buildTrainerUnavailableHelper(h), + tip: MOCK_TIP_FALLBACK_POWER, + action: { label: 'Ride with power meter only', onClick: h.onAction ?? noop }, +}) + /** A device made the row ready while the helper was open. */ export const buildResolvedHelper = (h: MockHelperHandlers = {}): PairingHelperDisplayProps => ({ ...buildAsleepHelper(h), diff --git a/src/components/PairingHelperPanel/PairingHelperPanel.stories.tsx b/src/components/PairingHelperPanel/PairingHelperPanel.stories.tsx index 74eabf91..3c3c4555 100644 --- a/src/components/PairingHelperPanel/PairingHelperPanel.stories.tsx +++ b/src/components/PairingHelperPanel/PairingHelperPanel.stories.tsx @@ -5,7 +5,7 @@ import { fn } from 'storybook/test'; import { PairingHelperPanel } from './PairingHelperPanel' import { colors } from '../../theme' import { - buildAsleepHelper, buildNoDeviceHelper, buildNoTrainerHelper, buildResolvedHelper, buildTrainerUnavailableHelper, + buildAsleepHelper, buildFallbackHelper, buildNoDeviceHelper, buildNoTrainerHelper, buildResolvedHelper, buildTrainerUnavailableHelper, } from './PairingHelperPanel.mock' const handlers = () => ({ onOpen: fn(), onDismiss: fn(), onSelect: fn(), onAction: fn() }) @@ -53,6 +53,14 @@ export const TrainerUnavailableTablet: Story = { args: { helper: buildTrainerUnavailableHelper(handlers()), layout: 'tablet' }, } +export const FallbackPhone: Story = { + args: { helper: buildFallbackHelper(handlers()) }, +} + +export const FallbackTablet: Story = { + args: { helper: buildFallbackHelper(handlers()), layout: 'tablet' }, +} + export const Resolved: Story = { args: { helper: buildResolvedHelper(handlers()) }, } diff --git a/src/components/PairingHelperPanel/PairingHelperPanel.test.tsx b/src/components/PairingHelperPanel/PairingHelperPanel.test.tsx index 4e77ff95..33224243 100644 --- a/src/components/PairingHelperPanel/PairingHelperPanel.test.tsx +++ b/src/components/PairingHelperPanel/PairingHelperPanel.test.tsx @@ -1,8 +1,9 @@ import React from 'react' -import { render, fireEvent } from '@testing-library/react-native' +import { render, fireEvent, within } from '@testing-library/react-native' import { PairingHelperPanel } from './PairingHelperPanel' import { - buildAsleepHelper, buildNoDeviceHelper, buildNoTrainerHelper, buildResolvedHelper, buildTrainerUnavailableHelper, + MOCK_TIP_FALLBACK_POWER, + buildAsleepHelper, buildFallbackHelper, buildNoDeviceHelper, buildNoTrainerHelper, buildResolvedHelper, buildTrainerUnavailableHelper, } from './PairingHelperPanel.mock' describe('PairingHelperPanel', () => { @@ -57,6 +58,31 @@ describe('PairingHelperPanel', () => { expect(getByText("My trainer isn't available today")).toBeTruthy() }) + it('offers the fallback action with the label as given, pinned below the tip, and calls its handler', () => { + const onAction = jest.fn() + const { getByText, getByTestId, toJSON } = render() + + expect(getByText(MOCK_TIP_FALLBACK_POWER.shortText)).toBeTruthy() + const pinned = getByTestId('pairing-side-panel-pinned') + expect(within(pinned).getByText('Ride with power meter only')).toBeTruthy() + const tree = JSON.stringify(toJSON()) + expect(tree.indexOf(MOCK_TIP_FALLBACK_POWER.shortText)).toBeLessThan(tree.indexOf('Ride with power meter only')) + + fireEvent.press(getByText('Ride with power meter only')) + expect(onAction).toHaveBeenCalledTimes(1) + }) + + it('without a note, the action shows no line above it', () => { + const { getByTestId } = render() + const texts = within(getByTestId('pairing-side-panel-pinned')).queryAllByText(/./) + expect(texts.map(t => t.props.children)).toEqual(['Ride with power meter only']) + }) + + it('once resolved, the action is gone', () => { + const { queryByText } = render() + expect(queryByText('Ride with power meter only')).toBeNull() + }) + it('close dismisses the helper', () => { const onDismiss = jest.fn() const { getByLabelText } = render() diff --git a/src/components/PairingHelperPanel/PairingHelperPanel.tsx b/src/components/PairingHelperPanel/PairingHelperPanel.tsx index a323841e..c0557924 100644 --- a/src/components/PairingHelperPanel/PairingHelperPanel.tsx +++ b/src/components/PairingHelperPanel/PairingHelperPanel.tsx @@ -3,6 +3,7 @@ import { View, Text, Pressable, ScrollView, StyleSheet } from 'react-native' import { colors, textSizes } from '../../theme' import { useLogging } from '../../hooks' +import { PairingSidePanel, PairingSidePanelAction } from '../PairingSidePanel' import { ReasonRow } from './ReasonRow' import { getVisibleReasons } from './utils' import { PairingHelperPanelProps } from './types' @@ -44,25 +45,23 @@ export const PairingHelperPanel = ({ helper, layout }: PairingHelperPanelProps) const resolved = helper.phase === 'resolved' const tip = isPhone ? helper.tip?.shortText : helper.tip?.text const showFooterLine = !isPhone && !resolved - const showPinned = (!resolved && helper.action !== undefined) || showFooterLine + const action = resolved ? undefined : helper.action + const showPinned = action !== undefined || showFooterLine - return ( - - - - {helper.title} - - ✕ - - - {!resolved && helper.subline ? {helper.subline} : null} - + const pinned = showPinned ? ( + <> + {action ? : null} + {showFooterLine ? {helper.footer} : null} + + ) : undefined + return ( + {resolved ? ( {helper.resolvedText} @@ -79,61 +78,11 @@ export const PairingHelperPanel = ({ helper, layout }: PairingHelperPanelProps) )} )} - - {showPinned && ( - - {!resolved && helper.action?.note ? {helper.action.note} : null} - {!resolved && helper.action ? ( - - {helper.action.label} - - ) : null} - {showFooterLine ? {helper.footer} : null} - - )} - + ) } const styles = StyleSheet.create({ - panel: { - flex: 1, - backgroundColor: colors.helperPanelBackground, - borderLeftWidth: 3, - borderLeftColor: colors.pairingWaiting, - borderTopLeftRadius: 8, - borderBottomLeftRadius: 8, - }, - header: { - paddingLeft: 12, - paddingTop: 4, - }, - titleRow: { - flexDirection: 'row', - alignItems: 'center', - }, - title: { - flex: 1, - color: colors.text, - fontSize: textSizes.normalText, - fontWeight: '700', - }, - close: { - width: MIN_TOUCH_SIZE, - height: MIN_TOUCH_SIZE, - alignItems: 'center', - justifyContent: 'center', - }, - closeText: { - color: colors.text, - fontSize: textSizes.normalText, - }, - subline: { - color: colors.text, - fontSize: textSizes.smallText, - paddingRight: 12, - paddingBottom: 6, - }, body: { flex: 1, }, @@ -163,30 +112,6 @@ const styles = StyleSheet.create({ fontWeight: '700', textAlign: 'center', }, - pinned: { - borderTopWidth: StyleSheet.hairlineWidth, - borderTopColor: colors.disabled, - padding: 10, - }, - note: { - color: colors.text, - fontSize: textSizes.smallText, - marginBottom: 6, - }, - action: { - minHeight: MIN_TOUCH_SIZE, - borderRadius: 6, - backgroundColor: colors.buttonPrimary, - alignItems: 'center', - justifyContent: 'center', - paddingHorizontal: 10, - }, - actionText: { - color: colors.text, - fontSize: textSizes.subtitle, - fontWeight: '700', - textAlign: 'center', - }, footer: { color: colors.text, fontSize: textSizes.smallText, diff --git a/src/components/PairingSidePanel/PairingSidePanel.stories.tsx b/src/components/PairingSidePanel/PairingSidePanel.stories.tsx new file mode 100644 index 00000000..419c695f --- /dev/null +++ b/src/components/PairingSidePanel/PairingSidePanel.stories.tsx @@ -0,0 +1,62 @@ +import React from 'react' +import { View, Text, StyleSheet } from 'react-native' +import type { Meta, StoryObj } from '@storybook/react-native-web-vite'; +import { fn } from 'storybook/test'; +import { PairingSidePanel } from './PairingSidePanel' +import { PairingSidePanelAction } from './PairingSidePanelAction' +import { colors, textSizes } from '../../theme' + +const Body = () => ( + + The body + +) + +const meta: Meta = { + title: 'Components/PairingSidePanel', + component: PairingSidePanel, + args: { + title: 'A panel beside the tiles', + subline: 'A line under the title.', + onClose: fn(), + children: , + }, + decorators: [ + (Story) => ( + + + + ), + ], +} + +export default meta + +type Story = StoryObj + +export const Plain: Story = {} + +export const WithTitleNote: Story = { + args: { titleNote: '1 more' }, +} + +export const WithPinnedAction: Story = { + args: { pinned: }, +} + +// the panel's size on a 667 x 375 phone +const styles = StyleSheet.create({ + phone: { + width: 300, + height: 337, + backgroundColor: colors.background, + }, + body: { + flex: 1, + padding: 12, + }, + bodyText: { + color: colors.text, + fontSize: textSizes.smallText, + }, +}) diff --git a/src/components/PairingSidePanel/PairingSidePanel.test.tsx b/src/components/PairingSidePanel/PairingSidePanel.test.tsx new file mode 100644 index 00000000..ff7a5d3c --- /dev/null +++ b/src/components/PairingSidePanel/PairingSidePanel.test.tsx @@ -0,0 +1,46 @@ +import React from 'react' +import { Text } from 'react-native' +import { render, fireEvent } from '@testing-library/react-native' +import { PairingSidePanel } from './PairingSidePanel' +import { PairingSidePanelAction } from './PairingSidePanelAction' + +describe('PairingSidePanel', () => { + it('shows the title, the note beside it, the subline and the body', () => { + const { getByText } = render( + + Body + + ) + expect(getByText('A title')).toBeTruthy() + expect(getByText('2 more')).toBeTruthy() + expect(getByText('A subline')).toBeTruthy() + expect(getByText('Body')).toBeTruthy() + }) + + it('✕ calls onClose', () => { + const onClose = jest.fn() + const { getByLabelText } = render(Body) + fireEvent.press(getByLabelText('Close')) + expect(onClose).toHaveBeenCalledTimes(1) + }) + + it('shows the pinned area only when given', () => { + const without = render(Body) + expect(without.queryByTestId('pairing-side-panel-pinned')).toBeNull() + + const withPinned = render(Pinned}>Body) + expect(withPinned.getByTestId('pairing-side-panel-pinned')).toBeTruthy() + expect(withPinned.getByText('Pinned')).toBeTruthy() + }) +}) + +describe('PairingSidePanelAction', () => { + it('shows its note above the button and calls onPress', () => { + const onPress = jest.fn() + const { getByText, toJSON } = render() + const tree = JSON.stringify(toJSON()) + expect(tree.indexOf('A note')).toBeLessThan(tree.indexOf('Do it')) + fireEvent.press(getByText('Do it')) + expect(onPress).toHaveBeenCalledTimes(1) + }) +}) diff --git a/src/components/PairingSidePanel/PairingSidePanel.tsx b/src/components/PairingSidePanel/PairingSidePanel.tsx new file mode 100644 index 00000000..df3a46a6 --- /dev/null +++ b/src/components/PairingSidePanel/PairingSidePanel.tsx @@ -0,0 +1,91 @@ +import React from 'react' +import { View, Text, Pressable, StyleSheet } from 'react-native' + +import { colors, textSizes } from '../../theme' +import { PairingSidePanelProps } from './types' + +const MIN_TOUCH_SIZE = 48 + +/** + * The non-modal panel beside the tiles on the Pairing page: a header with the title and a close + * button, the body, and an optional area pinned at the bottom. The page shows one panel at a time in + * this slot - the helper or a device-selection conflict. + */ +export const PairingSidePanel = ({ title, titleNote, subline, onClose, children, pinned }: PairingSidePanelProps) => ( + + + + {title} + {titleNote ? {titleNote} : null} + + ✕ + + + {subline ? {subline} : null} + + + {children} + + {pinned ? ( + + {pinned} + + ) : null} + +) + +const styles = StyleSheet.create({ + panel: { + flex: 1, + backgroundColor: colors.helperPanelBackground, + borderLeftWidth: 3, + borderLeftColor: colors.pairingWaiting, + borderTopLeftRadius: 8, + borderBottomLeftRadius: 8, + }, + header: { + paddingLeft: 12, + paddingTop: 4, + }, + titleRow: { + flexDirection: 'row', + alignItems: 'center', + }, + title: { + flex: 1, + color: colors.text, + fontSize: textSizes.normalText, + fontWeight: '700', + }, + titleNote: { + color: colors.text, + fontSize: textSizes.smallText, + marginLeft: 6, + }, + close: { + width: MIN_TOUCH_SIZE, + height: MIN_TOUCH_SIZE, + alignItems: 'center', + justifyContent: 'center', + }, + closeText: { + color: colors.text, + fontSize: textSizes.normalText, + }, + subline: { + color: colors.text, + fontSize: textSizes.smallText, + paddingRight: 12, + paddingBottom: 6, + }, + pinned: { + borderTopWidth: StyleSheet.hairlineWidth, + borderTopColor: colors.disabled, + padding: 10, + }, +}) diff --git a/src/components/PairingSidePanel/PairingSidePanelAction.tsx b/src/components/PairingSidePanel/PairingSidePanelAction.tsx new file mode 100644 index 00000000..53553d36 --- /dev/null +++ b/src/components/PairingSidePanel/PairingSidePanelAction.tsx @@ -0,0 +1,42 @@ +import React from 'react' +import { Text, Pressable, StyleSheet } from 'react-native' + +import { colors, textSizes } from '../../theme' +import { PairingSidePanelActionProps } from './types' + +const MIN_TOUCH_SIZE = 48 + +/** + * The main button in a side panel's pinned area, with an optional line above it. The caller logs the + * press, since only it knows what the button stands for. + */ +export const PairingSidePanelAction = ({ label, note, onPress }: PairingSidePanelActionProps) => ( + <> + {note ? {note} : null} + + {label} + + +) + +const styles = StyleSheet.create({ + note: { + color: colors.text, + fontSize: textSizes.smallText, + marginBottom: 6, + }, + action: { + minHeight: MIN_TOUCH_SIZE, + borderRadius: 6, + backgroundColor: colors.buttonPrimary, + alignItems: 'center', + justifyContent: 'center', + paddingHorizontal: 10, + }, + actionText: { + color: colors.text, + fontSize: textSizes.subtitle, + fontWeight: '700', + textAlign: 'center', + }, +}) diff --git a/src/components/PairingSidePanel/index.ts b/src/components/PairingSidePanel/index.ts new file mode 100644 index 00000000..4a04df86 --- /dev/null +++ b/src/components/PairingSidePanel/index.ts @@ -0,0 +1,3 @@ +export * from './PairingSidePanel' +export * from './PairingSidePanelAction' +export * from './types' diff --git a/src/components/PairingSidePanel/types.ts b/src/components/PairingSidePanel/types.ts new file mode 100644 index 00000000..351ceb72 --- /dev/null +++ b/src/components/PairingSidePanel/types.ts @@ -0,0 +1,21 @@ +import type { ReactNode } from 'react' + +export interface PairingSidePanelProps { + title: string + /** a short line beside the title, e.g. how many more are waiting */ + titleNote?: string + subline?: string + /** the ✕ in the header */ + onClose: () => void + /** the panel's body; it takes the space between the header and the pinned area */ + children: ReactNode + /** pinned at the bottom, so a large font scale never pushes it off-screen */ + pinned?: ReactNode +} + +export interface PairingSidePanelActionProps { + label: string + /** a line shown above the button */ + note?: string + onPress: () => void +} diff --git a/src/components/index.ts b/src/components/index.ts index 73d32407..a07fdf15 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -5,6 +5,7 @@ export * from './CapabilityGrid' export * from './CapabilityStatusBars' export * from './PairingStatusLine' export * from './PairingHelperPanel' +export * from './PairingSidePanel' export * from './ExitButton' export * from './InterfaceState' export * from './DeviceEntry' From 0dece91d1378b0f665336e2f81c107b878a40f03 Mon Sep 17 00:00:00 2001 From: Guido Doumen Date: Mon, 9 Nov 2026 21:29:08 +0100 Subject: [PATCH 03/14] feat(pairing): ask which device to keep after a pick in the Resistance list When the page service sends a conflict step for the open device list, the list is replaced, in the same dialog, by one row per slot already held by a different device, each with a keep and a replace choice, and a Done button. Done applies the choices; a tap outside or the back button applies the choices made so far through the step's own dismiss handler. The deprecated "For all capabilities" switch is gone from the list: a tap on a device now picks it without any argument, and the page service decides what happens to the other slots. --- .../ConflictStepRows/ConflictChoiceOption.tsx | 83 +++++++++++ .../ConflictStepRows/ConflictStepRows.mock.ts | 72 ++++++++++ .../ConflictStepRows.stories.tsx | 43 ++++++ .../ConflictStepRows.test.tsx | 61 ++++++++ .../ConflictStepRows/ConflictStepRows.tsx | 41 ++++++ src/components/ConflictStepRows/index.ts | 2 + src/components/ConflictStepRows/types.ts | 7 + .../DeviceSelector/DeviceSelector.stories.tsx | 19 ++- .../DeviceSelector/DeviceSelector.test.tsx | 135 ++++++++++++++++-- .../DeviceSelector/DeviceSelector.tsx | 134 ++++++++--------- src/components/index.ts | 1 + 11 files changed, 517 insertions(+), 81 deletions(-) create mode 100644 src/components/ConflictStepRows/ConflictChoiceOption.tsx create mode 100644 src/components/ConflictStepRows/ConflictStepRows.mock.ts create mode 100644 src/components/ConflictStepRows/ConflictStepRows.stories.tsx create mode 100644 src/components/ConflictStepRows/ConflictStepRows.test.tsx create mode 100644 src/components/ConflictStepRows/ConflictStepRows.tsx create mode 100644 src/components/ConflictStepRows/index.ts create mode 100644 src/components/ConflictStepRows/types.ts diff --git a/src/components/ConflictStepRows/ConflictChoiceOption.tsx b/src/components/ConflictStepRows/ConflictChoiceOption.tsx new file mode 100644 index 00000000..3f090488 --- /dev/null +++ b/src/components/ConflictStepRows/ConflictChoiceOption.tsx @@ -0,0 +1,83 @@ +import React, { useCallback } from 'react' +import { View, Text, Pressable, StyleSheet } from 'react-native' +import type { ConflictChoice, ConflictStepProps, TIncyclistCapability } from 'incyclist-services' + +import { colors, textSizes } from '../../theme' +import { useLogging } from '../../hooks' + +const MIN_ROW_HEIGHT = 48 + +interface ConflictChoiceOptionProps { + capability: TIncyclistCapability + capabilityTitle: string + choice: ConflictChoice + label: string + selected: boolean + onChoice: ConflictStepProps['onChoice'] +} + +/** One of a slot's two choices: a radio-style row at least 48 high, the same as the helper's answers. */ +export const ConflictChoiceOption = ({ capability, capabilityTitle, choice, label, selected, onChoice }: ConflictChoiceOptionProps) => { + const { logEvent } = useLogging('ConflictStepRows') + + const onPress = useCallback(() => { + logEvent({ message: 'button clicked', button: 'conflict choice', capability, choice, eventSource: 'user' }) + onChoice(capability, choice) + }, [logEvent, onChoice, capability, choice]) + + return ( + + + {selected && } + + {label} + + ) +} + +const styles = StyleSheet.create({ + option: { + minHeight: MIN_ROW_HEIGHT, + flexDirection: 'row', + alignItems: 'center', + paddingHorizontal: 10, + paddingVertical: 6, + marginBottom: 6, + borderRadius: 6, + borderWidth: 1, + borderColor: colors.disabled, + }, + optionSelected: { + borderColor: colors.pairingWaiting, + }, + radio: { + width: 16, + height: 16, + borderRadius: 8, + borderWidth: 2, + borderColor: colors.text, + alignItems: 'center', + justifyContent: 'center', + marginRight: 10, + }, + radioSelected: { + borderColor: colors.pairingWaiting, + }, + radioDot: { + width: 8, + height: 8, + borderRadius: 4, + backgroundColor: colors.pairingWaiting, + }, + label: { + flex: 1, + color: colors.text, + fontSize: textSizes.subtitle, + }, +}) diff --git a/src/components/ConflictStepRows/ConflictStepRows.mock.ts b/src/components/ConflictStepRows/ConflictStepRows.mock.ts new file mode 100644 index 00000000..f96c38be --- /dev/null +++ b/src/components/ConflictStepRows/ConflictStepRows.mock.ts @@ -0,0 +1,72 @@ +import type { ConflictChoice, ConflictStepProps, ConflictStepRowProps, TIncyclistCapability } from 'incyclist-services' + +// Fixtures with the page service's copy, for tests and stories. Callbacks default to no-ops; pass +// spies (jest.fn() in tests, fn() in stories) to observe them. + +type Noop = () => void +const noop: Noop = () => {} + +export interface MockConflictHandlers { + onChoice?: (capability: TIncyclistCapability, choice: ConflictChoice) => void + onDone?: Noop + onDismiss?: Noop +} + +const NEW_DEVICE = 'Tacx Neo 2T' + +const row = (capability: TIncyclistCapability, capabilityTitle: string, currentName: string, choice: ConflictChoice = 'keep'): ConflictStepRowProps => ({ + capability, + capabilityTitle, + currentName, + choice, + keepLabel: `Keep ${currentName}`, + replaceLabel: `Use ${NEW_DEVICE}`, +}) + +/** A trainer found by the search wants Power and Cadence, which other devices already hold. */ +export const buildDetectionConflict = (h: MockConflictHandlers = {}, choices: Partial> = {}): ConflictStepProps => ({ + id: 'conflict-1', + origin: 'detection', + deviceName: NEW_DEVICE, + title: `${NEW_DEVICE} can also measure more`, + subline: { + full: 'Resistance was free and now uses it. Choose for the rest; nothing changes until you do.', + short: 'Nothing changes until you choose.', + }, + rows: [ + row('power', 'Power', 'Stages Power', choices.power), + row('cadence', 'Cadence', 'Wahoo RPM', choices.cadence), + ], + queued: 0, + onChoice: h.onChoice ?? noop, + onDone: h.onDone ?? noop, + onDismiss: h.onDismiss ?? noop, +}) + +/** The same card, with two more conflicts waiting behind it. */ +export const buildQueuedDetectionConflict = (h: MockConflictHandlers = {}): ConflictStepProps => ({ + ...buildDetectionConflict(h), + queued: 2, + queuedText: '2 more', +}) + +/** The rider picked a trainer in the Resistance list, and it would take Power, Speed and Cadence from other devices. */ +export const buildManualConflict = (h: MockConflictHandlers = {}, choices: Partial> = {}): ConflictStepProps => ({ + id: 'conflict-2', + origin: 'manual', + deviceName: NEW_DEVICE, + title: `${NEW_DEVICE} can also measure more`, + subline: { + full: 'Choose which device to use for each.', + short: 'Choose which device to use for each.', + }, + rows: [ + row('power', 'Power', 'Stages Power', choices.power), + row('speed', 'Speed', 'Wahoo Speed', choices.speed), + row('cadence', 'Cadence', 'Wahoo RPM', choices.cadence), + ], + queued: 0, + onChoice: h.onChoice ?? noop, + onDone: h.onDone ?? noop, + onDismiss: h.onDismiss ?? noop, +}) diff --git a/src/components/ConflictStepRows/ConflictStepRows.stories.tsx b/src/components/ConflictStepRows/ConflictStepRows.stories.tsx new file mode 100644 index 00000000..a43ea15b --- /dev/null +++ b/src/components/ConflictStepRows/ConflictStepRows.stories.tsx @@ -0,0 +1,43 @@ +import React from 'react' +import { View, StyleSheet } from 'react-native' +import type { Meta, StoryObj } from '@storybook/react-native-web-vite'; +import { fn } from 'storybook/test'; +import { ConflictStepRows } from './ConflictStepRows' +import { colors } from '../../theme' +import { buildDetectionConflict, buildManualConflict } from './ConflictStepRows.mock' + +const meta: Meta = { + title: 'Components/ConflictStepRows', + component: ConflictStepRows, + args: { + onChoice: fn(), + }, + decorators: [ + (Story) => ( + + + + ), + ], +} + +export default meta + +type Story = StoryObj + +export const KeepEverything: Story = { + args: { rows: buildDetectionConflict().rows }, +} + +export const OneReplaced: Story = { + args: { rows: buildManualConflict({}, { speed: 'replace' }).rows }, +} + +// the width of the panel beside the tiles on a phone +const styles = StyleSheet.create({ + decorator: { + width: 300, + padding: 12, + backgroundColor: colors.helperPanelBackground, + }, +}) diff --git a/src/components/ConflictStepRows/ConflictStepRows.test.tsx b/src/components/ConflictStepRows/ConflictStepRows.test.tsx new file mode 100644 index 00000000..9ab792a3 --- /dev/null +++ b/src/components/ConflictStepRows/ConflictStepRows.test.tsx @@ -0,0 +1,61 @@ +import React from 'react' +import { render, fireEvent } from '@testing-library/react-native' +import { ConflictStepRows } from './ConflictStepRows' +import { buildDetectionConflict, buildManualConflict } from './ConflictStepRows.mock' + +const mockLogEvent = jest.fn() +jest.mock('../../hooks', () => ({ + useLogging: () => ({ logEvent: mockLogEvent }), +})) + +describe('ConflictStepRows', () => { + + afterEach(() => { + jest.clearAllMocks() + }) + + it('shows one row per slot, each with its title and both choices', () => { + const { rows, onChoice } = buildManualConflict() + const { getByText, getAllByText } = render() + + expect(getByText('POWER')).toBeTruthy() + expect(getByText('SPEED')).toBeTruthy() + expect(getByText('CADENCE')).toBeTruthy() + expect(getByText('Keep Stages Power')).toBeTruthy() + expect(getByText('Keep Wahoo Speed')).toBeTruthy() + expect(getAllByText('Use Tacx Neo 2T')).toHaveLength(3) + }) + + it('marks the choice each row has, keep by default', () => { + const { rows, onChoice } = buildDetectionConflict({}, { cadence: 'replace' }) + const { getByLabelText } = render() + + expect(getByLabelText('Power: Keep Stages Power').props.accessibilityState).toEqual({ selected: true }) + expect(getByLabelText('Power: Use Tacx Neo 2T').props.accessibilityState).toEqual({ selected: false }) + expect(getByLabelText('Cadence: Keep Wahoo RPM').props.accessibilityState).toEqual({ selected: false }) + expect(getByLabelText('Cadence: Use Tacx Neo 2T').props.accessibilityState).toEqual({ selected: true }) + }) + + it('a tap on a choice reports the slot and the choice, and logs it', () => { + const onChoice = jest.fn() + const { rows } = buildDetectionConflict({ onChoice }) + const { getByLabelText } = render() + + fireEvent.press(getByLabelText('Cadence: Use Tacx Neo 2T')) + expect(onChoice).toHaveBeenCalledWith('cadence', 'replace') + + fireEvent.press(getByLabelText('Power: Keep Stages Power')) + expect(onChoice).toHaveBeenCalledWith('power', 'keep') + + expect(onChoice).toHaveBeenCalledTimes(2) + expect(mockLogEvent).toHaveBeenCalledWith(expect.objectContaining({ message: 'button clicked', button: 'conflict choice', capability: 'cadence', choice: 'replace' })) + }) + + it('renders no buttons of its own beyond the two choices per row', () => { + const { rows, onChoice } = buildManualConflict() + const { getAllByRole, queryAllByRole } = render() + + expect(getAllByRole('radio')).toHaveLength(rows.length * 2) + expect(queryAllByRole('button')).toHaveLength(0) + }) +}) diff --git a/src/components/ConflictStepRows/ConflictStepRows.tsx b/src/components/ConflictStepRows/ConflictStepRows.tsx new file mode 100644 index 00000000..a164aaa6 --- /dev/null +++ b/src/components/ConflictStepRows/ConflictStepRows.tsx @@ -0,0 +1,41 @@ +import React from 'react' +import { View, Text, StyleSheet } from 'react-native' + +import { colors, textSizes } from '../../theme' +import { ConflictChoiceOption } from './ConflictChoiceOption' +import { ConflictStepRowsProps } from './types' + +/** + * The rows of a device-selection conflict: one per slot that already holds a different device, each + * with its title and the two choices (keep the current device, or use the new one) stacked under it. + * The same rows show in the conflict card beside the tiles and in the Resistance list's second step. + */ +export const ConflictStepRows = ({ rows, onChoice }: ConflictStepRowsProps) => ( + + {rows.map(row => ( + + {row.capabilityTitle.toUpperCase()} + + + + ))} + +) + +const styles = StyleSheet.create({ + row: { + marginBottom: 6, + }, + rowTitle: { + color: colors.text, + fontSize: textSizes.smallText, + fontWeight: '700', + marginBottom: 4, + }, +}) diff --git a/src/components/ConflictStepRows/index.ts b/src/components/ConflictStepRows/index.ts new file mode 100644 index 00000000..6ace5de6 --- /dev/null +++ b/src/components/ConflictStepRows/index.ts @@ -0,0 +1,2 @@ +export * from './ConflictStepRows' +export * from './types' diff --git a/src/components/ConflictStepRows/types.ts b/src/components/ConflictStepRows/types.ts new file mode 100644 index 00000000..a50387ad --- /dev/null +++ b/src/components/ConflictStepRows/types.ts @@ -0,0 +1,7 @@ +import type { ConflictStepProps, ConflictStepRowProps } from 'incyclist-services' + +export interface ConflictStepRowsProps { + /** one row per slot, as the page service gives them */ + rows: ReadonlyArray + onChoice: ConflictStepProps['onChoice'] +} diff --git a/src/components/DeviceSelector/DeviceSelector.stories.tsx b/src/components/DeviceSelector/DeviceSelector.stories.tsx index a7223878..a72447d8 100644 --- a/src/components/DeviceSelector/DeviceSelector.stories.tsx +++ b/src/components/DeviceSelector/DeviceSelector.stories.tsx @@ -4,6 +4,7 @@ import { View } from 'react-native'; import { DeviceSelector } from './DeviceSelector'; import { DeviceSelectionProps, TIncyclistCapability } from 'incyclist-services'; import { fn } from 'storybook/test'; +import { buildManualConflict } from '../ConflictStepRows/ConflictStepRows.mock'; export const defaultArgs: DeviceSelectionProps = { capability: 'control' as TIncyclistCapability, @@ -62,8 +63,7 @@ export const Disabled: Story = { }; // Regression case for the scroll/overlap bug: with enough entries to overflow the list's -// maxHeight, the last entries must remain reachable by scrolling and must not render hidden -// underneath the "For all capabilities" / "Disable All" footer bar. +// maxHeight, the last entries must remain reachable by scrolling. export const LongList: Story = { args: { ...Default.args, @@ -76,4 +76,19 @@ export const LongList: Story = { onDelete: () => {}, })), }, +}; + +// The second step after a pick in the Resistance list that would take slots held by other devices +export const ConflictStep: Story = { + args: { + ...Default.args, + conflictStep: buildManualConflict({ onChoice: fn(), onDone: fn(), onDismiss: fn() }), + }, +}; + +export const ConflictStepOneReplaced: Story = { + args: { + ...Default.args, + conflictStep: buildManualConflict({ onChoice: fn(), onDone: fn(), onDismiss: fn() }, { power: 'replace' }), + }, }; \ No newline at end of file diff --git a/src/components/DeviceSelector/DeviceSelector.test.tsx b/src/components/DeviceSelector/DeviceSelector.test.tsx index 47eda8af..fe32932e 100644 --- a/src/components/DeviceSelector/DeviceSelector.test.tsx +++ b/src/components/DeviceSelector/DeviceSelector.test.tsx @@ -1,8 +1,21 @@ import React from 'react'; -import { render } from '@testing-library/react-native'; -import { ScrollView } from 'react-native'; +import { render, fireEvent } from '@testing-library/react-native'; +import { Modal, ScrollView } from 'react-native'; import { DeviceSelector } from './DeviceSelector'; import { DeviceSelectionItemProps, DeviceSelectionProps, TIncyclistCapability } from 'incyclist-services'; +import { buildManualConflict } from '../ConflictStepRows/ConflictStepRows.mock'; + +const mockDimensions = { width: 800, height: 360 }; +jest.mock('react-native/Libraries/Utilities/useWindowDimensions', () => ({ + default: jest.fn(() => mockDimensions), +})); + +const setDimensions = (width: number, height: number) => { + mockDimensions.width = width; + mockDimensions.height = height; +}; +const PHONE: [number, number] = [800, 360]; +const TABLET: [number, number] = [1280, 800]; const buildDevice = (i: number): DeviceSelectionItemProps => ({ deviceName: `Device ${i}`, @@ -13,7 +26,7 @@ const buildDevice = (i: number): DeviceSelectionItemProps => ({ onDelete: jest.fn(), }); -const buildProps = (deviceCount: number): DeviceSelectionProps => ({ +const buildProps = (deviceCount: number, extra: Partial = {}): DeviceSelectionProps => ({ capability: 'control' as TIncyclistCapability, devices: Array.from({ length: deviceCount }, (_, i) => buildDevice(i)), isScanning: false, @@ -21,9 +34,14 @@ const buildProps = (deviceCount: number): DeviceSelectionProps => ({ changeForAll: true, canSelectAll: true, onClose: jest.fn(), + ...extra, }); describe('DeviceSelector', () => { + beforeEach(() => { + setDimensions(...PHONE); + }); + it('renders without crashing for a short device list', () => { const { getByText } = render(); expect(getByText('Device 0')).toBeTruthy(); @@ -38,23 +56,110 @@ describe('DeviceSelector', () => { expect(getByText('Device 29')).toBeTruthy(); }); - it('gives the device list ScrollView bottom padding matching the footer height, so the last entries clear it', () => { + it('lists the devices in a single ScrollView of its own - Dialog\'s is disabled', () => { const { UNSAFE_root } = render(); - const scrollViews = UNSAFE_root.findAllByType(ScrollView); - expect(scrollViews.length).toBe(1); // only DeviceSelector's own list ScrollView - Dialog's is disabled + expect(UNSAFE_root.findAllByType(ScrollView).length).toBe(1); + }); + + it('has no "For all capabilities" switch and no "Don\'t use" tick, even where the deprecated props still ask for one', () => { + const { queryByText, queryByRole } = render(); + expect(queryByText(/for all/i)).toBeNull(); + expect(queryByText(/Don't use/)).toBeNull(); + expect(queryByRole('checkbox')).toBeNull(); + expect(queryByRole('switch')).toBeNull(); + }); - const contentContainerStyle = scrollViews[0].props.contentContainerStyle; - const flatStyle = Array.isArray(contentContainerStyle) - ? Object.assign({}, ...contentContainerStyle) - : contentContainerStyle; + it('a tap on a device picks it, without any "for all" argument', () => { + const props = buildProps(3, { canSelectAll: true, changeForAll: true }); + const { getByText } = render(); - expect(flatStyle.paddingBottom).toBeGreaterThanOrEqual(60); + fireEvent.press(getByText('Device 1')); + + expect(props.devices[1].onClick).toHaveBeenCalledTimes(1); + expect(props.devices[1].onClick).toHaveBeenCalledWith(); }); - it('renders "For all capabilities" and no "Don\'t use" tick, since unselecting is done from the tile', () => { - const { getByText, queryByText } = render(); - expect(getByText('For all capabilities')).toBeTruthy(); - expect(queryByText(/Don't use/)).toBeNull(); + it('a tap outside closes the list', () => { + const props = buildProps(3); + const { UNSAFE_root } = render(); + + UNSAFE_root.findByType(Modal).props.onRequestClose(); + + expect(props.onClose).toHaveBeenCalledTimes(1); + }); +}); + +describe('DeviceSelector conflict step', () => { + beforeEach(() => { + setDimensions(...PHONE); + }); + + it('replaces the list with the step: title, rows and Done', () => { + const conflictStep = buildManualConflict(); + const { getByText, queryByText, getAllByText } = render(); + + expect(getByText('Tacx Neo 2T can also measure more')).toBeTruthy(); + expect(getByText('Keep Stages Power')).toBeTruthy(); + expect(getByText('Keep Wahoo Speed')).toBeTruthy(); + expect(getAllByText('Use Tacx Neo 2T')).toHaveLength(3); + expect(getByText('Done')).toBeTruthy(); + expect(queryByText('Device 0')).toBeNull(); + expect(queryByText('Select Device')).toBeNull(); + }); + + it('shows the phone subline on a phone, the full one on a tablet', () => { + const conflictStep = { ...buildManualConflict(), subline: { full: 'The full line', short: 'The short line' } }; + + const phone = render(); + expect(phone.getByText('The short line')).toBeTruthy(); + expect(phone.queryByText('The full line')).toBeNull(); + + setDimensions(...TABLET); + const tablet = render(); + expect(tablet.getByText('The full line')).toBeTruthy(); + }); + + it('a choice is passed on as given', () => { + const onChoice = jest.fn(); + const { getByLabelText } = render(); + + fireEvent.press(getByLabelText('Speed: Use Tacx Neo 2T')); + + expect(onChoice).toHaveBeenCalledWith('speed', 'replace'); + }); + + it('Done commits the choices', () => { + const onDone = jest.fn(); + const onDismiss = jest.fn(); + const props = buildProps(3, { conflictStep: buildManualConflict({ onDone, onDismiss }) }); + const { getByText } = render(); + + fireEvent.press(getByText('Done')); + + expect(onDone).toHaveBeenCalledTimes(1); + expect(onDismiss).not.toHaveBeenCalled(); + expect(props.onClose).not.toHaveBeenCalled(); + }); + + it('a tap outside or the back button applies the choices made so far, through the step', () => { + const onDone = jest.fn(); + const onDismiss = jest.fn(); + const props = buildProps(3, { conflictStep: buildManualConflict({ onDone, onDismiss }) }); + const { UNSAFE_root } = render(); + + UNSAFE_root.findByType(Modal).props.onRequestClose(); + + expect(onDismiss).toHaveBeenCalledTimes(1); + expect(onDone).not.toHaveBeenCalled(); + expect(props.onClose).not.toHaveBeenCalled(); + }); + + it('has Done as its only button', () => { + const { getAllByRole, getAllByText } = render(); + + // the dialog's buttons are plain touchables; Done is the only text that isn't a row or the copy + expect(getAllByText('Done')).toHaveLength(1); + expect(getAllByRole('radio')).toHaveLength(6); }); }); diff --git a/src/components/DeviceSelector/DeviceSelector.tsx b/src/components/DeviceSelector/DeviceSelector.tsx index e5a0b95c..959eb640 100644 --- a/src/components/DeviceSelector/DeviceSelector.tsx +++ b/src/components/DeviceSelector/DeviceSelector.tsx @@ -1,77 +1,97 @@ -import React, { FC, useState } from 'react'; -import { View, StyleSheet, ScrollView, useWindowDimensions } from 'react-native'; +import React, { FC, useCallback, useMemo } from 'react'; +import { View, Text, StyleSheet, ScrollView, useWindowDimensions } from 'react-native'; import DeviceEntry from '../DeviceEntry'; -import { DeviceSelectionItemProps, DeviceSelectionProps } from 'incyclist-services'; -import { textSizes } from '../../theme'; +import { ConflictStepProps, DeviceSelectionItemProps, DeviceSelectionProps } from 'incyclist-services'; +import { colors, textSizes } from '../../theme'; +import { useScreenLayout } from '../../hooks'; import { Dialog } from '../Dialog'; -import { BinarySelect } from '../BinarySelect'; +import { ButtonProps } from '../ButtonBar/types'; +import { ConflictStepRows } from '../ConflictStepRows'; +const DONE_LABEL = 'Done'; + +interface ConflictStepBodyProps { + step: ConflictStepProps + compact: boolean +} + +// the list's second step: which device each slot held by another device should use +const ConflictStepBody = ({ step, compact }: ConflictStepBodyProps) => ( + + {compact ? step.subline.short : step.subline.full} + + +); + +/** + * The device list of one capability. After a pick in the Resistance list that would take slots held + * by a different device, the page service sends a conflict step: it replaces the list in the same + * dialog until Done, or a tap outside / the back button, which both apply the choices made so far. + */ export const DeviceSelector: FC = ({ devices, isScanning, - changeForAll, - canSelectAll, + conflictStep, onClose, }) => { const { width: screenWidth, height: screenHeight } = useWindowDimensions(); + const compact = useScreenLayout() === 'compact'; const targetWidth = textSizes.listEntry * 0.6 * 40; // ~288dp const dialogWidth = Math.min(0.9 * screenWidth, targetWidth); const minHeightLeft = screenHeight - (textSizes.dialogTitle + 100 + 80 + 8); const deviceListMinHeight = Math.min(380, minHeightLeft); - const [all, setAll] = useState(canSelectAll && changeForAll); - const onDeviceClicked = (device: DeviceSelectionItemProps) => { - if (device.onClick) { - device.onClick(all); - } + device.onClick?.(); }; - const onDialogClosed = () => { - onClose(); - }; + const onOutsideClick = useCallback(() => { + if (conflictStep) + conflictStep.onDismiss(); + else + onClose(); + }, [conflictStep, onClose]); + + const stepButtons = useMemo(() => conflictStep + ? [{ id: 'conflict-done', label: DONE_LABEL, primary: true, onClick: conflictStep.onDone }] + : undefined + , [conflictStep]); const dialogStyle = [styles.dialog, { width: dialogWidth }]; const deviceListStyle = [styles.deviceList, { minHeight: deviceListMinHeight }]; + let title = isScanning ? 'Searching ...' : 'Select Device'; + if (conflictStep) + title = conflictStep.title; + return ( - - - {devices.map((device) => ( - onDeviceClicked(device)} - /> - ))} - - - - {canSelectAll && ( - - + ) : ( + + + {devices.map((device) => ( + onDeviceClicked(device)} /> - - )} + ))} + - + )} ); }; -const FOOTER_HEIGHT = 60; - const styles = StyleSheet.create({ dialog: { // Dynamic width applied via inline style @@ -89,27 +109,13 @@ const styles = StyleSheet.create({ maxHeight: 380, // Dynamic minHeight applied via inline style }, - // Reserves space at the bottom of the scrollable content so the last device entries clear - // the footer bar, which is absolutely positioned over the bottom of `modalView`. - deviceListContent: { - paddingBottom: FOOTER_HEIGHT, + stepView: { + paddingHorizontal: 8, + paddingTop: 4, }, - footer: { - flexDirection: 'row', - height: FOOTER_HEIGHT, - width: '100%', - position: 'absolute', - left: 0, - bottom: 0, - paddingHorizontal: 15, - borderTopWidth: 1, - borderTopColor: '#553388', - alignItems: 'center', - }, - checkboxContainer: { - flex: 1, - flexDirection: 'row', - alignItems: 'center', - marginRight: 4, + stepSubline: { + color: colors.text, + fontSize: textSizes.smallText, + marginBottom: 10, }, -}); \ No newline at end of file +}); diff --git a/src/components/index.ts b/src/components/index.ts index a07fdf15..e4f5166c 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -6,6 +6,7 @@ export * from './CapabilityStatusBars' export * from './PairingStatusLine' export * from './PairingHelperPanel' export * from './PairingSidePanel' +export * from './ConflictStepRows' export * from './ExitButton' export * from './InterfaceState' export * from './DeviceEntry' From 322501840d78f293155d8b362778ca423462e1ef Mon Sep 17 00:00:00 2001 From: Guido Doumen Date: Mon, 9 Nov 2026 21:29:32 +0100 Subject: [PATCH 04/14] feat(pairing): show a device-selection conflict as a card beside the tiles When the page service gives a pending conflict (a device found by the search wants slots another device holds), it is rendered as a card in the panel slot the helper uses: the title with how many more wait, the subline (phone or full copy), one row per slot with keep/replace, Done pinned at the bottom and a close button that keeps every current device. The card is non-modal, so the page's own buttons stay usable, and on a phone the required row collapses to status bars as it does for the helper. The page renders the card whenever it is given; the page service decides when. Tests now also guard that the page shows exactly the buttons the page service gives, and that no state of the page - helper, fallback, conflict card or the list's conflict step - shows a "try again" button. --- .../PairingConflictCard.stories.tsx | 58 ++++++ .../PairingConflictCard.test.tsx | 79 ++++++++ .../PairingConflictCard.tsx | 56 ++++++ src/components/PairingConflictCard/index.ts | 2 + src/components/PairingConflictCard/types.ts | 8 + src/components/index.ts | 1 + src/pages/PairingPage/PairingPage.mock.ts | 23 +++ src/pages/PairingPage/PairingPage.stories.tsx | 58 +++++- src/pages/PairingPage/View.test.tsx | 176 +++++++++++++++++- src/pages/PairingPage/View.tsx | 23 ++- 10 files changed, 469 insertions(+), 15 deletions(-) create mode 100644 src/components/PairingConflictCard/PairingConflictCard.stories.tsx create mode 100644 src/components/PairingConflictCard/PairingConflictCard.test.tsx create mode 100644 src/components/PairingConflictCard/PairingConflictCard.tsx create mode 100644 src/components/PairingConflictCard/index.ts create mode 100644 src/components/PairingConflictCard/types.ts create mode 100644 src/pages/PairingPage/PairingPage.mock.ts diff --git a/src/components/PairingConflictCard/PairingConflictCard.stories.tsx b/src/components/PairingConflictCard/PairingConflictCard.stories.tsx new file mode 100644 index 00000000..d494094e --- /dev/null +++ b/src/components/PairingConflictCard/PairingConflictCard.stories.tsx @@ -0,0 +1,58 @@ +import React from 'react' +import { View, StyleSheet } from 'react-native' +import type { Meta, StoryObj } from '@storybook/react-native-web-vite'; +import { fn } from 'storybook/test'; +import { PairingConflictCard } from './PairingConflictCard' +import { colors } from '../../theme' +import { buildDetectionConflict, buildQueuedDetectionConflict } from '../ConflictStepRows/ConflictStepRows.mock' + +const handlers = () => ({ onChoice: fn(), onDone: fn(), onDismiss: fn() }) + +const meta: Meta = { + title: 'Components/PairingConflictCard', + component: PairingConflictCard, + args: { + layout: 'phone', + }, + decorators: [ + (Story, ctx) => ( + + + + ), + ], +} + +export default meta + +type Story = StoryObj + +export const Phone: Story = { + args: { conflict: buildDetectionConflict(handlers()) }, +} + +export const PhoneOneReplaced: Story = { + args: { conflict: buildDetectionConflict(handlers(), { power: 'replace' }) }, +} + +export const PhoneMoreWaiting: Story = { + args: { conflict: buildQueuedDetectionConflict(handlers()) }, +} + +export const Tablet: Story = { + args: { conflict: buildDetectionConflict(handlers()), layout: 'tablet' }, +} + +// the panel's size on a 667 x 375 phone, and on a tablet, below the page title +const styles = StyleSheet.create({ + phone: { + width: 300, + height: 337, + backgroundColor: colors.background, + }, + tablet: { + width: 320, + height: 470, + backgroundColor: colors.background, + }, +}) diff --git a/src/components/PairingConflictCard/PairingConflictCard.test.tsx b/src/components/PairingConflictCard/PairingConflictCard.test.tsx new file mode 100644 index 00000000..96691c03 --- /dev/null +++ b/src/components/PairingConflictCard/PairingConflictCard.test.tsx @@ -0,0 +1,79 @@ +import React from 'react' +import { render, fireEvent, within } from '@testing-library/react-native' +import { PairingConflictCard } from './PairingConflictCard' +import { buildDetectionConflict, buildQueuedDetectionConflict } from '../ConflictStepRows/ConflictStepRows.mock' + +const mockLogEvent = jest.fn() +jest.mock('../../hooks', () => ({ + useLogging: () => ({ logEvent: mockLogEvent }), +})) + +describe('PairingConflictCard', () => { + + afterEach(() => { + jest.clearAllMocks() + }) + + it('shows the title, the phone subline and the rows on a phone', () => { + const conflict = buildDetectionConflict() + const { getByText, queryByText } = render() + + expect(getByText('Tacx Neo 2T can also measure more')).toBeTruthy() + expect(getByText(conflict.subline.short)).toBeTruthy() + expect(queryByText(conflict.subline.full)).toBeNull() + expect(getByText('Keep Stages Power')).toBeTruthy() + expect(getByText('Keep Wahoo RPM')).toBeTruthy() + }) + + it('shows the full subline on a tablet', () => { + const conflict = buildDetectionConflict() + const { getByText } = render() + + expect(getByText(conflict.subline.full)).toBeTruthy() + }) + + it('says how many more conflicts wait, only when some do', () => { + const queued = render() + expect(queued.getByText('2 more')).toBeTruthy() + + const single = render() + expect(single.queryByText('stale')).toBeNull() + }) + + it('Done is pinned and applies the choices', () => { + const onDone = jest.fn() + const { getByTestId } = render() + + fireEvent.press(within(getByTestId('pairing-side-panel-pinned')).getByText('Done')) + + expect(onDone).toHaveBeenCalledTimes(1) + expect(mockLogEvent).toHaveBeenCalledWith(expect.objectContaining({ message: 'button clicked', button: 'conflict done' })) + }) + + it('✕ dismisses the card', () => { + const onDismiss = jest.fn() + const onDone = jest.fn() + const { getByLabelText } = render() + + fireEvent.press(getByLabelText('Close')) + + expect(onDismiss).toHaveBeenCalledTimes(1) + expect(onDone).not.toHaveBeenCalled() + expect(mockLogEvent).toHaveBeenCalledWith(expect.objectContaining({ message: 'button clicked', button: 'conflict close' })) + }) + + it('a choice is passed on as given', () => { + const onChoice = jest.fn() + const { getByLabelText } = render() + + fireEvent.press(getByLabelText('Power: Use Tacx Neo 2T')) + + expect(onChoice).toHaveBeenCalledWith('power', 'replace') + }) + + it('has exactly two buttons: ✕ and Done', () => { + const { getAllByRole } = render() + + expect(getAllByRole('button').map(b => b.props.accessibilityLabel ?? within(b).queryByText(/./)?.props.children)).toEqual(['Close', 'Done']) + }) +}) diff --git a/src/components/PairingConflictCard/PairingConflictCard.tsx b/src/components/PairingConflictCard/PairingConflictCard.tsx new file mode 100644 index 00000000..245e8d43 --- /dev/null +++ b/src/components/PairingConflictCard/PairingConflictCard.tsx @@ -0,0 +1,56 @@ +import React, { useCallback } from 'react' +import { ScrollView, StyleSheet } from 'react-native' + +import { useLogging } from '../../hooks' +import { PairingSidePanel, PairingSidePanelAction } from '../PairingSidePanel' +import { ConflictStepRows } from '../ConflictStepRows' +import { PairingConflictCardProps } from './types' + +const DONE_LABEL = 'Done' + +/** + * A device found by the search wants slots that already hold a different device: the rider picks, + * per slot, which device to keep. Shown in the panel beside the tiles, non-modal, so the page's own + * buttons stay usable. ✕ keeps every current device; Done applies the choices. + */ +export const PairingConflictCard = ({ conflict, layout }: PairingConflictCardProps) => { + const { logEvent } = useLogging('PairingConflictCard') + + const onClose = useCallback(() => { + logEvent({ message: 'button clicked', button: 'conflict close', eventSource: 'user' }) + conflict.onDismiss() + }, [conflict, logEvent]) + + const onDone = useCallback(() => { + logEvent({ message: 'button clicked', button: 'conflict done', eventSource: 'user' }) + conflict.onDone() + }, [conflict, logEvent]) + + const subline = layout === 'phone' ? conflict.subline.short : conflict.subline.full + const titleNote = conflict.queued > 0 ? conflict.queuedText : undefined + + return ( + } + > + + + + + ) +} + +const styles = StyleSheet.create({ + body: { + flex: 1, + }, + bodyContent: { + paddingHorizontal: 12, + paddingTop: 6, + paddingBottom: 6, + }, +}) diff --git a/src/components/PairingConflictCard/index.ts b/src/components/PairingConflictCard/index.ts new file mode 100644 index 00000000..c2eb74ba --- /dev/null +++ b/src/components/PairingConflictCard/index.ts @@ -0,0 +1,2 @@ +export * from './PairingConflictCard' +export * from './types' diff --git a/src/components/PairingConflictCard/types.ts b/src/components/PairingConflictCard/types.ts new file mode 100644 index 00000000..885408a5 --- /dev/null +++ b/src/components/PairingConflictCard/types.ts @@ -0,0 +1,8 @@ +import type { ConflictStepProps } from 'incyclist-services' + +export interface PairingConflictCardProps { + /** the conflict as the page service gives it */ + conflict: ConflictStepProps + /** `phone`: the short subline; `tablet`: the full one */ + layout: 'phone' | 'tablet' +} diff --git a/src/components/index.ts b/src/components/index.ts index e4f5166c..9e354ff9 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -6,6 +6,7 @@ export * from './CapabilityStatusBars' export * from './PairingStatusLine' export * from './PairingHelperPanel' export * from './PairingSidePanel' +export * from './PairingConflictCard' export * from './ConflictStepRows' export * from './ExitButton' export * from './InterfaceState' diff --git a/src/pages/PairingPage/PairingPage.mock.ts b/src/pages/PairingPage/PairingPage.mock.ts new file mode 100644 index 00000000..49e0e310 --- /dev/null +++ b/src/pages/PairingPage/PairingPage.mock.ts @@ -0,0 +1,23 @@ +import type { PairingButtonProps } from 'incyclist-services' + +// Fixtures for tests and stories: every button set the page service gives the Pairing page, with the +// labels it uses (OK/Skip outside a ride, Start/Cancel when pairing for a ride). Callbacks resolve to +// nothing; tests and stories that want to observe a press build their own set. + +type Button = PairingButtonProps[number] + +const noop = async () => {} +const button = (label: string, primary: boolean): Button => ({ label, primary, onClick: noop }) + +export const MOCK_PAIRING_BUTTON_SETS: Record = { + 'searching, something to ride with found': [button('Stop searching', true), button('Skip', false)], + 'searching for a ride, something to ride with found': [button('Stop searching', true), button('Cancel', false)], + 'ready': [button('OK', true)], + 'ready for a ride': [button('Start', true)], + 'ready, search ended without a trainer': [button('OK', true), button('Search again', false)], + 'ready for a ride, search ended without a trainer': [button('Start', true), button('Search again', false)], + 'not ready, nothing found': [button('Search again', true), button('Skip', false)], + 'not ready': [button('Skip', true)], + 'not ready for a ride, nothing found': [button('Search again', true), button('Simulate', false), button('Cancel', false)], + 'not ready for a ride': [button('Simulate', true), button('Cancel', false)], +} diff --git a/src/pages/PairingPage/PairingPage.stories.tsx b/src/pages/PairingPage/PairingPage.stories.tsx index c334005b..885b8c7e 100644 --- a/src/pages/PairingPage/PairingPage.stories.tsx +++ b/src/pages/PairingPage/PairingPage.stories.tsx @@ -4,11 +4,15 @@ import { View as PairingPage } from 'react-native'; import { PairingPageView } from './View'; import { defaultArgs as deviceSelectorArgs } from '../../components/DeviceSelector/DeviceSelector.stories'; import { - buildAsleepHelper, buildNoDeviceHelper, buildNoTrainerHelper, buildTrainerUnavailableHelper, + buildAsleepHelper, buildFallbackHelper, buildNoDeviceHelper, buildNoTrainerHelper, buildTrainerUnavailableHelper, } from '../../components/PairingHelperPanel/PairingHelperPanel.mock'; import { - MOCK_CAPABILITIES_HEARTRATE_ONLY, MOCK_CAPABILITIES_SEARCHING, MOCK_CAPABILITIES_TRAINER_CONNECTING, MOCK_CAPABILITIES_TRAINER_UNAVAILABLE, + MOCK_CAPABILITIES_FALLBACK, MOCK_CAPABILITIES_HEARTRATE_ONLY, MOCK_CAPABILITIES_SEARCHING, MOCK_CAPABILITIES_SWITCHED_OFF, + MOCK_CAPABILITIES_TRAINER_CONNECTING, MOCK_CAPABILITIES_TRAINER_UNAVAILABLE, } from '../../components/CapabilityStatusBars/CapabilityStatusBars.mock'; +import { + buildDetectionConflict, buildManualConflict, buildQueuedDetectionConflict, +} from '../../components/ConflictStepRows/ConflictStepRows.mock'; import { MOCK_STATUS_STILL_SEARCHING, MOCK_STATUS_TRAINER_CONNECTING, MOCK_STATUS_TRAINER_UNAVAILABLE, } from '../../components/PairingStatusLine/PairingStatusLine.mock'; @@ -263,3 +267,53 @@ export const TrainerUnavailableHelper: Story = { helper: buildTrainerUnavailableHelper({ onOpen: fn(), onDismiss: fn(), onSelect: fn(), onAction: fn() }), } as any, }; + +// The trainer can't be reached, a separate power meter is connected: the helper offers to ride with it +export const FallbackOffered: Story = { + args: { + ...TrainerUnavailable.args, + helper: buildFallbackHelper({ onOpen: fn(), onDismiss: fn(), onSelect: fn(), onAction: fn() }), + } as any, +}; + +// The rider chose to ride with the power meter: the trainer's tiles are dimmed, a tap on Resistance takes it back +export const FallingBack: Story = { + args: { + title: 'Devices', + capabilities: MOCK_CAPABILITIES_FALLBACK, + pairingCase: 'trainer-unavailable', + trainerPhase: 'unavailable', + interfaces: [{ name: 'ble', state: 'scanning', onClick: fn() }], + buttons: [{ label: 'Start', primary: true, onClick: fn() }], + } as any, +}; + +// A trainer found by the search wants slots other devices hold: the card beside the tiles, OK stays usable +export const ConflictCard: Story = { + args: { + title: 'Devices', + capabilities: MOCK_CAPABILITIES_SWITCHED_OFF, + pendingConflict: buildDetectionConflict({ onChoice: fn(), onDone: fn(), onDismiss: fn() }), + interfaces: [{ name: 'ble', state: 'scanning', onClick: fn() }], + buttons: [{ label: 'OK', primary: true, onClick: fn() }], + } as any, +}; + +export const ConflictCardMoreWaiting: Story = { + args: { + ...ConflictCard.args, + pendingConflict: buildQueuedDetectionConflict({ onChoice: fn(), onDone: fn(), onDismiss: fn() }), + } as any, +}; + +// A pick in the Resistance list would take slots other devices hold: the list's second step +export const ResistanceListConflictStep: Story = { + args: { + ...ConflictCard.args, + pendingConflict: undefined, + deviceSelection: { + ...deviceSelectorArgs, + conflictStep: buildManualConflict({ onChoice: fn(), onDone: fn(), onDismiss: fn() }), + }, + } as any, +}; diff --git a/src/pages/PairingPage/View.test.tsx b/src/pages/PairingPage/View.test.tsx index 09f77404..907c0b23 100644 --- a/src/pages/PairingPage/View.test.tsx +++ b/src/pages/PairingPage/View.test.tsx @@ -1,10 +1,19 @@ import React from 'react' -import { render, fireEvent } from '@testing-library/react-native' -import type { PairingDisplayProps } from 'incyclist-services' +import { render, fireEvent, within } from '@testing-library/react-native' +import type { DeviceSelectionProps, PairingDisplayProps } from 'incyclist-services' import { PairingPageView } from './View' -import { buildAsleepHelper, buildNoTrainerHelper } from '../../components/PairingHelperPanel/PairingHelperPanel.mock' -import { MOCK_CAPABILITIES_SEARCHING } from '../../components/CapabilityStatusBars/CapabilityStatusBars.mock' +import { MOCK_PAIRING_BUTTON_SETS } from './PairingPage.mock' +import { + buildAsleepHelper, buildFallbackHelper, buildNoDeviceHelper, buildNoTrainerHelper, buildTrainerUnavailableHelper, +} from '../../components/PairingHelperPanel/PairingHelperPanel.mock' +import { + MOCK_CAPABILITIES_FALLBACK, MOCK_CAPABILITIES_SEARCHING, MOCK_CAPABILITIES_SWITCHED_OFF, MOCK_CAPABILITIES_TRAINER_CONNECTING, + MOCK_CAPABILITIES_TRAINER_UNAVAILABLE, +} from '../../components/CapabilityStatusBars/CapabilityStatusBars.mock' import { MOCK_STATUS_STILL_SEARCHING } from '../../components/PairingStatusLine/PairingStatusLine.mock' +import { + buildDetectionConflict, buildManualConflict, buildQueuedDetectionConflict, +} from '../../components/ConflictStepRows/ConflictStepRows.mock' // the barrel pulls in every component with its native modules; only the ones this page renders are needed jest.mock('../../components', () => { @@ -13,12 +22,13 @@ jest.mock('../../components', () => { const Stub = () => null return { MainBackground: Passthrough, - ButtonBar: Stub, InterfaceState: Stub, - DeviceSelector: Stub, + ButtonBar: jest.requireActual('../../components/ButtonBar').ButtonBar, + DeviceSelector: jest.requireActual('../../components/DeviceSelector').DeviceSelector, CapabilityGrid: jest.requireActual('../../components/CapabilityGrid').CapabilityGrid, CapabilityStatusBars: jest.requireActual('../../components/CapabilityStatusBars').CapabilityStatusBars, PairingHelperPanel: jest.requireActual('../../components/PairingHelperPanel').PairingHelperPanel, + PairingConflictCard: jest.requireActual('../../components/PairingConflictCard').PairingConflictCard, PairingStatusLine: jest.requireActual('../../components/PairingStatusLine').PairingStatusLine, } }) @@ -46,6 +56,20 @@ const props = (extra: Partial = {}): PairingDisplayProps => ...extra, }) +const resistanceList = (extra: Partial = {}): DeviceSelectionProps => ({ + capability: 'control', + devices: [ + { deviceName: 'Tacx Flux', value: 1, interface: 'ble', isSelected: true, connectState: 'failed', onClick: jest.fn(), onDelete: jest.fn() }, + { deviceName: 'Tacx Neo 2T', value: 2, interface: 'ble', isSelected: false, onClick: jest.fn(), onDelete: jest.fn() }, + ], + isScanning: false, + disabled: false, + changeForAll: false, + canSelectAll: true, + onClose: jest.fn(), + ...extra, +}) + describe('PairingPageView', () => { it('the status line link opens the helper', () => { setDimensions(...PHONE) @@ -76,3 +100,143 @@ describe('PairingPageView', () => { expect(queryByText('Smart trainer · Searching…')).toBeNull() }) }) + +describe('PairingPageView conflict card', () => { + it('on a phone: the card in the panel slot, the required row as status bars', () => { + setDimensions(...PHONE) + const { getByText } = render() + expect(getByText('Tacx Neo 2T can also measure more')).toBeTruthy() + expect(getByText('Nothing changes until you choose.')).toBeTruthy() + expect(getByText('Smart trainer · Searching…')).toBeTruthy() + }) + + it('on a tablet: the card beside the tiles, with the full subline', () => { + setDimensions(...TABLET) + const conflict = buildDetectionConflict() + const { getByText, queryByText } = render() + expect(getByText(conflict.subline.full)).toBeTruthy() + expect(queryByText('Smart trainer · Searching…')).toBeNull() + }) + + it('shows how many more wait', () => { + setDimensions(...PHONE) + const { getByText } = render() + expect(getByText('2 more')).toBeTruthy() + }) + + it('never blocks the page buttons: OK still works while the card shows', () => { + setDimensions(...PHONE) + const onOK = jest.fn(async () => {}) + const { getByText } = render() + fireEvent.press(getByText('OK')) + expect(onOK).toHaveBeenCalledTimes(1) + }) + + it('Done and ✕ go to the card\'s own handlers', () => { + setDimensions(...PHONE) + const onDone = jest.fn() + const onDismiss = jest.fn() + const { getByText, getByLabelText } = render() + fireEvent.press(getByText('Done')) + fireEvent.press(getByLabelText('Close')) + expect(onDone).toHaveBeenCalledTimes(1) + expect(onDismiss).toHaveBeenCalledTimes(1) + }) + + it('renders the card every time it is given, whatever else the page shows', () => { + setDimensions(...PHONE) + const { getByText } = render() + expect(getByText('Tacx Neo 2T can also measure more')).toBeTruthy() + }) + + it('without one, there is no card', () => { + setDimensions(...PHONE) + const { queryByText } = render() + expect(queryByText('Tacx Neo 2T can also measure more')).toBeNull() + }) +}) + +describe('PairingPageView fallback', () => { + it('the helper offers the fallback with the label the page service gives', () => { + setDimensions(...PHONE) + const onAction = jest.fn() + const { getByText } = render() + fireEvent.press(getByText('Ride with power meter only')) + expect(onAction).toHaveBeenCalledTimes(1) + }) + + it('while the ride falls back, the dimmed Resistance bar beside a card shows its copy and a tap calls its onClick', () => { + setDimensions(...PHONE) + const onClick = jest.fn() + const top = MOCK_CAPABILITIES_FALLBACK.top.map(t => (t.capability === 'control' ? { ...t, onClick } : t)) + const { getByText } = render() + + expect(getByText('Tacx Flux · Your trainer · Tap to use again')).toBeTruthy() + fireEvent.press(getByText('RESISTANCE')) + expect(onClick).toHaveBeenCalledTimes(1) + }) +}) + +// The pairing flow never offers a "try again" button, on any platform: the page renders exactly the +// buttons the page service gives, and none of its own panels or steps adds one. +describe('PairingPageView never shows a "try again" button', () => { + const TRY_AGAIN = /try\s*again|re-?try/i + + const STATES: Array<[string, Partial]> = [ + ['searching', {}], + ['the helper, nothing picked', { helper: buildNoTrainerHelper() }], + ['the helper, no device', { helper: buildNoDeviceHelper() }], + ['the trainer connecting', { capabilities: MOCK_CAPABILITIES_TRAINER_CONNECTING }], + ['the trainer unavailable, its helper', { capabilities: MOCK_CAPABILITIES_TRAINER_UNAVAILABLE, helper: buildTrainerUnavailableHelper() }], + ['the fallback offered', { capabilities: MOCK_CAPABILITIES_TRAINER_UNAVAILABLE, helper: buildFallbackHelper() }], + ['the ride falling back', { capabilities: MOCK_CAPABILITIES_FALLBACK }], + ['Resistance switched off', { capabilities: MOCK_CAPABILITIES_SWITCHED_OFF }], + ['a conflict card', { pendingConflict: buildQueuedDetectionConflict() }], + ['the Resistance list', { deviceSelection: resistanceList() }], + ['the Resistance list\'s conflict step', { deviceSelection: resistanceList({ conflictStep: buildManualConflict() }) }], + ] + const BUTTON_SETS = Object.entries(MOCK_PAIRING_BUTTON_SETS) + const LAYOUTS: Array<[string, [number, number]]> = [['phone', PHONE], ['tablet', TABLET]] + + describe.each(LAYOUTS)('on a %s', (_layout, size) => { + it.each(STATES)('%s: no text anywhere on the page reads "try again", with any of the page service\'s button sets', (_state, extra) => { + setDimensions(...size) + BUTTON_SETS.forEach(([, buttons]) => { + const { queryAllByText, unmount } = render() + expect(queryAllByText(TRY_AGAIN)).toHaveLength(0) + unmount() + }) + }) + }) + + it.each(BUTTON_SETS)('the page shows exactly the buttons it is given (%s), none added, none dropped', (_name, buttons) => { + setDimensions(...PHONE) + const { getByTestId } = render() + const labels = within(getByTestId('pairing-page-buttons')).queryAllByText(/./).map(t => t.props.children) + expect(labels).toEqual(buttons.map(b => b.label)) + }) + + it('the check itself is not blind: a button labelled like that would be found', () => { + setDimensions(...PHONE) + const { queryAllByText } = render( {} }] })} />) + expect(queryAllByText(TRY_AGAIN)).toHaveLength(1) + }) + + it('no button set the page service gives has a "try again" label', () => { + BUTTON_SETS.forEach(([, buttons]) => { + buttons.forEach(b => expect(b.label).not.toMatch(TRY_AGAIN)) + }) + }) +}) diff --git a/src/pages/PairingPage/View.tsx b/src/pages/PairingPage/View.tsx index 275f35b0..e8b736bc 100644 --- a/src/pages/PairingPage/View.tsx +++ b/src/pages/PairingPage/View.tsx @@ -5,7 +5,7 @@ import type { PairingDisplayProps, InterfaceDisplayProps } from 'incyclist-servi import { colors, textSizes } from '../../theme' import { ButtonBar, CapabilityGrid, CapabilityStatusBars, MainBackground, InterfaceState, DeviceSelector, - PairingHelperPanel, PairingStatusLine, + PairingConflictCard, PairingHelperPanel, PairingStatusLine, } from '../../components' import { BleInterfaceSettings } from '../../components/BleInterfaceSettings' import { useScreenLayout } from '../../hooks' @@ -20,14 +20,20 @@ const PANEL_WIDTH_TABLET = 320 const PANEL_TOP_CLEARANCE = 56 export const PairingPageView = (props: PairingDisplayProps) => { - const { deviceSelection, onExit, helper, status, interfaces, capabilities } = props + const { deviceSelection, onExit, helper, status, interfaces, capabilities, pendingConflict } = props const compact = useScreenLayout() === 'compact' + const panelLayout = compact ? 'phone' : 'tablet' const onStatusLink = useMemo(() => getStatusLinkHandler(status, helper, interfaces), [status, helper, interfaces]) const helperOpen = helper !== undefined && helper.phase !== 'hidden' - // on a phone, the helper leaves too little room for tiles: the required row becomes status bars - const showBars = helperOpen && compact + // the panel beside the tiles holds one thing at a time: the helper, or a device-selection + // conflict. The page service only gives a conflict while the helper and the device lists are + // closed, so the conflict card is shown whenever it is given. + const conflictCard = helperOpen ? undefined : pendingConflict + const panelOpen = helperOpen || conflictCard !== undefined + // on a phone, the panel leaves too little room for tiles: the required row becomes status bars + const showBars = panelOpen && compact const panelStyle = { width: compact ? PANEL_WIDTH_PHONE : PANEL_WIDTH_TABLET } return ( @@ -76,14 +82,17 @@ export const PairingPageView = (props: PairingDisplayProps) => { )} - + {/* exactly the page service's buttons, never filtered or added to */} + {props.buttons && } - {helperOpen && ( + {panelOpen && ( - + {helperOpen + ? + : conflictCard && } )} From 43686f6e29a1877e4fe551cfc057d1ac26e240c1 Mon Sep 17 00:00:00 2001 From: Guido Doumen Date: Tue, 10 Nov 2026 12:21:06 +0100 Subject: [PATCH 05/14] refactor(pairing): share the conflict step's body and the device dialog's width The device list's conflict step body (subline and rows) moves next to the rows as ConflictStepBody, and the list dialog's width into a helper, so a second conflict dialog can render the same body at the same size. The body also shows how many more conflicts wait, when the page service says so. No change to how the device list behaves. --- .../ConflictStepRows/ConflictStepBody.tsx | 37 +++++++++++++++++++ src/components/ConflictStepRows/index.ts | 1 + src/components/ConflictStepRows/types.ts | 9 +++++ .../DeviceSelector/DeviceSelector.tsx | 36 ++++-------------- src/components/DeviceSelector/utils.ts | 11 ++++++ 5 files changed, 65 insertions(+), 29 deletions(-) create mode 100644 src/components/ConflictStepRows/ConflictStepBody.tsx create mode 100644 src/components/DeviceSelector/utils.ts diff --git a/src/components/ConflictStepRows/ConflictStepBody.tsx b/src/components/ConflictStepRows/ConflictStepBody.tsx new file mode 100644 index 00000000..38f3b7c4 --- /dev/null +++ b/src/components/ConflictStepRows/ConflictStepBody.tsx @@ -0,0 +1,37 @@ +import React from 'react' +import { View, Text, StyleSheet } from 'react-native' + +import { colors, textSizes } from '../../theme' +import { ConflictStepRows } from './ConflictStepRows' +import { ConflictStepBodyProps } from './types' + +/** + * The body of a conflict dialog, under its title: how many more conflicts wait (when the page service + * says so), the subline, and the rows. Both the device list's second step and the dialog for a device + * found by the search show it, so the two look and read the same. + */ +export const ConflictStepBody = ({ step, compact, onChoice }: ConflictStepBodyProps) => ( + + {step.queuedText ? {step.queuedText} : null} + {compact ? step.subline.short : step.subline.full} + + +) + +const styles = StyleSheet.create({ + body: { + paddingHorizontal: 8, + paddingTop: 4, + }, + queued: { + color: colors.text, + fontSize: textSizes.smallText, + textAlign: 'right', + marginBottom: 4, + }, + subline: { + color: colors.text, + fontSize: textSizes.smallText, + marginBottom: 10, + }, +}) diff --git a/src/components/ConflictStepRows/index.ts b/src/components/ConflictStepRows/index.ts index 6ace5de6..dff46656 100644 --- a/src/components/ConflictStepRows/index.ts +++ b/src/components/ConflictStepRows/index.ts @@ -1,2 +1,3 @@ export * from './ConflictStepRows' +export * from './ConflictStepBody' export * from './types' diff --git a/src/components/ConflictStepRows/types.ts b/src/components/ConflictStepRows/types.ts index a50387ad..b7d89401 100644 --- a/src/components/ConflictStepRows/types.ts +++ b/src/components/ConflictStepRows/types.ts @@ -5,3 +5,12 @@ export interface ConflictStepRowsProps { rows: ReadonlyArray onChoice: ConflictStepProps['onChoice'] } + +export interface ConflictStepBodyProps { + /** the conflict as the page service gives it */ + step: ConflictStepProps + /** the phone's short subline instead of the full one */ + compact: boolean + /** what a tap on a row's choice calls: the step's own `onChoice`, or a guarded wrapper of it */ + onChoice: ConflictStepProps['onChoice'] +} diff --git a/src/components/DeviceSelector/DeviceSelector.tsx b/src/components/DeviceSelector/DeviceSelector.tsx index 959eb640..f7b3efa3 100644 --- a/src/components/DeviceSelector/DeviceSelector.tsx +++ b/src/components/DeviceSelector/DeviceSelector.tsx @@ -1,28 +1,16 @@ import React, { FC, useCallback, useMemo } from 'react'; -import { View, Text, StyleSheet, ScrollView, useWindowDimensions } from 'react-native'; +import { View, StyleSheet, ScrollView, useWindowDimensions } from 'react-native'; import DeviceEntry from '../DeviceEntry'; -import { ConflictStepProps, DeviceSelectionItemProps, DeviceSelectionProps } from 'incyclist-services'; -import { colors, textSizes } from '../../theme'; +import { DeviceSelectionItemProps, DeviceSelectionProps } from 'incyclist-services'; +import { textSizes } from '../../theme'; import { useScreenLayout } from '../../hooks'; import { Dialog } from '../Dialog'; import { ButtonProps } from '../ButtonBar/types'; -import { ConflictStepRows } from '../ConflictStepRows'; +import { ConflictStepBody } from '../ConflictStepRows'; +import { getDeviceDialogWidth } from './utils'; const DONE_LABEL = 'Done'; -interface ConflictStepBodyProps { - step: ConflictStepProps - compact: boolean -} - -// the list's second step: which device each slot held by another device should use -const ConflictStepBody = ({ step, compact }: ConflictStepBodyProps) => ( - - {compact ? step.subline.short : step.subline.full} - - -); - /** * The device list of one capability. After a pick in the Resistance list that would take slots held * by a different device, the page service sends a conflict step: it replaces the list in the same @@ -37,8 +25,7 @@ export const DeviceSelector: FC = ({ const { width: screenWidth, height: screenHeight } = useWindowDimensions(); const compact = useScreenLayout() === 'compact'; - const targetWidth = textSizes.listEntry * 0.6 * 40; // ~288dp - const dialogWidth = Math.min(0.9 * screenWidth, targetWidth); + const dialogWidth = getDeviceDialogWidth(screenWidth); const minHeightLeft = screenHeight - (textSizes.dialogTitle + 100 + 80 + 8); const deviceListMinHeight = Math.min(380, minHeightLeft); @@ -74,7 +61,7 @@ export const DeviceSelector: FC = ({ scrollable={Boolean(conflictStep)} > {conflictStep ? ( - + ) : ( @@ -109,13 +96,4 @@ const styles = StyleSheet.create({ maxHeight: 380, // Dynamic minHeight applied via inline style }, - stepView: { - paddingHorizontal: 8, - paddingTop: 4, - }, - stepSubline: { - color: colors.text, - fontSize: textSizes.smallText, - marginBottom: 10, - }, }); diff --git a/src/components/DeviceSelector/utils.ts b/src/components/DeviceSelector/utils.ts new file mode 100644 index 00000000..ddce5e71 --- /dev/null +++ b/src/components/DeviceSelector/utils.ts @@ -0,0 +1,11 @@ +import { textSizes } from '../../theme' + +// about 288 dp: wide enough for a device name at list-entry size +const TARGET_WIDTH = textSizes.listEntry * 0.6 * 40 + +/** + * The width of the device list's dialog, which the dialog for a device found by the search shares. + * + * @param screenWidth the window's width + */ +export const getDeviceDialogWidth = (screenWidth: number): number => Math.min(0.9 * screenWidth, TARGET_WIDTH) From 2e0b43bf2ed5f77f1eefc15dd03c51eab783dc33 Mon Sep 17 00:00:00 2001 From: Guido Doumen Date: Tue, 10 Nov 2026 12:21:19 +0100 Subject: [PATCH 06/14] feat(pairing): ask about a conflict found by the search in a dialog, not a card A device found by the search that wants slots held by another device now asks in the same dialog, at the same size, as the Resistance list's own conflict step, instead of a card in the panel beside the tiles. The automatic and manual conflicts now share one pattern. - the dialog shows the conflict's title, subline (short on a phone, full on a tablet), how many more wait, the rows, and Done; there is no close button - a tap outside or the back button go to the conflict's onDismiss right away - for half a second after a conflict appears, Keep, Use and Done ignore taps, since the dialog opens by itself and may catch a tap meant for the page; ignored taps are logged - as a modal, the dialog keeps OK out of reach while it is open - the tiles stay as they are behind it: only the helper still turns the required row into status bars on a phone - the conflict card is removed --- .../ConflictStepRows/ConflictStepRows.mock.ts | 12 +- .../ConflictStepRows/ConflictStepRows.tsx | 2 +- .../PairingConflictCard.stories.tsx | 58 ----- .../PairingConflictCard.test.tsx | 79 ------ .../PairingConflictCard.tsx | 56 ----- src/components/PairingConflictCard/index.ts | 2 - src/components/PairingConflictCard/types.ts | 8 - .../PairingConflictDialog.stories.tsx | 54 +++++ .../PairingConflictDialog.test.tsx | 227 ++++++++++++++++++ .../PairingConflictDialog.tsx | 79 ++++++ src/components/PairingConflictDialog/index.ts | 2 + src/components/PairingConflictDialog/types.ts | 6 + src/components/index.ts | 2 +- src/pages/PairingPage/PairingPage.stories.tsx | 10 +- src/pages/PairingPage/View.test.tsx | 101 +++++--- src/pages/PairingPage/View.tsx | 19 +- 16 files changed, 464 insertions(+), 253 deletions(-) delete mode 100644 src/components/PairingConflictCard/PairingConflictCard.stories.tsx delete mode 100644 src/components/PairingConflictCard/PairingConflictCard.test.tsx delete mode 100644 src/components/PairingConflictCard/PairingConflictCard.tsx delete mode 100644 src/components/PairingConflictCard/index.ts delete mode 100644 src/components/PairingConflictCard/types.ts create mode 100644 src/components/PairingConflictDialog/PairingConflictDialog.stories.tsx create mode 100644 src/components/PairingConflictDialog/PairingConflictDialog.test.tsx create mode 100644 src/components/PairingConflictDialog/PairingConflictDialog.tsx create mode 100644 src/components/PairingConflictDialog/index.ts create mode 100644 src/components/PairingConflictDialog/types.ts diff --git a/src/components/ConflictStepRows/ConflictStepRows.mock.ts b/src/components/ConflictStepRows/ConflictStepRows.mock.ts index f96c38be..fd15e0f0 100644 --- a/src/components/ConflictStepRows/ConflictStepRows.mock.ts +++ b/src/components/ConflictStepRows/ConflictStepRows.mock.ts @@ -30,8 +30,8 @@ export const buildDetectionConflict = (h: MockConflictHandlers = {}, choices: Pa deviceName: NEW_DEVICE, title: `${NEW_DEVICE} can also measure more`, subline: { - full: 'Resistance was free and now uses it. Choose for the rest; nothing changes until you do.', - short: 'Nothing changes until you choose.', + full: `We just found your ${NEW_DEVICE}. Nothing changes until you choose. Resistance was free and now uses ${NEW_DEVICE}.`, + short: `Just found ${NEW_DEVICE}. Nothing changes until you choose.`, }, rows: [ row('power', 'Power', 'Stages Power', choices.power), @@ -43,7 +43,13 @@ export const buildDetectionConflict = (h: MockConflictHandlers = {}, choices: Pa onDismiss: h.onDismiss ?? noop, }) -/** The same card, with two more conflicts waiting behind it. */ +/** A power meter found by the search wants Cadence only, which another device already holds. */ +export const buildSingleRowDetectionConflict = (h: MockConflictHandlers = {}): ConflictStepProps => { + const conflict = buildDetectionConflict(h) + return { ...conflict, rows: conflict.rows.filter(r => r.capability === 'cadence') } +} + +/** The same conflict, with two more waiting behind it. */ export const buildQueuedDetectionConflict = (h: MockConflictHandlers = {}): ConflictStepProps => ({ ...buildDetectionConflict(h), queued: 2, diff --git a/src/components/ConflictStepRows/ConflictStepRows.tsx b/src/components/ConflictStepRows/ConflictStepRows.tsx index a164aaa6..a428b9b5 100644 --- a/src/components/ConflictStepRows/ConflictStepRows.tsx +++ b/src/components/ConflictStepRows/ConflictStepRows.tsx @@ -8,7 +8,7 @@ import { ConflictStepRowsProps } from './types' /** * The rows of a device-selection conflict: one per slot that already holds a different device, each * with its title and the two choices (keep the current device, or use the new one) stacked under it. - * The same rows show in the conflict card beside the tiles and in the Resistance list's second step. + * The same rows show in the dialog for a device found by the search and in the Resistance list's second step. */ export const ConflictStepRows = ({ rows, onChoice }: ConflictStepRowsProps) => ( diff --git a/src/components/PairingConflictCard/PairingConflictCard.stories.tsx b/src/components/PairingConflictCard/PairingConflictCard.stories.tsx deleted file mode 100644 index d494094e..00000000 --- a/src/components/PairingConflictCard/PairingConflictCard.stories.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import React from 'react' -import { View, StyleSheet } from 'react-native' -import type { Meta, StoryObj } from '@storybook/react-native-web-vite'; -import { fn } from 'storybook/test'; -import { PairingConflictCard } from './PairingConflictCard' -import { colors } from '../../theme' -import { buildDetectionConflict, buildQueuedDetectionConflict } from '../ConflictStepRows/ConflictStepRows.mock' - -const handlers = () => ({ onChoice: fn(), onDone: fn(), onDismiss: fn() }) - -const meta: Meta = { - title: 'Components/PairingConflictCard', - component: PairingConflictCard, - args: { - layout: 'phone', - }, - decorators: [ - (Story, ctx) => ( - - - - ), - ], -} - -export default meta - -type Story = StoryObj - -export const Phone: Story = { - args: { conflict: buildDetectionConflict(handlers()) }, -} - -export const PhoneOneReplaced: Story = { - args: { conflict: buildDetectionConflict(handlers(), { power: 'replace' }) }, -} - -export const PhoneMoreWaiting: Story = { - args: { conflict: buildQueuedDetectionConflict(handlers()) }, -} - -export const Tablet: Story = { - args: { conflict: buildDetectionConflict(handlers()), layout: 'tablet' }, -} - -// the panel's size on a 667 x 375 phone, and on a tablet, below the page title -const styles = StyleSheet.create({ - phone: { - width: 300, - height: 337, - backgroundColor: colors.background, - }, - tablet: { - width: 320, - height: 470, - backgroundColor: colors.background, - }, -}) diff --git a/src/components/PairingConflictCard/PairingConflictCard.test.tsx b/src/components/PairingConflictCard/PairingConflictCard.test.tsx deleted file mode 100644 index 96691c03..00000000 --- a/src/components/PairingConflictCard/PairingConflictCard.test.tsx +++ /dev/null @@ -1,79 +0,0 @@ -import React from 'react' -import { render, fireEvent, within } from '@testing-library/react-native' -import { PairingConflictCard } from './PairingConflictCard' -import { buildDetectionConflict, buildQueuedDetectionConflict } from '../ConflictStepRows/ConflictStepRows.mock' - -const mockLogEvent = jest.fn() -jest.mock('../../hooks', () => ({ - useLogging: () => ({ logEvent: mockLogEvent }), -})) - -describe('PairingConflictCard', () => { - - afterEach(() => { - jest.clearAllMocks() - }) - - it('shows the title, the phone subline and the rows on a phone', () => { - const conflict = buildDetectionConflict() - const { getByText, queryByText } = render() - - expect(getByText('Tacx Neo 2T can also measure more')).toBeTruthy() - expect(getByText(conflict.subline.short)).toBeTruthy() - expect(queryByText(conflict.subline.full)).toBeNull() - expect(getByText('Keep Stages Power')).toBeTruthy() - expect(getByText('Keep Wahoo RPM')).toBeTruthy() - }) - - it('shows the full subline on a tablet', () => { - const conflict = buildDetectionConflict() - const { getByText } = render() - - expect(getByText(conflict.subline.full)).toBeTruthy() - }) - - it('says how many more conflicts wait, only when some do', () => { - const queued = render() - expect(queued.getByText('2 more')).toBeTruthy() - - const single = render() - expect(single.queryByText('stale')).toBeNull() - }) - - it('Done is pinned and applies the choices', () => { - const onDone = jest.fn() - const { getByTestId } = render() - - fireEvent.press(within(getByTestId('pairing-side-panel-pinned')).getByText('Done')) - - expect(onDone).toHaveBeenCalledTimes(1) - expect(mockLogEvent).toHaveBeenCalledWith(expect.objectContaining({ message: 'button clicked', button: 'conflict done' })) - }) - - it('✕ dismisses the card', () => { - const onDismiss = jest.fn() - const onDone = jest.fn() - const { getByLabelText } = render() - - fireEvent.press(getByLabelText('Close')) - - expect(onDismiss).toHaveBeenCalledTimes(1) - expect(onDone).not.toHaveBeenCalled() - expect(mockLogEvent).toHaveBeenCalledWith(expect.objectContaining({ message: 'button clicked', button: 'conflict close' })) - }) - - it('a choice is passed on as given', () => { - const onChoice = jest.fn() - const { getByLabelText } = render() - - fireEvent.press(getByLabelText('Power: Use Tacx Neo 2T')) - - expect(onChoice).toHaveBeenCalledWith('power', 'replace') - }) - - it('has exactly two buttons: ✕ and Done', () => { - const { getAllByRole } = render() - - expect(getAllByRole('button').map(b => b.props.accessibilityLabel ?? within(b).queryByText(/./)?.props.children)).toEqual(['Close', 'Done']) - }) -}) diff --git a/src/components/PairingConflictCard/PairingConflictCard.tsx b/src/components/PairingConflictCard/PairingConflictCard.tsx deleted file mode 100644 index 245e8d43..00000000 --- a/src/components/PairingConflictCard/PairingConflictCard.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import React, { useCallback } from 'react' -import { ScrollView, StyleSheet } from 'react-native' - -import { useLogging } from '../../hooks' -import { PairingSidePanel, PairingSidePanelAction } from '../PairingSidePanel' -import { ConflictStepRows } from '../ConflictStepRows' -import { PairingConflictCardProps } from './types' - -const DONE_LABEL = 'Done' - -/** - * A device found by the search wants slots that already hold a different device: the rider picks, - * per slot, which device to keep. Shown in the panel beside the tiles, non-modal, so the page's own - * buttons stay usable. ✕ keeps every current device; Done applies the choices. - */ -export const PairingConflictCard = ({ conflict, layout }: PairingConflictCardProps) => { - const { logEvent } = useLogging('PairingConflictCard') - - const onClose = useCallback(() => { - logEvent({ message: 'button clicked', button: 'conflict close', eventSource: 'user' }) - conflict.onDismiss() - }, [conflict, logEvent]) - - const onDone = useCallback(() => { - logEvent({ message: 'button clicked', button: 'conflict done', eventSource: 'user' }) - conflict.onDone() - }, [conflict, logEvent]) - - const subline = layout === 'phone' ? conflict.subline.short : conflict.subline.full - const titleNote = conflict.queued > 0 ? conflict.queuedText : undefined - - return ( - } - > - - - - - ) -} - -const styles = StyleSheet.create({ - body: { - flex: 1, - }, - bodyContent: { - paddingHorizontal: 12, - paddingTop: 6, - paddingBottom: 6, - }, -}) diff --git a/src/components/PairingConflictCard/index.ts b/src/components/PairingConflictCard/index.ts deleted file mode 100644 index c2eb74ba..00000000 --- a/src/components/PairingConflictCard/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './PairingConflictCard' -export * from './types' diff --git a/src/components/PairingConflictCard/types.ts b/src/components/PairingConflictCard/types.ts deleted file mode 100644 index 885408a5..00000000 --- a/src/components/PairingConflictCard/types.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { ConflictStepProps } from 'incyclist-services' - -export interface PairingConflictCardProps { - /** the conflict as the page service gives it */ - conflict: ConflictStepProps - /** `phone`: the short subline; `tablet`: the full one */ - layout: 'phone' | 'tablet' -} diff --git a/src/components/PairingConflictDialog/PairingConflictDialog.stories.tsx b/src/components/PairingConflictDialog/PairingConflictDialog.stories.tsx new file mode 100644 index 00000000..b772f440 --- /dev/null +++ b/src/components/PairingConflictDialog/PairingConflictDialog.stories.tsx @@ -0,0 +1,54 @@ +import React from 'react' +import { View, StyleSheet } from 'react-native' +import type { Meta, StoryObj } from '@storybook/react-native-web-vite'; +import { fn } from 'storybook/test'; +import { PairingConflictDialog } from './PairingConflictDialog' +import { + buildDetectionConflict, buildQueuedDetectionConflict, buildSingleRowDetectionConflict, +} from '../ConflictStepRows/ConflictStepRows.mock' + +// Like the device list's dialog, this one sizes itself to the window: resize the preview (or use the +// viewport toolbar) to see the phone's short subline below tablet size. +const handlers = () => ({ onChoice: fn(), onDone: fn(), onDismiss: fn() }) + +const meta: Meta = { + title: 'Components/PairingConflictDialog', + component: PairingConflictDialog, + decorators: [ + (Story) => ( + + + + ), + ], +} + +export default meta + +type Story = StoryObj + +export const MultipleRows: Story = { + args: { conflict: buildDetectionConflict(handlers()) }, +} + +export const SingleRow: Story = { + args: { conflict: buildSingleRowDetectionConflict(handlers()) }, +} + +export const OneReplaced: Story = { + args: { conflict: buildDetectionConflict(handlers(), { power: 'replace' }) }, +} + +export const MoreWaiting: Story = { + args: { conflict: buildQueuedDetectionConflict(handlers()) }, +} + +const styles = StyleSheet.create({ + centered: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + width: '100%', + height: '100%', + }, +}) diff --git a/src/components/PairingConflictDialog/PairingConflictDialog.test.tsx b/src/components/PairingConflictDialog/PairingConflictDialog.test.tsx new file mode 100644 index 00000000..2af0f5fa --- /dev/null +++ b/src/components/PairingConflictDialog/PairingConflictDialog.test.tsx @@ -0,0 +1,227 @@ +import React from 'react' +import { act, render, fireEvent } from '@testing-library/react-native' +import { Modal, TouchableWithoutFeedback } from 'react-native' +import { PairingConflictDialog, ARMING_DELAY_MS } from './PairingConflictDialog' +import { + buildDetectionConflict, buildQueuedDetectionConflict, buildSingleRowDetectionConflict, +} from '../ConflictStepRows/ConflictStepRows.mock' + +const mockLogEvent = jest.fn() +jest.mock('../../hooks', () => ({ + ...jest.requireActual('../../hooks'), + useLogging: () => ({ logEvent: mockLogEvent, logError: jest.fn() }), +})) + +const mockDimensions = { width: 800, height: 360 } +jest.mock('react-native/Libraries/Utilities/useWindowDimensions', () => ({ + default: jest.fn(() => mockDimensions), +})) + +const setDimensions = (width: number, height: number) => { + mockDimensions.width = width + mockDimensions.height = height +} +const PHONE: [number, number] = [800, 360] +const TABLET: [number, number] = [1280, 800] + +const arm = () => act(() => { jest.advanceTimersByTime(ARMING_DELAY_MS) }) + +// the dialog's outside area is the outermost TouchableWithoutFeedback; the inner one only stops taps on the dialog itself +const tapOutside = (root: ReturnType['UNSAFE_root']) => { + root.findAllByType(TouchableWithoutFeedback)[0].props.onPress() +} +const pressBack = (root: ReturnType['UNSAFE_root']) => { + root.findByType(Modal).props.onRequestClose() +} + +describe('PairingConflictDialog', () => { + beforeEach(() => { + jest.useFakeTimers() + setDimensions(...PHONE) + }) + + afterEach(() => { + jest.useRealTimers() + jest.clearAllMocks() + }) + + it('shows the title, the phone subline and the rows on a phone', () => { + const conflict = buildDetectionConflict() + const { getByText, queryByText, getAllByText } = render() + + expect(getByText('Tacx Neo 2T can also measure more')).toBeTruthy() + expect(getByText('Just found Tacx Neo 2T. Nothing changes until you choose.')).toBeTruthy() + expect(queryByText(conflict.subline.full)).toBeNull() + expect(getByText('Keep Stages Power')).toBeTruthy() + expect(getByText('Keep Wahoo RPM')).toBeTruthy() + expect(getAllByText('Use Tacx Neo 2T')).toHaveLength(2) + }) + + it('shows the full subline on a tablet', () => { + setDimensions(...TABLET) + const conflict = buildDetectionConflict() + const { getByText, queryByText } = render() + + expect(getByText(conflict.subline.full)).toBeTruthy() + expect(queryByText(conflict.subline.short)).toBeNull() + }) + + it('shows a single row', () => { + const { getByText, queryByText, getAllByRole } = render() + + expect(getByText('Keep Wahoo RPM')).toBeTruthy() + expect(queryByText('Keep Stages Power')).toBeNull() + expect(getAllByRole('radio')).toHaveLength(2) + }) + + it('says how many more conflicts wait, only when it is given', () => { + const queued = render() + expect(queued.getByText('2 more')).toBeTruthy() + queued.unmount() + + const single = render() + expect(single.queryByText(/^\d+ more$/)).toBeNull() + }) + + it('marks each row\'s choice as given: Keep unless the rider picked otherwise', () => { + const { getByLabelText } = render() + + expect(getByLabelText('Power: Keep Stages Power').props.accessibilityState).toEqual({ selected: true }) + expect(getByLabelText('Power: Use Tacx Neo 2T').props.accessibilityState).toEqual({ selected: false }) + expect(getByLabelText('Cadence: Keep Wahoo RPM').props.accessibilityState).toEqual({ selected: false }) + expect(getByLabelText('Cadence: Use Tacx Neo 2T').props.accessibilityState).toEqual({ selected: true }) + }) + + it('Done applies the choices', () => { + const onDone = jest.fn() + const onDismiss = jest.fn() + const { getByText } = render() + arm() + + fireEvent.press(getByText('Done')) + + expect(onDone).toHaveBeenCalledTimes(1) + expect(onDismiss).not.toHaveBeenCalled() + }) + + it('a choice is passed on as given', () => { + const onChoice = jest.fn() + const { getByLabelText } = render() + arm() + + fireEvent.press(getByLabelText('Power: Use Tacx Neo 2T')) + + expect(onChoice).toHaveBeenCalledWith('power', 'replace') + }) + + it.each([ + ['the back button', pressBack], + ['a tap outside', tapOutside], + ])('%s dismisses through the conflict\'s own onDismiss', (_name, dismiss) => { + const onDone = jest.fn() + const onDismiss = jest.fn() + const { UNSAFE_root } = render() + arm() + + dismiss(UNSAFE_root) + + expect(onDismiss).toHaveBeenCalledTimes(1) + expect(onDone).not.toHaveBeenCalled() + }) + + it('has no ✕: Done is its only button besides the rows', () => { + const { queryByLabelText, queryByText, getAllByText, getAllByRole } = render() + + expect(queryByLabelText('Close')).toBeNull() + expect(queryByText('✕')).toBeNull() + expect(getAllByText('Done')).toHaveLength(1) + expect(getAllByRole('radio')).toHaveLength(4) + }) +}) + +describe('PairingConflictDialog arming delay', () => { + beforeEach(() => { + jest.useFakeTimers() + setDimensions(...PHONE) + }) + + afterEach(() => { + jest.useRealTimers() + jest.clearAllMocks() + }) + + it('is about half a second', () => { + expect(ARMING_DELAY_MS).toBe(500) + }) + + it('ignores Keep, Use and Done right after the dialog appears', () => { + const onChoice = jest.fn() + const onDone = jest.fn() + const { getByText, getByLabelText } = render() + + act(() => { jest.advanceTimersByTime(ARMING_DELAY_MS - 1) }) + fireEvent.press(getByLabelText('Power: Use Tacx Neo 2T')) + fireEvent.press(getByLabelText('Cadence: Keep Wahoo RPM')) + fireEvent.press(getByText('Done')) + + expect(onChoice).not.toHaveBeenCalled() + expect(onDone).not.toHaveBeenCalled() + expect(mockLogEvent).toHaveBeenCalledWith(expect.objectContaining({ message: 'conflict tap ignored', control: 'done' })) + }) + + it('takes Keep, Use and Done once the delay has passed', () => { + const onChoice = jest.fn() + const onDone = jest.fn() + const { getByText, getByLabelText } = render() + + fireEvent.press(getByText('Done')) + arm() + fireEvent.press(getByLabelText('Power: Use Tacx Neo 2T')) + fireEvent.press(getByLabelText('Cadence: Keep Wahoo RPM')) + fireEvent.press(getByText('Done')) + + expect(onChoice).toHaveBeenNthCalledWith(1, 'power', 'replace') + expect(onChoice).toHaveBeenNthCalledWith(2, 'cadence', 'keep') + expect(onDone).toHaveBeenCalledTimes(1) + }) + + it.each([ + ['the back button', pressBack], + ['a tap outside', tapOutside], + ])('never holds back %s', (_name, dismiss) => { + const onDismiss = jest.fn() + const { UNSAFE_root } = render() + + dismiss(UNSAFE_root) + + expect(onDismiss).toHaveBeenCalledTimes(1) + }) + + it('starts again when the next conflict takes this one\'s place, so a quick second tap on Done is not applied to it', () => { + const first = jest.fn() + const next = jest.fn() + const { getByText, rerender } = render() + arm() + fireEvent.press(getByText('Done')) + + rerender() + fireEvent.press(getByText('Done')) + expect(next).not.toHaveBeenCalled() + + arm() + fireEvent.press(getByText('Done')) + expect(first).toHaveBeenCalledTimes(1) + expect(next).toHaveBeenCalledTimes(1) + }) + + it('does not start again when the same conflict updates, e.g. after a choice', () => { + const onDone = jest.fn() + const { getByText, rerender } = render() + arm() + + rerender() + fireEvent.press(getByText('Done')) + + expect(onDone).toHaveBeenCalledTimes(1) + }) +}) diff --git a/src/components/PairingConflictDialog/PairingConflictDialog.tsx b/src/components/PairingConflictDialog/PairingConflictDialog.tsx new file mode 100644 index 00000000..8b258cda --- /dev/null +++ b/src/components/PairingConflictDialog/PairingConflictDialog.tsx @@ -0,0 +1,79 @@ +import React, { useCallback, useEffect, useMemo, useRef } from 'react' +import { useWindowDimensions } from 'react-native' +import type { ConflictStepProps } from 'incyclist-services' + +import { useLogging, useScreenLayout } from '../../hooks' +import { Dialog } from '../Dialog' +import { ButtonProps } from '../ButtonBar/types' +import { ConflictStepBody } from '../ConflictStepRows' +import { getDeviceDialogWidth } from '../DeviceSelector/utils' +import { PairingConflictDialogProps } from './types' + +/** + * How long Keep, Use and Done ignore taps after a conflict appears. The dialog opens by itself when + * the search finds a device, possibly while the rider is about to tap something else on the page. + */ +export const ARMING_DELAY_MS = 500 + +const DONE_LABEL = 'Done' + +type TapControl = 'choice' | 'done' + +/** + * A device found by the search wants slots that already hold a different device: the rider picks, + * per slot, which device to keep. The same dialog, at the same size, as the device list's own + * conflict step. Done applies the choices; a tap outside or the back button go to the conflict's + * `onDismiss`, right away, even during the arming delay. + */ +export const PairingConflictDialog = ({ conflict }: PairingConflictDialogProps) => { + const { logEvent } = useLogging('PairingConflictDialog') + const { width: screenWidth } = useWindowDimensions() + const compact = useScreenLayout() === 'compact' + const refArmed = useRef(false) + + // armed again for every new conflict: the next one in the queue takes this one's place right + // after Done, under the finger that just tapped it + useEffect(() => { + refArmed.current = false + const timer = setTimeout(() => { refArmed.current = true }, ARMING_DELAY_MS) + return () => clearTimeout(timer) + }, [conflict.id]) + + const isArmed = useCallback((control: TapControl): boolean => { + if (refArmed.current) + return true + logEvent({ message: 'conflict tap ignored', control, conflictId: conflict.id, delay: ARMING_DELAY_MS }) + return false + }, [logEvent, conflict.id]) + + const onChoice = useCallback((capability, choice) => { + if (isArmed('choice')) + conflict.onChoice(capability, choice) + }, [isArmed, conflict]) + + const onDone = useCallback(() => { + if (isArmed('done')) + conflict.onDone() + }, [isArmed, conflict]) + + const onOutsideClick = useCallback(() => { + conflict.onDismiss() + }, [conflict]) + + const buttons = useMemo(() => [ + { id: 'conflict-done', label: DONE_LABEL, primary: true, onClick: onDone }, + ], [onDone]) + + const dialogStyle = { width: getDeviceDialogWidth(screenWidth) } + + return ( + + + + ) +} diff --git a/src/components/PairingConflictDialog/index.ts b/src/components/PairingConflictDialog/index.ts new file mode 100644 index 00000000..11f83763 --- /dev/null +++ b/src/components/PairingConflictDialog/index.ts @@ -0,0 +1,2 @@ +export * from './PairingConflictDialog' +export * from './types' diff --git a/src/components/PairingConflictDialog/types.ts b/src/components/PairingConflictDialog/types.ts new file mode 100644 index 00000000..fb467372 --- /dev/null +++ b/src/components/PairingConflictDialog/types.ts @@ -0,0 +1,6 @@ +import type { ConflictStepProps } from 'incyclist-services' + +export interface PairingConflictDialogProps { + /** the conflict as the page service gives it (`pendingConflict`) */ + conflict: ConflictStepProps +} diff --git a/src/components/index.ts b/src/components/index.ts index 9e354ff9..e3244bdd 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -6,7 +6,7 @@ export * from './CapabilityStatusBars' export * from './PairingStatusLine' export * from './PairingHelperPanel' export * from './PairingSidePanel' -export * from './PairingConflictCard' +export * from './PairingConflictDialog' export * from './ConflictStepRows' export * from './ExitButton' export * from './InterfaceState' diff --git a/src/pages/PairingPage/PairingPage.stories.tsx b/src/pages/PairingPage/PairingPage.stories.tsx index 885b8c7e..9c4ce771 100644 --- a/src/pages/PairingPage/PairingPage.stories.tsx +++ b/src/pages/PairingPage/PairingPage.stories.tsx @@ -288,8 +288,8 @@ export const FallingBack: Story = { } as any, }; -// A trainer found by the search wants slots other devices hold: the card beside the tiles, OK stays usable -export const ConflictCard: Story = { +// A trainer found by the search wants slots other devices hold: a dialog over the tiles, which stay as they are +export const ConflictDialog: Story = { args: { title: 'Devices', capabilities: MOCK_CAPABILITIES_SWITCHED_OFF, @@ -299,9 +299,9 @@ export const ConflictCard: Story = { } as any, }; -export const ConflictCardMoreWaiting: Story = { +export const ConflictDialogMoreWaiting: Story = { args: { - ...ConflictCard.args, + ...ConflictDialog.args, pendingConflict: buildQueuedDetectionConflict({ onChoice: fn(), onDone: fn(), onDismiss: fn() }), } as any, }; @@ -309,7 +309,7 @@ export const ConflictCardMoreWaiting: Story = { // A pick in the Resistance list would take slots other devices hold: the list's second step export const ResistanceListConflictStep: Story = { args: { - ...ConflictCard.args, + ...ConflictDialog.args, pendingConflict: undefined, deviceSelection: { ...deviceSelectorArgs, diff --git a/src/pages/PairingPage/View.test.tsx b/src/pages/PairingPage/View.test.tsx index 907c0b23..76165d06 100644 --- a/src/pages/PairingPage/View.test.tsx +++ b/src/pages/PairingPage/View.test.tsx @@ -1,7 +1,11 @@ import React from 'react' -import { render, fireEvent, within } from '@testing-library/react-native' +import { Modal } from 'react-native' +import { act, render, fireEvent, within } from '@testing-library/react-native' import type { DeviceSelectionProps, PairingDisplayProps } from 'incyclist-services' import { PairingPageView } from './View' +import { ARMING_DELAY_MS } from '../../components/PairingConflictDialog' +import { CapabilityGrid } from '../../components/CapabilityGrid' +import { CapabilityStatusBars } from '../../components/CapabilityStatusBars' import { MOCK_PAIRING_BUTTON_SETS } from './PairingPage.mock' import { buildAsleepHelper, buildFallbackHelper, buildNoDeviceHelper, buildNoTrainerHelper, buildTrainerUnavailableHelper, @@ -28,7 +32,7 @@ jest.mock('../../components', () => { CapabilityGrid: jest.requireActual('../../components/CapabilityGrid').CapabilityGrid, CapabilityStatusBars: jest.requireActual('../../components/CapabilityStatusBars').CapabilityStatusBars, PairingHelperPanel: jest.requireActual('../../components/PairingHelperPanel').PairingHelperPanel, - PairingConflictCard: jest.requireActual('../../components/PairingConflictCard').PairingConflictCard, + PairingConflictDialog: jest.requireActual('../../components/PairingConflictDialog').PairingConflictDialog, PairingStatusLine: jest.requireActual('../../components/PairingStatusLine').PairingStatusLine, } }) @@ -101,21 +105,30 @@ describe('PairingPageView', () => { }) }) -describe('PairingPageView conflict card', () => { - it('on a phone: the card in the panel slot, the required row as status bars', () => { +describe('PairingPageView conflict dialog', () => { + beforeEach(() => { + jest.useFakeTimers() + }) + + afterEach(() => { + jest.useRealTimers() + }) + + const arm = () => act(() => { jest.advanceTimersByTime(ARMING_DELAY_MS) }) + + it('on a phone: the conflict in a dialog, with the phone subline', () => { setDimensions(...PHONE) - const { getByText } = render() + const { getByText, UNSAFE_root } = render() + expect(UNSAFE_root.findAllByType(Modal)).toHaveLength(1) expect(getByText('Tacx Neo 2T can also measure more')).toBeTruthy() - expect(getByText('Nothing changes until you choose.')).toBeTruthy() - expect(getByText('Smart trainer · Searching…')).toBeTruthy() + expect(getByText('Just found Tacx Neo 2T. Nothing changes until you choose.')).toBeTruthy() }) - it('on a tablet: the card beside the tiles, with the full subline', () => { + it('on a tablet: the full subline', () => { setDimensions(...TABLET) const conflict = buildDetectionConflict() - const { getByText, queryByText } = render() + const { getByText } = render() expect(getByText(conflict.subline.full)).toBeTruthy() - expect(queryByText('Smart trainer · Searching…')).toBeNull() }) it('shows how many more wait', () => { @@ -124,30 +137,39 @@ describe('PairingPageView conflict card', () => { expect(getByText('2 more')).toBeTruthy() }) - it('never blocks the page buttons: OK still works while the card shows', () => { + it.each([['phone', PHONE], ['tablet', TABLET]] as Array<[string, [number, number]]>)( + 'on a %s the tiles stay as they are behind the dialog: no status bars, and no side panel', (_layout, size) => { + setDimensions(...size) + const { queryByText, queryByLabelText, UNSAFE_root } = render() + expect(UNSAFE_root.findAllByType(CapabilityGrid)).toHaveLength(1) + expect(UNSAFE_root.findAllByType(CapabilityStatusBars)).toHaveLength(0) + expect(queryByText('Smart trainer · Searching…')).toBeNull() + expect(queryByLabelText('Close')).toBeNull() + }) + + it('on a phone the helper still turns the required row into status bars, as before', () => { setDimensions(...PHONE) - const onOK = jest.fn(async () => {}) - const { getByText } = render() - fireEvent.press(getByText('OK')) - expect(onOK).toHaveBeenCalledTimes(1) + const { UNSAFE_root } = render() + expect(UNSAFE_root.findAllByType(CapabilityStatusBars)).toHaveLength(1) + expect(UNSAFE_root.findAllByType(CapabilityGrid)).toHaveLength(0) }) - it('Done and ✕ go to the card\'s own handlers', () => { + it('Done, a tap outside and the back button go to the conflict\'s own handlers; there is no ✕', () => { setDimensions(...PHONE) const onDone = jest.fn() const onDismiss = jest.fn() - const { getByText, getByLabelText } = render() + const { getByText, queryByLabelText, UNSAFE_root } = render() + arm() + + expect(queryByLabelText('Close')).toBeNull() fireEvent.press(getByText('Done')) - fireEvent.press(getByLabelText('Close')) + UNSAFE_root.findByType(Modal).props.onRequestClose() + expect(onDone).toHaveBeenCalledTimes(1) expect(onDismiss).toHaveBeenCalledTimes(1) }) - it('renders the card every time it is given, whatever else the page shows', () => { + it('renders the dialog every time it is given, whatever else the page shows', () => { setDimensions(...PHONE) const { getByText } = render( { expect(getByText('Tacx Neo 2T can also measure more')).toBeTruthy() }) - it('without one, there is no card', () => { + it('without one, there is no dialog', () => { setDimensions(...PHONE) - const { queryByText } = render() + const { queryByText, UNSAFE_root } = render() expect(queryByText('Tacx Neo 2T can also measure more')).toBeNull() + expect(UNSAFE_root.findAllByType(Modal)).toHaveLength(0) + }) + + it('the Resistance list\'s own conflict step still opens and resolves in the list\'s dialog, apart from this one', () => { + setDimensions(...PHONE) + const stepDone = jest.fn() + const stepDismiss = jest.fn() + const listClose = jest.fn() + const { getByText, queryByText, UNSAFE_root } = render() + + expect(UNSAFE_root.findAllByType(Modal)).toHaveLength(1) + expect(getByText('Choose which device to use for each.')).toBeTruthy() + expect(queryByText('Just found Tacx Neo 2T. Nothing changes until you choose.')).toBeNull() + + // no arming delay on the list's step: it only ever opens in answer to the rider's own pick + fireEvent.press(getByText('Done')) + UNSAFE_root.findByType(Modal).props.onRequestClose() + + expect(stepDone).toHaveBeenCalledTimes(1) + expect(stepDismiss).toHaveBeenCalledTimes(1) + expect(listClose).not.toHaveBeenCalled() }) }) @@ -175,12 +220,12 @@ describe('PairingPageView fallback', () => { expect(onAction).toHaveBeenCalledTimes(1) }) - it('while the ride falls back, the dimmed Resistance bar beside a card shows its copy and a tap calls its onClick', () => { + it('while the ride falls back, the dimmed Resistance bar beside the helper shows its copy and a tap calls its onClick', () => { setDimensions(...PHONE) const onClick = jest.fn() const top = MOCK_CAPABILITIES_FALLBACK.top.map(t => (t.capability === 'control' ? { ...t, onClick } : t)) const { getByText } = render() expect(getByText('Tacx Flux · Your trainer · Tap to use again')).toBeTruthy() @@ -203,7 +248,7 @@ describe('PairingPageView never shows a "try again" button', () => { ['the fallback offered', { capabilities: MOCK_CAPABILITIES_TRAINER_UNAVAILABLE, helper: buildFallbackHelper() }], ['the ride falling back', { capabilities: MOCK_CAPABILITIES_FALLBACK }], ['Resistance switched off', { capabilities: MOCK_CAPABILITIES_SWITCHED_OFF }], - ['a conflict card', { pendingConflict: buildQueuedDetectionConflict() }], + ['a conflict found by the search', { pendingConflict: buildQueuedDetectionConflict() }], ['the Resistance list', { deviceSelection: resistanceList() }], ['the Resistance list\'s conflict step', { deviceSelection: resistanceList({ conflictStep: buildManualConflict() }) }], ] diff --git a/src/pages/PairingPage/View.tsx b/src/pages/PairingPage/View.tsx index e8b736bc..69f6715f 100644 --- a/src/pages/PairingPage/View.tsx +++ b/src/pages/PairingPage/View.tsx @@ -5,7 +5,7 @@ import type { PairingDisplayProps, InterfaceDisplayProps } from 'incyclist-servi import { colors, textSizes } from '../../theme' import { ButtonBar, CapabilityGrid, CapabilityStatusBars, MainBackground, InterfaceState, DeviceSelector, - PairingConflictCard, PairingHelperPanel, PairingStatusLine, + PairingConflictDialog, PairingHelperPanel, PairingStatusLine, } from '../../components' import { BleInterfaceSettings } from '../../components/BleInterfaceSettings' import { useScreenLayout } from '../../hooks' @@ -27,19 +27,16 @@ export const PairingPageView = (props: PairingDisplayProps) => { const onStatusLink = useMemo(() => getStatusLinkHandler(status, helper, interfaces), [status, helper, interfaces]) const helperOpen = helper !== undefined && helper.phase !== 'hidden' - // the panel beside the tiles holds one thing at a time: the helper, or a device-selection - // conflict. The page service only gives a conflict while the helper and the device lists are - // closed, so the conflict card is shown whenever it is given. - const conflictCard = helperOpen ? undefined : pendingConflict - const panelOpen = helperOpen || conflictCard !== undefined - // on a phone, the panel leaves too little room for tiles: the required row becomes status bars - const showBars = panelOpen && compact + // on a phone, the helper's panel leaves too little room for tiles: the required row becomes status bars + const showBars = helperOpen && compact const panelStyle = { width: compact ? PANEL_WIDTH_PHONE : PANEL_WIDTH_TABLET } return ( {deviceSelection && } + {/* the page service only gives a conflict while the helper and the device lists are closed */} + {pendingConflict && } {interfaces?.map((inter: InterfaceDisplayProps, index: number) => ( @@ -88,11 +85,9 @@ export const PairingPageView = (props: PairingDisplayProps) => { - {panelOpen && ( + {helperOpen && ( - {helperOpen - ? - : conflictCard && } + )} From 82e791728a8b0b7e9094131efb1585e52f3bb546 Mon Sep 17 00:00:00 2001 From: Guido Doumen Date: Tue, 10 Nov 2026 12:21:24 +0100 Subject: [PATCH 07/14] refactor(pairing): drop the side panel's title note Only the conflict card used it, to say how many more conflicts wait. The panel now holds just the helper, which never sets it. --- .../PairingSidePanel/PairingSidePanel.stories.tsx | 4 ---- .../PairingSidePanel/PairingSidePanel.test.tsx | 5 ++--- src/components/PairingSidePanel/PairingSidePanel.tsx | 12 +++--------- src/components/PairingSidePanel/types.ts | 2 -- 4 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/components/PairingSidePanel/PairingSidePanel.stories.tsx b/src/components/PairingSidePanel/PairingSidePanel.stories.tsx index 419c695f..443f938b 100644 --- a/src/components/PairingSidePanel/PairingSidePanel.stories.tsx +++ b/src/components/PairingSidePanel/PairingSidePanel.stories.tsx @@ -36,10 +36,6 @@ type Story = StoryObj export const Plain: Story = {} -export const WithTitleNote: Story = { - args: { titleNote: '1 more' }, -} - export const WithPinnedAction: Story = { args: { pinned: }, } diff --git a/src/components/PairingSidePanel/PairingSidePanel.test.tsx b/src/components/PairingSidePanel/PairingSidePanel.test.tsx index ff7a5d3c..ba5dec66 100644 --- a/src/components/PairingSidePanel/PairingSidePanel.test.tsx +++ b/src/components/PairingSidePanel/PairingSidePanel.test.tsx @@ -5,14 +5,13 @@ import { PairingSidePanel } from './PairingSidePanel' import { PairingSidePanelAction } from './PairingSidePanelAction' describe('PairingSidePanel', () => { - it('shows the title, the note beside it, the subline and the body', () => { + it('shows the title, the subline and the body', () => { const { getByText } = render( - + Body ) expect(getByText('A title')).toBeTruthy() - expect(getByText('2 more')).toBeTruthy() expect(getByText('A subline')).toBeTruthy() expect(getByText('Body')).toBeTruthy() }) diff --git a/src/components/PairingSidePanel/PairingSidePanel.tsx b/src/components/PairingSidePanel/PairingSidePanel.tsx index df3a46a6..ab7bb86b 100644 --- a/src/components/PairingSidePanel/PairingSidePanel.tsx +++ b/src/components/PairingSidePanel/PairingSidePanel.tsx @@ -8,15 +8,14 @@ const MIN_TOUCH_SIZE = 48 /** * The non-modal panel beside the tiles on the Pairing page: a header with the title and a close - * button, the body, and an optional area pinned at the bottom. The page shows one panel at a time in - * this slot - the helper or a device-selection conflict. + * button, the body, and an optional area pinned at the bottom. It holds the "can't find your + * trainer" helper. */ -export const PairingSidePanel = ({ title, titleNote, subline, onClose, children, pinned }: PairingSidePanelProps) => ( +export const PairingSidePanel = ({ title, subline, onClose, children, pinned }: PairingSidePanelProps) => ( {title} - {titleNote ? {titleNote} : null} void From 29785e6a76078dd84b0277a9944a1dd842a57475 Mon Sep 17 00:00:00 2001 From: Guido Doumen Date: Tue, 10 Nov 2026 13:00:03 +0100 Subject: [PATCH 08/14] fix(dialog): bound the content of non-scrollable dialogs, and allow a footer note With scrollable={false}, the children scroll themselves, but the content View around them never shrank: it grew to the children's full height and ran under the footer on short screens. It now shrinks to the space between header and footer. This also fixes the route details form at a short phone height, whose last rows were drawn behind the Cancel/Start buttons and could not be reached. A new footerNote shows a short line on the footer's line, left of the buttons, which stay centered. --- src/components/Dialog/Dialog.test.tsx | 52 ++++++++++++++++++++++++++- src/components/Dialog/Dialog.tsx | 51 +++++++++++++++++++++++--- src/components/Dialog/types.ts | 5 +++ 3 files changed, 103 insertions(+), 5 deletions(-) diff --git a/src/components/Dialog/Dialog.test.tsx b/src/components/Dialog/Dialog.test.tsx index 6746ec07..c8603bdd 100644 --- a/src/components/Dialog/Dialog.test.tsx +++ b/src/components/Dialog/Dialog.test.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { render } from '@testing-library/react-native'; +import { render, within } from '@testing-library/react-native'; import { Modal, ScrollView, StyleSheet, Text, View } from 'react-native'; import * as SafeAreaContext from 'react-native-safe-area-context'; import { EventLogger } from 'gd-eventlog'; @@ -31,6 +31,18 @@ describe('Dialog', () => { expect(UNSAFE_root.findAllByType(ScrollView).length).toBe(0); }); + it('when scrollable=false, lets the content shrink to the space between header and footer, so a child that scrolls itself is bounded', () => { + const { getByTestId } = render( + + content + + ); + + const style = StyleSheet.flatten(getByTestId('dialog-content').props.style); + expect(style.flexShrink).toBe(1); + expect(style.minHeight).toBe(0); + }); + it('still renders the children content when scrollable=false', () => { const { getByText } = render( @@ -225,3 +237,41 @@ describe('Dialog', () => { }); }); }); + +describe('Dialog footer note', () => { + const buttons = [{ id: 'done', label: 'Done', primary: true, onClick: () => {} }]; + + it('shows the note on the footer\'s line, with the buttons', () => { + const { getByTestId } = render( + + content + + ); + + const footer = within(getByTestId('dialog-footer')); + expect(footer.getByText('2 more to check')).toBeTruthy(); + expect(footer.getByText('Done')).toBeTruthy(); + expect(StyleSheet.flatten(getByTestId('dialog-footer').props.style).flexDirection).toBe('row'); + }); + + it('puts the note before the buttons, so it reads left of them', () => { + const { getByTestId } = render( + + content + + ); + + const texts = within(getByTestId('dialog-footer')).getAllByText(/./).map(t => t.props.children); + expect(texts).toEqual(['2 more to check', 'Done']); + }); + + it('without a note, the footer holds just the buttons, as before', () => { + const { getByTestId } = render( + + content + + ); + + expect(within(getByTestId('dialog-footer')).getAllByText(/./).map(t => t.props.children)).toEqual(['Done']); + }); +}); diff --git a/src/components/Dialog/Dialog.tsx b/src/components/Dialog/Dialog.tsx index 1c3af6f6..fdc91567 100644 --- a/src/components/Dialog/Dialog.tsx +++ b/src/components/Dialog/Dialog.tsx @@ -48,16 +48,35 @@ interface DialogContentProps { * inserting into a mounted one - see the FIXES_BACKLOG #52 comment on `buttonSignature` * below for the RN Fabric defect this works around. */ buttonSignature: string; + footerNote?: string; styles: ReturnType; } +interface DialogFooterWithNoteProps { + buttons: ButtonProps[]; + note: string; + styles: ReturnType; +} + +// The note takes the left of the footer's line and an equal spacer the right, so the buttons stay +// centered just as they are without a note. +const DialogFooterWithNote = ({ buttons, note, styles }: DialogFooterWithNoteProps) => ( + <> + + {note} + + + + +); + /** * Header + scrollable body + footer, shared by both the `'full'` variant's Modal and the * info/details variants' Modal - extracted from a byte-identical copy in both (FIXES_BACKLOG.md * item #63 - SonarCloud duplication; also resolves the paired cognitive-complexity smell on * `Dialog`, typescript:S3776, since the two branches no longer duplicate this much logic inline). */ -const DialogContent = ({ title, titleStyle, scrollable, children, buttons, buttonSignature, styles }: DialogContentProps) => ( +const DialogContent = ({ title, titleStyle, scrollable, children, buttons, buttonSignature, footerNote, styles }: DialogContentProps) => ( <> {title} @@ -73,15 +92,17 @@ const DialogContent = ({ title, titleStyle, scrollable, children, buttons, butto ) : ( - + {children} )} {buttons?.length ? ( - - + + {footerNote + ? + : } ) : <>} @@ -99,6 +120,7 @@ export const Dialog = ({ onOutsideClick, slideFrom, scrollable = true, + footerNote, }: PropsWithChildren) => { const { logEvent } = useLogging('Incyclist'); @@ -254,6 +276,7 @@ export const Dialog = ({ scrollable={scrollable} buttons={buttons} buttonSignature={buttonSignature} + footerNote={footerNote} styles={styles} > {children} @@ -291,6 +314,7 @@ export const Dialog = ({ scrollable={scrollable} buttons={buttons} buttonSignature={buttonSignature} + footerNote={footerNote} styles={styles} > {children} @@ -370,10 +394,29 @@ const getStyles = ({ width, height, minWidth, minHeight, variant = 'details', is padding: 2, color: colors.text, }, + // without Dialog's own ScrollView, the children scroll themselves: they need a bounded + // height, so the content shrinks to the space between header and footer instead of + // growing to the children's full height and running under the footer + contentBounded: { + flexShrink: 1, + minHeight: 0, + }, footer: { borderTopWidth: 1, borderTopColor: colors.dialogBorder ?? 'rgba(255,255,255,0.1)', }, + footerWithNote: { + flexDirection: 'row', + alignItems: 'center', + }, + footerSide: { + flex: 1, + paddingHorizontal: 16, + }, + footerNote: { + color: colors.text, + fontSize: textSizes.smallText, + }, fullScreenWrapper: { flex: 1, }, diff --git a/src/components/Dialog/types.ts b/src/components/Dialog/types.ts index cfc1da02..a5be208d 100644 --- a/src/components/Dialog/types.ts +++ b/src/components/Dialog/types.ts @@ -28,4 +28,9 @@ export interface DialogProps { * behaviour for all other Dialog consumers. */ scrollable?: boolean; + /** + * A short line on the footer's line, left of the buttons - e.g. how many more items wait for + * the action the primary button takes. Only shown together with `buttons`. + */ + footerNote?: string; } \ No newline at end of file From 3d2347d1cda88e9c24673ba7cd41f4ad03db3c4c Mon Sep 17 00:00:00 2001 From: Guido Doumen Date: Tue, 10 Nov 2026 13:00:05 +0100 Subject: [PATCH 09/14] fix(buttons): give compact buttons a 48 dp touch target The compact button stays about 34 high; its vertical hitSlop grows from 5 to 8, which takes the touch target to about 50, inside the bar's margin. --- src/components/ButtonBar/ButtonBar.test.tsx | 11 +++++++++++ src/components/ButtonBar/ButtonBar.tsx | 11 ++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/ButtonBar/ButtonBar.test.tsx b/src/components/ButtonBar/ButtonBar.test.tsx index f619dff1..ce0c11c6 100644 --- a/src/components/ButtonBar/ButtonBar.test.tsx +++ b/src/components/ButtonBar/ButtonBar.test.tsx @@ -42,6 +42,17 @@ describe('Button', () => { expect(touchable?.props.hitSlop.right).toBeLessThan(8); }); + // The compact button is about 34 high (14 text plus 8 padding above and below): with the + // vertical hitSlop, its touch target reaches the 48 dp minimum. + it('in compact layout, its touch target is at least 48 high', () => { + (useScreenLayout as jest.Mock).mockReturnValue('compact'); + + const { getByText } = render(