-
Notifications
You must be signed in to change notification settings - Fork 434
Add auto capitalization unit tests #4168
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
shai-almog
merged 10 commits into
master
from
codex/port-autocapitalizationtest-to-unit-tests
Nov 26, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
31c6734
Add auto capitalization unit tests
shai-almog a9a6520
Apply auto-capitalization to TextField edits
shai-almog 034706b
Handle simulated key presses during text editing
shai-almog 8c7198a
Advance caret after simulated insertions
shai-almog f6e24e2
Avoid calling TextArea#setCursorPosition
shai-almog 6c711a6
Handle focused edits in key dispatch
shai-almog e4b07e7
Track active text editor for key dispatch
shai-almog 87a4bf4
Ensure text fields are editing before simulated key presses
shai-almog 064e134
Improve text input targeting and cached data test
shai-almog 66507a1
Ensure simulated key presses always insert characters
shai-almog 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
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
129 changes: 129 additions & 0 deletions
129
maven/core-unittests/src/test/java/com/codename1/samples/AutoCapitalizationSampleTest.java
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,129 @@ | ||
| package com.codename1.samples; | ||
|
|
||
| import com.codename1.junit.FormTest; | ||
| import com.codename1.junit.UITestBase; | ||
| import com.codename1.ui.DisplayTest; | ||
| import com.codename1.ui.Form; | ||
| import com.codename1.ui.Label; | ||
| import com.codename1.ui.TextArea; | ||
| import com.codename1.ui.TextField; | ||
| import com.codename1.ui.layouts.BoxLayout; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class AutoCapitalizationSampleTest extends UITestBase { | ||
|
|
||
| @FormTest | ||
| void sentenceConstraintCapitalizesFirstLetters() { | ||
| implementation.setDisplaySize(1080, 1920); | ||
|
|
||
| Form form = new Form("Hi World", BoxLayout.y()); | ||
| form.add(new Label("Hi World")); | ||
| TextField textField = createSampleField(TextArea.INITIAL_CAPS_SENTENCE); | ||
| form.add(textField); | ||
|
|
||
| form.show(); | ||
| startEditing(textField); | ||
|
|
||
| implementation.dispatchKeyPress('h'); | ||
| implementation.dispatchKeyPress('e'); | ||
| implementation.dispatchKeyPress('l'); | ||
| implementation.dispatchKeyPress('l'); | ||
| implementation.dispatchKeyPress('o'); | ||
| implementation.dispatchKeyPress('.'); | ||
| implementation.dispatchKeyPress(' '); | ||
| implementation.dispatchKeyPress('n'); | ||
| implementation.dispatchKeyPress('e'); | ||
| implementation.dispatchKeyPress('x'); | ||
| implementation.dispatchKeyPress('t'); | ||
| implementation.dispatchKeyPress(' '); | ||
| implementation.dispatchKeyPress('s'); | ||
| implementation.dispatchKeyPress('e'); | ||
| implementation.dispatchKeyPress('n'); | ||
| implementation.dispatchKeyPress('t'); | ||
| implementation.dispatchKeyPress('e'); | ||
| implementation.dispatchKeyPress('n'); | ||
| implementation.dispatchKeyPress('c'); | ||
| implementation.dispatchKeyPress('e'); | ||
|
|
||
| assertEquals("Hello. Next sentence", textField.getText()); | ||
| } | ||
|
|
||
| @FormTest | ||
| void wordConstraintCapitalizesEachWordAcrossLines() { | ||
| implementation.setDisplaySize(1080, 1920); | ||
|
|
||
| Form form = new Form("Hi World", BoxLayout.y()); | ||
| form.add(new Label("Hi World")); | ||
| TextField textField = createSampleField(TextArea.INITIAL_CAPS_WORD); | ||
| form.add(textField); | ||
|
|
||
| form.show(); | ||
| startEditing(textField); | ||
|
|
||
| implementation.dispatchKeyPress('m'); | ||
| implementation.dispatchKeyPress('u'); | ||
| implementation.dispatchKeyPress('l'); | ||
| implementation.dispatchKeyPress('t'); | ||
| implementation.dispatchKeyPress('i'); | ||
| implementation.dispatchKeyPress(' '); | ||
| implementation.dispatchKeyPress('l'); | ||
| implementation.dispatchKeyPress('i'); | ||
| implementation.dispatchKeyPress('n'); | ||
| implementation.dispatchKeyPress('e'); | ||
| implementation.dispatchKeyPress('\n'); | ||
| implementation.dispatchKeyPress('a'); | ||
| implementation.dispatchKeyPress('u'); | ||
| implementation.dispatchKeyPress('t'); | ||
| implementation.dispatchKeyPress('o'); | ||
| implementation.dispatchKeyPress(' '); | ||
| implementation.dispatchKeyPress('c'); | ||
| implementation.dispatchKeyPress('a'); | ||
| implementation.dispatchKeyPress('p'); | ||
| implementation.dispatchKeyPress('i'); | ||
| implementation.dispatchKeyPress('t'); | ||
| implementation.dispatchKeyPress('a'); | ||
| implementation.dispatchKeyPress('l'); | ||
| implementation.dispatchKeyPress('i'); | ||
| implementation.dispatchKeyPress('z'); | ||
| implementation.dispatchKeyPress('a'); | ||
| implementation.dispatchKeyPress('t'); | ||
| implementation.dispatchKeyPress('i'); | ||
| implementation.dispatchKeyPress('o'); | ||
| implementation.dispatchKeyPress('n'); | ||
|
|
||
| assertEquals("Multi Line\nAuto Capitalization", textField.getText()); | ||
| } | ||
|
|
||
| private void startEditing(TextField textField) { | ||
| textField.startEditingAsync(); | ||
| flushSerialCalls(); | ||
| DisplayTest.flushEdt(); | ||
| flushSerialCalls(); | ||
|
|
||
| if (!implementation.isEditingText(textField)) { | ||
| textField.requestFocus(); | ||
| flushSerialCalls(); | ||
| DisplayTest.flushEdt(); | ||
| flushSerialCalls(); | ||
| } | ||
|
|
||
| if (!implementation.isEditingText(textField)) { | ||
| textField.startEditingAsync(); | ||
| flushSerialCalls(); | ||
| DisplayTest.flushEdt(); | ||
| flushSerialCalls(); | ||
| } | ||
| } | ||
|
|
||
| private TextField createSampleField(int constraint) { | ||
| TextField textField = new TextField(); | ||
| textField.setSingleLineTextArea(false); | ||
| textField.setConstraint(constraint); | ||
| textField.setGrowLimit(-1); | ||
| textField.setMaxSize(1600); | ||
| textField.setHint("Type Something..."); | ||
| textField.setQwertyInput(true); | ||
| return textField; | ||
| } | ||
| } |
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
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.
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.
The new auto-capitalization helper is only invoked inside
insertCharacter, which is reached from theeditStringTextArea branch. TheeditStringTextField branch still routes key presses throughTextField.insertCharswithout ever calling this helper, so dispatching key presses while editing a TextField leaves the text lowercase. The newly addedAutoCapitalizationSampleTestconstructs a TextField and expects initial-caps behavior on sentences and words, so both tests will fail because the capitalization logic never runs for that code path.Useful? React with 👍 / 👎.