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
18 changes: 10 additions & 8 deletions apps/mobile/src/components/PickerSchedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import { ScrollView, Text, TouchableOpacity, View } from 'react-native'

import { styles } from '../styles'

export function PickerSchedule({
left,
middle,
right,
}: {
export type PickerScheduleProps = {
left: {
disabled?: boolean,
onChange: (value: typeof left.options[number]['value']) => void,
onChange: (value: string) => void,
options: { label: string, value: string }[],
value: typeof left.options[number]['value'],
value: string,
},
middle: {
disabled?: boolean,
Expand All @@ -24,7 +20,13 @@ export function PickerSchedule({
onChange: (value: 'day' | 'week' | 'year') => void,
value: 'day' | 'week' | 'year',
},
}) {
}

export function PickerSchedule({
left,
middle,
right,
}: PickerScheduleProps) {
const justLeft = middle.disabled && right.disabled

return (
Expand Down
71 changes: 71 additions & 0 deletions apps/mobile/src/components/__tests__/PickerSchedule.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react'
import { render, screen } from '@testing-library/react-native'

import { PickerSchedule, type PickerScheduleProps } from '../PickerSchedule'

describe('PickerSchedule', () => {
const defaultLeft: PickerScheduleProps['left'] = {
options: [{ label: 'Option 1', value: 'option1' }],
value: 'option1',
onChange: jest.fn(),
}

const defaultRight: PickerScheduleProps['right'] = {
value: 'day',
onChange: jest.fn(),
}

describe('Right-most labels', () => {
it('shows singular labels (day, week, year) when middle selection is 1', () => {
render(
<PickerSchedule
left={defaultLeft}
middle={{ value: 1, onChange: jest.fn() }}
right={defaultRight}
/>
)

expect(screen.getByText('day')).toBeTruthy()
expect(screen.getByText('week')).toBeTruthy()
expect(screen.getByText('year')).toBeTruthy()

// Ensure plural forms are not present
expect(screen.queryByText('days')).toBeNull()
expect(screen.queryByText('weeks')).toBeNull()
expect(screen.queryByText('years')).toBeNull()
})

it('shows plural labels (days, weeks, years) when middle selection is not 1', () => {
render(
<PickerSchedule
left={defaultLeft}
middle={{ value: 2, onChange: jest.fn() }}
right={defaultRight}
/>
)

expect(screen.getByText('days')).toBeTruthy()
expect(screen.getByText('weeks')).toBeTruthy()
expect(screen.getByText('years')).toBeTruthy()

// Ensure singular forms are not present
expect(screen.queryByText('day')).toBeNull()
expect(screen.queryByText('week')).toBeNull()
expect(screen.queryByText('year')).toBeNull()
})

it('shows plural labels when middle selection is a larger number', () => {
render(
<PickerSchedule
left={defaultLeft}
middle={{ value: 7, onChange: jest.fn() }}
right={defaultRight}
/>
)

expect(screen.getByText('days')).toBeTruthy()
expect(screen.getByText('weeks')).toBeTruthy()
expect(screen.getByText('years')).toBeTruthy()
})
})
})
Loading