|
2 | 2 | import { useState } from 'react'; |
3 | 3 | import type { ReactNode } from 'react'; |
4 | 4 | import { StyleSheet, Text, View } from 'react-native'; |
| 5 | +import type { AccessibilityActionEvent } from 'react-native'; |
| 6 | +import type { WdioStory } from '@fluentui-react-native/storybook-desktop/testing'; |
5 | 7 |
|
6 | 8 | import type { Meta, StoryObj } from '@storybook/react-native'; |
7 | 9 |
|
8 | 10 | import { Radio } from './radio'; |
| 11 | +import type { RadioProps } from './radio.types'; |
| 12 | +import { StoryStatus } from '../../common/StoryStatus.story-helpers'; |
9 | 13 |
|
10 | 14 | type StoryGroupProps = { |
11 | 15 | children: ReactNode; |
@@ -48,12 +52,100 @@ const meta: Meta<typeof Radio> = { |
48 | 52 |
|
49 | 53 | export default meta; |
50 | 54 |
|
51 | | -type Story = StoryObj<typeof Radio>; |
| 55 | +type Story = WdioStory<StoryObj<typeof Radio>>; |
52 | 56 |
|
53 | 57 | export const Default: Story = {}; |
54 | 58 |
|
| 59 | +export const NativeSelectionSemantics: Story = { |
| 60 | + render: () => { |
| 61 | + const Scene = () => { |
| 62 | + const [actions, setActions] = useState(0); |
| 63 | + const [presses, setPresses] = useState(0); |
| 64 | + const [lastAction, setLastAction] = useState('none'); |
| 65 | + const recordAction = (event: AccessibilityActionEvent) => { |
| 66 | + setLastAction(event.nativeEvent.actionName); |
| 67 | + setActions((value) => value + 1); |
| 68 | + }; |
| 69 | + return ( |
| 70 | + <View style={styles.story}> |
| 71 | + <Radio |
| 72 | + label="Unselected option" |
| 73 | + selected={false} |
| 74 | + testID="radio-native-off" |
| 75 | + onAccessibilityAction={recordAction} |
| 76 | + onPress={() => setPresses((value) => value + 1)} |
| 77 | + /> |
| 78 | + <Radio label="Selected option" selected testID="radio-native-on" /> |
| 79 | + <Radio |
| 80 | + label="Disabled option" |
| 81 | + selected |
| 82 | + disabled |
| 83 | + testID="radio-native-disabled" |
| 84 | + onAccessibilityAction={recordAction} |
| 85 | + onPress={() => setPresses((value) => value + 1)} |
| 86 | + /> |
| 87 | + <StoryStatus testID="radio-native-actions">{String(actions)}</StoryStatus> |
| 88 | + <StoryStatus testID="radio-native-presses">{String(presses)}</StoryStatus> |
| 89 | + <StoryStatus testID="radio-native-last-action">{lastAction}</StoryStatus> |
| 90 | + </View> |
| 91 | + ); |
| 92 | + }; |
| 93 | + return <Scene />; |
| 94 | + }, |
| 95 | + wdio: { |
| 96 | + 'RAD-003 RAD-005 Win32 exposes native RadioButton selection, names and disabled state': async ({ browser, expect, platform, skip }) => { |
| 97 | + if (platform !== 'win32') { |
| 98 | + skip('This case qualifies Win32 UI Automation SelectionItem projection.'); |
| 99 | + return; |
| 100 | + } |
| 101 | + for (const [id, name, selected] of [ |
| 102 | + ['radio-native-off', 'Unselected option', false], |
| 103 | + ['radio-native-on', 'Selected option', true], |
| 104 | + ['radio-native-disabled', 'Disabled option', true], |
| 105 | + ] as const) { |
| 106 | + const radio = await browser.$(`~${id}`); |
| 107 | + expect(await radio.getTagName()).toBe('radio'); |
| 108 | + expect(await radio.getProperty('name')).toBe(name); |
| 109 | + expect(await radio.getProperty('selected')).toBe(selected); |
| 110 | + } |
| 111 | + await expect(await browser.$('~radio-native-disabled')).toBeDisabled(); |
| 112 | + }, |
| 113 | + 'RAD-003 Win32 Select forwards once without self-selection or presses and disabled public activation rejects': async ({ |
| 114 | + browser, |
| 115 | + expect, |
| 116 | + platform, |
| 117 | + skip, |
| 118 | + }) => { |
| 119 | + if (platform !== 'win32') { |
| 120 | + skip('This case qualifies Win32 UI Automation Select transport.'); |
| 121 | + return; |
| 122 | + } |
| 123 | + const radio = await browser.$('~radio-native-off'); |
| 124 | + const disabled = await browser.$('~radio-native-disabled'); |
| 125 | + const actions = await browser.$('~radio-native-actions'); |
| 126 | + const presses = await browser.$('~radio-native-presses'); |
| 127 | + await expect(actions).toHaveAttribute('name', '0'); |
| 128 | + await radio.click(); |
| 129 | + await expect(actions).toHaveAttribute('name', '1'); |
| 130 | + await expect(await browser.$('~radio-native-last-action')).toHaveAttribute('name', 'Select'); |
| 131 | + await expect(presses).toHaveAttribute('name', '0'); |
| 132 | + expect(await radio.getProperty('selected')).toBe(false); |
| 133 | + let rejection: unknown; |
| 134 | + try { |
| 135 | + await disabled.click(); |
| 136 | + } catch (error) { |
| 137 | + rejection = error; |
| 138 | + } |
| 139 | + expect(rejection).toBeDefined(); |
| 140 | + await expect(actions).toHaveAttribute('name', '1'); |
| 141 | + await expect(presses).toHaveAttribute('name', '0'); |
| 142 | + expect(await disabled.getProperty('selected')).toBe(true); |
| 143 | + }, |
| 144 | + }, |
| 145 | +}; |
| 146 | + |
55 | 147 | export const Overview: Story = { |
56 | | - render: ({ label, secondaryText }) => ( |
| 148 | + render: ({ label, secondaryText }: RadioProps) => ( |
57 | 149 | <View style={styles.story}> |
58 | 150 | <StoryGroup label="Selection"> |
59 | 151 | <Radio label={label} secondaryText={secondaryText} showSecondaryText /> |
|
0 commit comments