mvysny / karibu-testing

Vaadin Server-Side Browserless Containerless Unit Testing
Apache License 2.0
105 stars 14 forks source link

Composite<Dialog> causes footer components to appear two times in Karibu tree dump #162

Closed mvysny closed 4 months ago

mvysny commented 4 months ago
        class MyDialog : Composite<Dialog>() {
            init {
                content.footer.add(Button("Hi!"))
            }
        }
        val dlg = MyDialog()
        dlg._expectOne<Button> { text = "Hi!" }

causes

ava.lang.AssertionError: /: Too many visible Buttons (2) in MyDialog[] matching Button and text='Hi!': [Button[text='Hi!'], Button[text='Hi!']]. Component tree:
└── MyDialog[]
    ├── Dialog[]
    │   └── Button[text='Hi!']
    └── Button[text='Hi!']

    at com.github.mvysny.kaributesting.v10.LocatorKt._find(Locator.kt:207)
    at com.github.mvysny.kaributesting.v10.LocatorKt._get(Locator.kt:155)
mvysny commented 4 months ago

The Composite class overrides getChildren() to return a stream with the wrapped component, but also getElement() returning the Element of the wrapped component. The latter causes the virtual child to be fetched as Composite direct child.

A fix for this seems to only consult getChildren() in case of Composite, and not the list of virtual children. Let me try.