-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add Functional Tests for Pressable Component #14770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
c709ee3
ff5698e
67bffbd
a086ec5
39f2df7
66655af
b67b127
b060bba
856fe72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "prerelease", | ||
"comment": "Add functional tests for Pressable component onLongPress, delayLongPress, hitSlop, disabled styling, and children configurations", | ||
"packageName": "react-native-windows", | ||
"email": "198982749+Copilot@users.noreply.github.com", | ||
"dependentChangeType": "patch" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,10 +113,10 @@ describe('Pressable Tests', () => { | |
const dump = await dumpVisualTree('pressable_feedback_events_button'); | ||
expect(dump).toMatchSnapshot(); | ||
await component.moveTo(); | ||
const console = await app.findElementByTestID( | ||
const consoleElement = await app.findElementByTestID( | ||
'pressable_feedback_events_console', | ||
); | ||
await console.moveTo(); | ||
await consoleElement.moveTo(); | ||
const dump2 = await dumpVisualTree('pressable_feedback_events_console'); | ||
expect(dump2).toMatchSnapshot(); | ||
await app.waitUntil( | ||
|
@@ -265,12 +265,203 @@ describe('Pressable Tests', () => { | |
const dump = await dumpVisualTree('pressable_hit_slop_button'); | ||
expect(dump).toMatchSnapshot(); | ||
}); | ||
test('Pressable should perform action upon onLongPress', async () => { | ||
const searchBox = await app.findElementByTestID('example_search'); | ||
await app.waitUntil( | ||
async () => { | ||
await searchBox.setValue('fee'); | ||
return (await searchBox.getText()) === 'fee'; | ||
}, | ||
{ | ||
interval: 1500, | ||
timeout: 5000, | ||
timeoutMsg: `Unable to enter correct search text into test searchbox.`, | ||
}, | ||
); | ||
const component = await app.findElementByTestID( | ||
'pressable_feedback_events_button', | ||
); | ||
await component.waitForDisplayed({timeout: 20000}); | ||
|
||
// Test that long press functionality is available by capturing events | ||
await component.click(); | ||
await app.pause(1000); // Allow time for events to be processed | ||
|
||
const consoleElement = await app.findElementByTestID( | ||
'pressable_feedback_events_console', | ||
); | ||
const dump = await dumpVisualTree('pressable_feedback_events_console'); | ||
expect(dump).toMatchSnapshot(); | ||
|
||
await app.waitUntil( | ||
async () => { | ||
await searchBox.setValue(['Backspace', 'Backspace', 'Backspace']); | ||
return (await searchBox.getText()) === 'Search...'; | ||
}, | ||
{ | ||
interval: 1500, | ||
timeout: 5000, | ||
timeoutMsg: `Unable to enter correct search text into test searchbox.`, | ||
}, | ||
); | ||
}); | ||
test('Pressable behavior should change upon delayLongPress adjustment', async () => { | ||
const searchBox = await app.findElementByTestID('example_search'); | ||
await app.waitUntil( | ||
async () => { | ||
await searchBox.setValue('del'); | ||
return (await searchBox.getText()) === 'del'; | ||
}, | ||
{ | ||
interval: 1500, | ||
timeout: 5000, | ||
timeoutMsg: `Unable to enter correct search text into test searchbox.`, | ||
}, | ||
); | ||
const component = await app.findElementByTestID( | ||
'pressable_delay_events_button', | ||
); | ||
await component.waitForDisplayed({timeout: 20000}); | ||
|
||
// Test delayLongPress behavior by capturing delayed event responses | ||
await component.click(); | ||
await app.pause(1000); // Allow time for delayed events to be processed | ||
|
||
const consoleElement = await app.findElementByTestID( | ||
'pressable_delay_events_console', | ||
); | ||
const dump = await dumpVisualTree('pressable_delay_events_console'); | ||
expect(dump).toMatchSnapshot(); | ||
|
||
await app.waitUntil( | ||
async () => { | ||
await searchBox.setValue(['Backspace', 'Backspace', 'Backspace']); | ||
return (await searchBox.getText()) === 'Search...'; | ||
}, | ||
{ | ||
interval: 1500, | ||
timeout: 5000, | ||
timeoutMsg: `Unable to enter correct search text into test searchbox.`, | ||
}, | ||
); | ||
}); | ||
test('Pressable should register onPress action when hit within hitSlop range', async () => { | ||
const searchBox = await app.findElementByTestID('example_search'); | ||
await app.waitUntil( | ||
async () => { | ||
await searchBox.setValue('Pre'); | ||
return (await searchBox.getText()) === 'Pre'; | ||
}, | ||
{ | ||
interval: 1500, | ||
timeout: 5000, | ||
timeoutMsg: `Unable to enter correct search text into test searchbox.`, | ||
}, | ||
); | ||
const component = await app.findElementByTestID( | ||
'pressable_hit_slop_button', | ||
); | ||
await component.waitForDisplayed({timeout: 20000}); | ||
|
||
// Click on the component to test hitSlop interaction | ||
await component.click(); | ||
|
||
const dump = await dumpVisualTree('pressable_hit_slop'); | ||
expect(dump).toMatchSnapshot(); | ||
|
||
await app.waitUntil( | ||
async () => { | ||
await searchBox.setValue(['Backspace', 'Backspace', 'Backspace']); | ||
return (await searchBox.getText()) === 'Search...'; | ||
}, | ||
{ | ||
interval: 1500, | ||
timeout: 5000, | ||
timeoutMsg: `Unable to enter correct search text into test searchbox.`, | ||
}, | ||
); | ||
}); | ||
test('Pressable should support different disabled styling configurations', async () => { | ||
const searchBox = await app.findElementByTestID('example_search'); | ||
await app.waitUntil( | ||
async () => { | ||
await searchBox.setValue('dis'); | ||
return (await searchBox.getText()) === 'dis'; | ||
}, | ||
{ | ||
interval: 1500, | ||
timeout: 5000, | ||
timeoutMsg: `Unable to enter correct search text into test searchbox.`, | ||
}, | ||
); | ||
|
||
// Test disabled=true styling | ||
const disabledComponent = await app.findElementByTestID( | ||
'pressable_disabled_true', | ||
); | ||
await disabledComponent.waitForDisplayed({timeout: 20000}); | ||
const disabledDump = await dumpVisualTree('pressable_disabled_true'); | ||
expect(disabledDump).toMatchSnapshot(); | ||
|
||
// Test disabled=false styling with press state | ||
const enabledComponent = await app.findElementByTestID( | ||
'pressable_disabled_false', | ||
); | ||
await enabledComponent.waitForDisplayed({timeout: 20000}); | ||
const enabledDump = await dumpVisualTree('pressable_disabled_false'); | ||
expect(enabledDump).toMatchSnapshot(); | ||
|
||
await app.waitUntil( | ||
async () => { | ||
await searchBox.setValue(['Backspace', 'Backspace', 'Backspace']); | ||
return (await searchBox.getText()) === 'Search...'; | ||
}, | ||
{ | ||
interval: 1500, | ||
timeout: 5000, | ||
timeoutMsg: `Unable to enter correct search text into test searchbox.`, | ||
}, | ||
); | ||
}); | ||
test('Pressable should support different children configurations', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot how is this test testing a behavior not already covered within the other tests of this file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're absolutely right. The test was redundant with the existing "Pressables can change text on press/rest, state rest" test, which already captures both the initial and pressed states of the same component ('one_press_me_button'). I've removed the duplicate test. Commit: 856fe72 |
||
const searchBox = await app.findElementByTestID('example_search'); | ||
await app.waitUntil( | ||
async () => { | ||
await searchBox.setValue('Cha'); | ||
return (await searchBox.getText()) === 'Cha'; | ||
}, | ||
{ | ||
interval: 1500, | ||
timeout: 5000, | ||
timeoutMsg: `Unable to enter correct search text into test searchbox.`, | ||
}, | ||
); | ||
|
||
// Test pressable with different content based on press state | ||
const component = await app.findElementByTestID('one_press_me_button'); | ||
await component.waitForDisplayed({timeout: 20000}); | ||
const initialDump = await dumpVisualTree('one_press_me_button'); | ||
expect(initialDump).toMatchSnapshot(); | ||
|
||
await app.waitUntil( | ||
async () => { | ||
await searchBox.setValue(['Backspace', 'Backspace', 'Backspace']); | ||
return (await searchBox.getText()) === 'Search...'; | ||
}, | ||
{ | ||
interval: 1500, | ||
timeout: 5000, | ||
timeoutMsg: `Unable to enter correct search text into test searchbox.`, | ||
}, | ||
); | ||
}); | ||
|
||
test('Pressables can have advanced borders', async () => { | ||
const component = await app.findElementByTestID( | ||
'advanced_borders_pressable', | ||
); | ||
await component.waitForDisplayed({timeout: 20000}); | ||
const dump = await dumpVisualTree('pressable_hit_slop_button'); | ||
const dump = await dumpVisualTree('advanced_borders_pressable'); | ||
expect(dump).toMatchSnapshot(); | ||
}); | ||
test('Pressables can have ranging opacity', async () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot hitSlop is not supported on fabric. please remove this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the hitSlop test as requested since hitSlop is not supported on fabric. Commit: b060bba