Skip to content

Bug: The mouse_click function in wx/_interaction_helpers.py do not set focus to current control #1780

@pbrod

Description

@pbrod

The mouse_click function in for wx located in traitsui/testing/tester/_ui_tester_registry/wx/_interaction_helpers.py do not set focus to current control. This result in test failures when testing the RangeTextEditor for wx, because
when editing the text part of a range control box and clicking on the OK button will not update the value of the HasTraits class
since the focus will not change in the test-envirionment as exemplified in the following test:

class NumberWithRangeEditor(HasTraits):
    """Dialog containing a RangeEditor in 'spinner' mode for an Int."""

    number = Int()

    traits_view = View(
        Item(label="Range should be 3 to 8. Enter 1, then press OK"),
        Item("number", editor=RangeEditor(low=3, high=8, mode="text",
                                          enter_set=True,
                                          auto_set=False)),
        buttons=["OK", "Cancel"],
    )

class TestRangeEditorText(BaseTestMixin, unittest.TestCase):
    def setUp(self):
        BaseTestMixin.setUp(self)

    def tearDown(self):
        BaseTestMixin.tearDown(self)

    @requires_toolkit([ToolkitName.qt, ToolkitName.wx]) 
    def test_text_editing(self):
        num = NumberWithRangeEditor()
        assert num.number == 0
        tester = UITester()
        with tester.create_ui(num) as ui:
            text = tester.find_by_name(ui, "number")
            displayed = text.inspect(DisplayedText())
            assert displayed == '3'
            assert num.number == 3
            text.perform(command.KeyClick("Backspace"))
            text.perform(command.KeyClick("4"))
            displayed = text.inspect(DisplayedText())
            assert displayed == '4'
            assert num.number == 3

            cancel_button = tester.find_by_id(ui, "Cancel")
            cancel_button.perform(command.MouseClick())

        assert num.number == 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions