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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 60 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"axios": "^1.17.0",
"events": "^3.3.0",
"gd-eventlog": "^0.1.27",
"incyclist-services": "^1.9.21",
"incyclist-services": "^1.9.22",
"mqtt": "^5.15.2",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
Expand Down
11 changes: 11 additions & 0 deletions src/components/ButtonBar/ButtonBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Button id="a" label="OK" onClick={jest.fn()} />);
const { top, bottom } = getByText('OK').parent?.parent?.props.hitSlop;

expect(34 + top + bottom).toBeGreaterThanOrEqual(48);
});

it('still fires onClick when compact', () => {
(useScreenLayout as jest.Mock).mockReturnValue('compact');
const onClick = jest.fn();
Expand Down
11 changes: 6 additions & 5 deletions src/components/ButtonBar/ButtonBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { colors } from '../../theme'
import { ButtonBarProps, ButtonProps } from './types'
import { useLogging, useScreenLayout } from '../../hooks'

// Compact mode's ~34px visible button is under the 44px touch-target guideline, but its small
// Compact mode's ~34px visible button is under the 48dp touch-target guideline, but its small
// footprint is intentional (saves vertical space in landscape on phones as short as ~320px tall)
// - expand the tappable region via hitSlop instead of growing the button. Horizontal slop must
// stay under btnCompact's 8px marginHorizontal (styles.btn) so adjacent buttons' hit-slop
// regions can't overlap and turn near-misses into taps on the wrong button.
const COMPACT_HIT_SLOP = { top: 5, bottom: 5, left: 6, right: 6 }
// - expand the tappable region via hitSlop instead of growing the button: 8 above and below takes
// it to ~50. That stays inside the bar's 12px vertical margin. Horizontal slop must stay under
// btnCompact's 8px marginHorizontal (styles.btn) so adjacent buttons' hit-slop regions can't
// overlap and turn near-misses into taps on the wrong button.
const COMPACT_HIT_SLOP = { top: 8, bottom: 8, left: 6, right: 6 }

export const Button = ({ id,label, primary,attention, disabled, onClick }:ButtonProps) => {
const {logEvent} = useLogging('Incyclist')
Expand Down
33 changes: 33 additions & 0 deletions src/components/CapabilityStatusBars/CapabilityStatusBars.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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(<CapabilityStatusBars capabilities={MOCK_CAPABILITIES_FALLBACK} />)
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(<CapabilityStatusBars capabilities={{ ...MOCK_CAPABILITIES_FALLBACK, top: tiles }} />)
fireEvent.press(getByText('RESISTANCE'))
expect(onClick).toHaveBeenCalledTimes(1)
})

it('renders nothing without capabilities', () => {
const { toJSON } = render(<CapabilityStatusBars />)
expect(toJSON()).toBeNull()
Expand Down
Loading
Loading