|
1 | 1 | import { TestDefinition, TestMethod, TestHelper } from './testHelper' |
| 2 | +import { FocusZoneMode, FocusZoneDefinition } from '../../../src/lib/accessibility/types' |
2 | 3 | import * as keyboardKey from 'keyboard-key' |
3 | 4 |
|
4 | 5 | const definitions: TestDefinition[] = [] |
@@ -181,44 +182,91 @@ definitions.push({ |
181 | 182 | }, |
182 | 183 | }) |
183 | 184 |
|
| 185 | +// Embeds FocusZone into component allowing arrow key navigation through the children of the component. |
| 186 | +definitions.push({ |
| 187 | + regexp: /Embeds FocusZone into component allowing arrow key navigation through the children of the component\.+/g, |
| 188 | + testMethod: (parameters: TestMethod) => { |
| 189 | + const actualFocusZone = parameters.behavior({}).focusZone |
| 190 | + |
| 191 | + const expectedFocusZone: FocusZoneDefinition = { |
| 192 | + mode: FocusZoneMode.Embed, |
| 193 | + props: { |
| 194 | + isCircularNavigation: false, |
| 195 | + preventDefaultWhenHandled: true, |
| 196 | + }, |
| 197 | + } |
| 198 | + |
| 199 | + verifyFocusZones(expectedFocusZone, actualFocusZone) |
| 200 | + }, |
| 201 | +}) |
| 202 | + |
| 203 | +// [Circular navigation] Embeds FocusZone into component allowing circular arrow key navigation through the children of the component. |
| 204 | +definitions.push({ |
| 205 | + regexp: /Embeds FocusZone into component allowing circular arrow key navigation through the children of the component\.+/g, |
| 206 | + testMethod: (parameters: TestMethod) => { |
| 207 | + const actualFocusZone = parameters.behavior({}).focusZone |
| 208 | + |
| 209 | + const expectedFocusZone: FocusZoneDefinition = { |
| 210 | + mode: FocusZoneMode.Embed, |
| 211 | + props: { |
| 212 | + isCircularNavigation: true, |
| 213 | + preventDefaultWhenHandled: true, |
| 214 | + }, |
| 215 | + } |
| 216 | + |
| 217 | + verifyFocusZones(expectedFocusZone, actualFocusZone) |
| 218 | + }, |
| 219 | +}) |
| 220 | + |
184 | 221 | // Wraps component in FocusZone allowing arrow key navigation through the children of the component. |
185 | 222 | definitions.push({ |
186 | 223 | regexp: /Wraps component in FocusZone allowing arrow key navigation through the children of the component\.+/g, |
187 | 224 | testMethod: (parameters: TestMethod) => { |
188 | | - const property = { |
189 | | - isCircularNavigation: undefined, |
190 | | - preventDefaultWhenHandled: undefined, |
| 225 | + const actualFocusZone = parameters.behavior({}).focusZone |
| 226 | + |
| 227 | + const expectedFocusZone: FocusZoneDefinition = { |
| 228 | + mode: FocusZoneMode.Wrap, |
| 229 | + props: { |
| 230 | + isCircularNavigation: false, |
| 231 | + preventDefaultWhenHandled: true, |
| 232 | + }, |
191 | 233 | } |
192 | | - const expectedMode = parameters.behavior(property).focusZone.mode |
193 | | - const expectedIsCircularNav = parameters.behavior(property).focusZone.props.isCircularNavigation |
194 | | - const expectedPreventDefault = parameters.behavior(property).focusZone.props |
195 | | - .preventDefaultWhenHandled |
196 | | - |
197 | | - expect(expectedMode).toBe(1) |
198 | | - expect(expectedIsCircularNav).toBe(false) |
199 | | - expect(expectedPreventDefault).toBe(true) |
| 234 | + |
| 235 | + verifyFocusZones(expectedFocusZone, actualFocusZone) |
200 | 236 | }, |
201 | 237 | }) |
202 | 238 |
|
203 | 239 | // [Circular navigation] Wraps component in FocusZone allowing circular arrow key navigation through the children of the component. |
204 | 240 | definitions.push({ |
205 | 241 | regexp: /Wraps component in FocusZone allowing circular arrow key navigation through the children of the component\.+/g, |
206 | 242 | testMethod: (parameters: TestMethod) => { |
207 | | - const property = { |
208 | | - isCircularNavigation: undefined, |
209 | | - preventDefaultWhenHandled: undefined, |
| 243 | + const actualFocusZone = parameters.behavior({}).focusZone |
| 244 | + |
| 245 | + const expectedFocusZone: FocusZoneDefinition = { |
| 246 | + mode: FocusZoneMode.Wrap, |
| 247 | + props: { |
| 248 | + isCircularNavigation: true, |
| 249 | + preventDefaultWhenHandled: true, |
| 250 | + }, |
210 | 251 | } |
211 | | - const expectedMode = parameters.behavior(property).focusZone.mode |
212 | | - const expectedIsCircularNav = parameters.behavior(property).focusZone.props.isCircularNavigation |
213 | | - const expectedPreventDefault = parameters.behavior(property).focusZone.props |
214 | | - .preventDefaultWhenHandled |
215 | | - |
216 | | - expect(expectedMode).toBe(1) |
217 | | - expect(expectedIsCircularNav).toBe(true) |
218 | | - expect(expectedPreventDefault).toBe(true) |
| 252 | + |
| 253 | + verifyFocusZones(expectedFocusZone, actualFocusZone) |
219 | 254 | }, |
220 | 255 | }) |
221 | 256 |
|
| 257 | +function verifyFocusZones( |
| 258 | + expectedFocusZone: FocusZoneDefinition, |
| 259 | + actualFocusZone: FocusZoneDefinition, |
| 260 | +) { |
| 261 | + expect(expectedFocusZone.mode).toBe(actualFocusZone.mode) |
| 262 | + expect(expectedFocusZone.props.isCircularNavigation).toBe( |
| 263 | + actualFocusZone.props.isCircularNavigation, |
| 264 | + ) |
| 265 | + expect(expectedFocusZone.props.preventDefaultWhenHandled).toBe( |
| 266 | + actualFocusZone.props.preventDefaultWhenHandled, |
| 267 | + ) |
| 268 | +} |
| 269 | + |
222 | 270 | // [FocusTrapZone] Traps focus inside component |
223 | 271 | definitions.push({ |
224 | 272 | regexp: /Traps focus inside component/, |
|
0 commit comments