mvysny / karibu-testing

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

Re-evaluate the decision on Polymer Templates #114

Closed mvysny closed 2 years ago

mvysny commented 2 years ago

A customer has a PolymerTemplate for the main app route, which nests individual routes inside. The routes are server-constructed and have proper state management (so they're not just "shells"); having access to the routes themselves would therefore be valuable.

Karibu-Testing should therefore expose an API which would allow the user to "override" children enumeration: it should be able to tell that a PolymerTemplate has particular children.

mvysny commented 2 years ago

Maybe overriding TestingLifecycleHook.getAllChildren() and providing access to specific child components per PolymerTemplate implementor would be the key to solution.

mvysny commented 2 years ago

Yup, that's the key. The solution is like this (Java):

public class MyLifecycleHook implements TestingLifecycleHook {

        @Override
        public void awaitAfterLookup() {
            TestingLifecycleHook.Companion.getDefault().awaitAfterLookup();
        }

        @Override
        public void awaitBeforeLookup() {
            TestingLifecycleHook.Companion.getDefault().awaitBeforeLookup();
        }

        @NotNull
        @Override
        public List<Component> getAllChildren(@NotNull Component component) {
            if (component instanceof BaseView) {
                return Arrays.asList(((BaseView) component).main);
            }
            return TestingLifecycleHook.Companion.getDefault().getAllChildren(component);
        }
}

To register this:

    @BeforeAll
    public static void configureKaribu() {
        TestingLifecycleHookKt.setTestingLifecycleHook(new MyLifecycleHook());
    }