|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. |
| 3 | + * Licensed under the MIT License. |
| 4 | + * |
| 5 | + * @format |
| 6 | + */ |
| 7 | + |
| 8 | +import { app } from '@react-native-windows/automation'; |
| 9 | +import { dumpVisualTree } from '@react-native-windows/automation-commands'; |
| 10 | +import { goToComponentExample } from './RNTesterNavigation'; |
| 11 | +import { verifyNoErrorLogs } from './Helpers'; |
| 12 | + |
| 13 | +beforeAll(async () => { |
| 14 | + // If window is partially offscreen, tests will fail to click on certain elements |
| 15 | + await app.setWindowPosition(0, 0); |
| 16 | + await app.setWindowSize(1000, 1250); |
| 17 | + await goToComponentExample('Hit Testing'); |
| 18 | +}); |
| 19 | + |
| 20 | +afterEach(async () => { |
| 21 | + await verifyNoErrorLogs(); |
| 22 | +}); |
| 23 | + |
| 24 | +async function verifyElementAccessibiltyValue(element: string, value: string) { |
| 25 | + const dump = await dumpVisualTree(element); |
| 26 | + expect(dump!["Automation Tree"]["ValuePattern.Value"]).toBe(value); |
| 27 | +} |
| 28 | + |
| 29 | +describe('Hit Testing', () => { |
| 30 | + |
| 31 | + test('Hit testing child outside the bounds of parents', async () => { |
| 32 | + const target = await app.findElementByTestID('visible-overflow-element'); |
| 33 | + |
| 34 | + // View starts in red state |
| 35 | + await verifyElementAccessibiltyValue('visible-overflow-element', 'red'); |
| 36 | + |
| 37 | + // The webdriverio package computes the offsets from the center point of the target. |
| 38 | + // This is within the bounds of the child and the parent, so should hitTest even with overflow:visible |
| 39 | + await target.click({ x: -50, y: -50, }); |
| 40 | + |
| 41 | + await verifyElementAccessibiltyValue('visible-overflow-element', 'green'); |
| 42 | + |
| 43 | + // The webdriverio package computes the offsets from the center point of the target. |
| 44 | + // This is within the bounds of the child, but outside the parents bounds |
| 45 | + await target.click({ x: 0, y: 0, }); |
| 46 | + |
| 47 | + // View should still be red, since the click should hit the pressable |
| 48 | + await verifyElementAccessibiltyValue('visible-overflow-element', 'red'); |
| 49 | + }); |
| 50 | + |
| 51 | + test('Overflow hidden prevents hittesting child', async () => { |
| 52 | + const target = await app.findElementByTestID('hidden-overflow-element'); |
| 53 | + |
| 54 | + // View starts in red state |
| 55 | + await verifyElementAccessibiltyValue('hidden-overflow-element', 'red'); |
| 56 | + |
| 57 | + // This is within the bounds of the child and the parent, so should hitTest even with overflow:hidden |
| 58 | + await target.click({ x: -50, y: -50, }); |
| 59 | + |
| 60 | + await verifyElementAccessibiltyValue('hidden-overflow-element', 'green'); |
| 61 | + |
| 62 | + // This is within the bounds of the child, but shouldn't hit test, since the parent is overflow:hidden |
| 63 | + await target.click({ x: 0, y: 0, }); |
| 64 | + |
| 65 | + // View should still be green, since the click shouldn't hit the pressable |
| 66 | + await verifyElementAccessibiltyValue('hidden-overflow-element', 'green'); |
| 67 | + }); |
| 68 | + |
| 69 | +}); |
0 commit comments