mvysny / karibu-testing

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

Header and Footer in Vaadin 23.1.0 Dialogs are not visible #115

Closed simasch closed 2 years ago

simasch commented 2 years ago

Vaadin added Header and Footer to the Dialog.

But neither is visible in Karibu Testing:

CompetitionDialog[]
        └── Div[]
            └── FormLayout[]
                ├── TextField[label='Name', value='Test']
                └── DatePicker[label='Date', value='2022-06-09']
mvysny commented 2 years ago

Hi, thanks! While this is fixed, here's a workaround:

        testingLifecycleHook = object : TestingLifecycleHook {
            private fun getChildrenOf(dialogHeaderFooter: Any): List<Component> {
                val rootField =
                    dialogHeaderFooter.javaClass.superclass.getDeclaredField("root")
                rootField.isAccessible = true
                val root = rootField.get(dialogHeaderFooter) as Element
                return root.children.map { it.component.orElse(null) } .toList().filterNotNull()
            }
            override fun getAllChildren(component: Component): List<Component> {
                var list = super.getAllChildren(component)
                if (component is Dialog) {
                    list = getChildrenOf(component.header) + list + getChildrenOf(component.footer)
                }
                return list
            }
        }