mvysny / karibu-testing

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

URL parameter change assertions #138

Closed machine88 closed 1 year ago

machine88 commented 1 year ago

Currently using Vaadin there are two mechanisms to change the URL: 1- An entity is selected from a ConfigurableGrid using getUI().get().getPage().getHistory().replaceState( null, RouteConfiguration.forSessionScope().getUrl(getClass(), current.getId()));

result = /subroute/id

On a cancel action the URL is modified using UI.getCurrent() .navigate( getUI().get() .getInternals() .getActiveViewLocation() .getPath() .replaceFirst( "/\w+", "")); result = /subroute

Using Karibu how do we test this function to confirm URL changes.? I have tried using var path = view.root.UI.get().internals.activeViewLocation.path to assert for the URL string however only the subroute is there.

mvysny commented 1 year ago

Yup, NavigatorKt.currentPath (which relies on UI.getCurrent()?.internals?.activeViewLocation?.pathWithQueryParameters) is the only way currently. I guess that it doesn't take History.replaceState() into account though. However, that actually might work as expected. The reason is that replaceState() doesn't actually perform the navigation, it just overwrites the URL in browser's address bar (if I understand correctly). That means that the activeViewLocation should keep returning the old value, since it's the URL of the active view which hasn't been changed via replaceState(). In order to observe the history state, please try registering History.setHistoryStateChangeHandler() from Karibu tests... even though it may probably not fire since it's triggered by an event coming from a browser.

If you'd like to have access to the latest history state, I'll have to devise some kind of browser mocking solution.

mvysny commented 1 year ago

Closing as won't fix, please reopen and add more details if Karibu should provide a way to retrieve the last state from History.