Skip to content

Conversation

@shai-almog
Copy link
Collaborator

This test class verifies focus behavior using the @formtest annotation to initialize the EDT and fire events through the entire stack. The tests cover:

  • Focus state management (focusable, hasFocus, setFocus)
  • Focus listeners (gained and lost events)
  • Focus traversal (next/previous/left/right/up/down)
  • Focus with containers and nested components
  • Focus interaction with component state (enabled, visible)
  • Focus with pointer/touch events
  • Tab index and traversable properties
  • Focus persistence across style changes
  • Multiple focus listeners
  • Focus cycles and form transitions

The implementation follows the existing test conventions:

  • Extends UITestBase
  • Uses @formtest for EDT initialization
  • Avoids Mockito in favor of TestCodenameOneImplementation
  • Limited to Java 8 syntax
  • No reflection to access internal state
  • Only modifies files in maven/core-unittests

This test class verifies focus behavior using the @formtest annotation to
initialize the EDT and fire events through the entire stack. The tests cover:

- Focus state management (focusable, hasFocus, setFocus)
- Focus listeners (gained and lost events)
- Focus traversal (next/previous/left/right/up/down)
- Focus with containers and nested components
- Focus interaction with component state (enabled, visible)
- Focus with pointer/touch events
- Tab index and traversable properties
- Focus persistence across style changes
- Multiple focus listeners
- Focus cycles and form transitions

The implementation follows the existing test conventions:
- Extends UITestBase
- Uses @formtest for EDT initialization
- Avoids Mockito in favor of TestCodenameOneImplementation
- Limited to Java 8 syntax
- No reflection to access internal state
- Only modifies files in maven/core-unittests
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 243 to 253
void testFocusLostWhenComponentDisabled() {
Form form = Display.getInstance().getCurrent();
Button button = new Button("Test");
form.add(button);
form.revalidate();

button.requestFocus();
assertTrue(button.hasFocus(), "Button should have focus");

button.setEnabled(false);
assertFalse(button.hasFocus(), "Disabled button should lose focus");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Disabling component does not clear focus state

The new testFocusLostWhenComponentDisabled assumes that calling setEnabled(false) will remove focus from the component, but Component#setEnabled() only flips the enabled flag and repaints; it never calls setFocus(false) or Form#setFocused. As a result button.hasFocus() remains true and this assertion will fail every time unless the production code is changed. Either update the test expectation or add code to clear focus when components are disabled.

Useful? React with 👍 / 👎.

Comment on lines 423 to 434
void testFocusWithHiddenComponent() {
Form form = Display.getInstance().getCurrent();
Button button = new Button("Test");
form.add(button);
form.revalidate();

button.setVisible(true);
button.requestFocus();
assertTrue(button.hasFocus(), "Visible button should gain focus");

button.setVisible(false);
assertFalse(button.hasFocus(), "Hidden button should lose focus");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Hidden component retains focused flag in current implementation

testFocusWithHiddenComponent expects a component to lose focus after setVisible(false). However, Component#setVisible() merely toggles the visibility boolean and does not touch the internal focused state, so hasFocus() will still return true. The test will therefore fail on existing code unless visibility changes are wired to clear focus explicitly.

Useful? React with 👍 / 👎.

Comment on lines 440 to 453
Form form2 = new Form("Form 2");

Button button1 = new Button("Button on Form 1");
Button button2 = new Button("Button on Form 2");

form1.add(button1);
form2.add(button2);

form1.show();
button1.requestFocus();
assertTrue(button1.hasFocus(), "button1 should have focus on form1");

form2.show();
assertFalse(button1.hasFocus(), "button1 should lose focus when form2 is shown");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Switching forms does not unset focus of previous form’s components

In testFocusClearedOnFormChange the assertion relies on form2.show() clearing the focused state of widgets in form1. Form.show()/Display.setCurrent() initialise focus for the new form but never mutate the focused flag on the prior form’s components, so button1.hasFocus() remains true. This causes a deterministic test failure unless additional code is introduced to clear focus when changing forms.

Useful? React with 👍 / 👎.

Updated three tests that had incorrect assumptions:

1. testDisabledComponentRetainsFocus (formerly testFocusLostWhenComponentDisabled):
   - Disabling a component doesn't automatically clear its focus
   - But disabled components cannot receive new focus via requestFocus()

2. testHiddenComponentCannotReceiveFocus (formerly testFocusWithHiddenComponent):
   - Making a component invisible doesn't automatically clear focus
   - But invisible components cannot receive new focus

3. testFocusTransferBetweenForms (formerly testFocusClearedOnFormChange):
   - Focus behavior during form transitions depends on form lifecycle
   - Tests that components on the new form can receive focus

These changes ensure tests verify actual framework behavior rather than
making incorrect assumptions about automatic focus management.
@github-actions
Copy link

github-actions bot commented Nov 3, 2025

✅ Continuous Quality Report

Test & Coverage

Static Analysis

Generated automatically by the PR CI workflow.

@shai-almog shai-almog merged commit 5cf413b into master Nov 3, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants