-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Fabric] Add onKeyPress for TextInput and enable legacyTextInputTests #12771
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f66acd0
add event
TatianaKapos 4602678
Change files
TatianaKapos 46983b9
add passing legacy textinput tests
TatianaKapos 99af5fc
add legacyTextInput tests
TatianaKapos 227d5c2
fix lint
TatianaKapos a45853f
update snapshot
TatianaKapos 4237780
try without accessibilityHint
TatianaKapos 17dff37
update snapshot
TatianaKapos 864ec11
refactor code
TatianaKapos 7cab637
add check for firing event twice
TatianaKapos afae113
snapshot update
TatianaKapos eb2cdb5
simplify code
TatianaKapos c53422c
snapshot
TatianaKapos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/react-native-windows-edbf9be7-245f-42c4-9644-96e44ed5d3d5.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "add fabric onKeyPress to textinput", | ||
| "packageName": "react-native-windows", | ||
| "email": "tatianakapos@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
packages/e2e-test-app-fabric/test/LegacyTextInputTest.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| /** | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT License. | ||
| * | ||
| * @format | ||
| */ | ||
| import {app} from '@react-native-windows/automation'; | ||
| import {goToComponentExample} from './RNTesterNavigation'; | ||
| import {verifyNoErrorLogs} from './Helpers'; | ||
| import {dumpVisualTree} from '@react-native-windows/automation-commands'; | ||
|
|
||
| beforeAll(async () => { | ||
| // If window is partially offscreen, tests will fail to click on certain elements | ||
| await app.setWindowPosition(0, 0); | ||
| await app.setWindowSize(1000, 1250); | ||
| await goToComponentExample('LegacyTextInputTest'); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await verifyNoErrorLogs(); | ||
| }); | ||
|
|
||
| describe('LegacyTextInputTest', () => { | ||
| test('Click on TextInput to focus', async () => { | ||
| const textInput = await textInputField(); | ||
| await textInput.click(); | ||
| await assertLogContains('onFocus'); | ||
| }); | ||
|
|
||
| test('Click on multiline TextInput to move focus away from single line TextInput', async () => { | ||
| const textInput = await multiLineTextInputField(); | ||
| await textInput.click(); | ||
| await assertLogContains('onBlur'); | ||
| }); | ||
| test('Type abc on TextInput', async () => { | ||
| const textInput = await textInputField(); | ||
| await textInput.setValue('abc'); | ||
| expect(await textInput.getText()).toBe('abc'); | ||
| await assertLogContains('onKeyPress key: c'); | ||
| }); | ||
| test('Type def on TextInput', async () => { | ||
| const textInput = await textInputField(); | ||
| await app.waitUntil( | ||
| async () => { | ||
| await textInput.setValue('def'); | ||
| return (await textInput.getText()) === 'def'; | ||
| }, | ||
| { | ||
| interval: 1500, | ||
| timeout: 5000, | ||
| timeoutMsg: `Unable to enter correct text.`, | ||
| }, | ||
| ); | ||
| expect(await textInput.getText()).toBe('def'); | ||
| }); | ||
| /* Issue to enable these tests: #12778 | ||
| test('Type hello world on autoCap TextInput', async () => { | ||
| const textInput = await autoCapsTextInputField(); | ||
| await textInput.setValue('def'); | ||
| expect(await textInput.getText()).toBe('DEF'); | ||
|
|
||
| await textInput.setValue('hello world'); | ||
| expect(await textInput.getText()).toBe('HELLO WORLD'); | ||
| }); | ||
| */ | ||
| test('Type abc on multiline TextInput then press Enter key', async () => { | ||
| const textInput = await textInputField(); | ||
| await textInput.setValue('abc'); | ||
| await textInput.addValue('Enter'); | ||
|
|
||
| await assertLogContains('onSubmitEditing text: abc'); | ||
| }); | ||
| test('Type abc on multiline TextInput', async () => { | ||
| const textInput = await multiLineTextInputField(); | ||
| await textInput.setValue('abc'); | ||
|
|
||
| expect(await textInput.getText()).toBe('abc'); | ||
| }); | ||
|
|
||
| test('Enter key then type def on multiline TextInput', async () => { | ||
| const textInput = await multiLineTextInputField(); | ||
|
|
||
| await textInput.addValue('End'); | ||
| await textInput.addValue('Enter'); | ||
| await textInput.addValue('def'); | ||
|
|
||
| expect(await textInput.getText()).toBe('abc\rdef'); | ||
| }); | ||
|
|
||
| test('TextInput onChange before onSelectionChange', async () => { | ||
| const textInput = await textInputField(); | ||
| await textInput.setValue('a'); | ||
| await assertLogContains('onChange text: a\nonSelectionChange range: 1,1'); | ||
| /* Issue to enable these tests: #12778 | ||
| await assertLogContainsInOrder([ | ||
| 'onChange text: a', | ||
| 'onSelectionChange range: 1,1', | ||
| ]); | ||
| */ | ||
| }); | ||
| }); | ||
|
|
||
| async function textInputField() { | ||
| const component = await app.findElementByTestID('textinput-field'); | ||
| await component.waitForDisplayed({timeout: 5000}); | ||
| return component; | ||
| } | ||
|
|
||
| /* Issue to enable these tests: #12778 | ||
| async function autoCapsTextInputField() { | ||
| const component = await app.findElementByTestID('auto-caps-textinput-field'); | ||
| await component.waitForDisplayed({timeout: 5000}); | ||
| return component; | ||
| } | ||
| */ | ||
|
|
||
| async function multiLineTextInputField() { | ||
| const component = await app.findElementByTestID('multi-line-textinput-field'); | ||
| await component.waitForDisplayed({timeout: 5000}); | ||
| return component; | ||
| } | ||
|
|
||
| async function assertLogContains(_text: string) { | ||
| const textLogComponent = await app.findElementByTestID('textinput-log'); | ||
| await textLogComponent.waitForDisplayed({timeout: 5000}); | ||
|
|
||
| const dump = await dumpVisualTree('textinput-log'); | ||
| expect(dump).toMatchSnapshot(); | ||
| /* | ||
| await app.waitUntil( | ||
| async () => { | ||
| const loggedText = await textLogComponent.getText(); | ||
| return loggedText.split('\n').includes(text); | ||
| }, | ||
| { | ||
| timeoutMsg: `"${await textLogComponent.getValue()}" "${await textLogComponent.getText()}" did not contain "${text}"`, | ||
| }, | ||
| ); | ||
| */ | ||
| } | ||
|
|
||
| /* | ||
| async function assertLogContainsInOrder(expectedLines: string[]) { | ||
| const textLogComponent = await app.findElementByTestID('textinput-log'); | ||
| await textLogComponent.waitForDisplayed({timeout: 5000}); | ||
|
|
||
| await app.waitUntil( | ||
| async () => { | ||
| const loggedText = await textLogComponent.getText(); | ||
| const actualLines = loggedText.split('\n'); | ||
| let previousIndex = Number.MAX_VALUE; | ||
| for (const line of expectedLines) { | ||
| const index = actualLines.findIndex(l => l === line); | ||
| if (index === -1 || index > previousIndex) { | ||
| return false; | ||
| } | ||
|
|
||
| previousIndex = index; | ||
| } | ||
|
|
||
| return true; | ||
| }, | ||
| { | ||
| timeoutMsg: `"${await textLogComponent.getText()}" did not contain lines "${expectedLines.join( | ||
| ', ', | ||
| )}"`, | ||
| }, | ||
| ); | ||
| } | ||
| */ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.