|
| 1 | +package com.vaadin.flow; |
| 2 | + |
| 3 | +import org.junit.Assert; |
| 4 | +import org.junit.Test; |
| 5 | +import org.openqa.selenium.TimeoutException; |
| 6 | + |
| 7 | +import com.vaadin.flow.component.html.testbench.SpanElement; |
| 8 | +import com.vaadin.flow.testutil.ChromeBrowserTest; |
| 9 | + |
| 10 | +public class ForwardTargetIT extends ChromeBrowserTest { |
| 11 | + |
| 12 | + public static final String FORWARD_TARGET_VIEW = "/view/com.vaadin.flow.ForwardTargetView"; |
| 13 | + |
| 14 | + // Test for https://github.com/vaadin/flow/issues/19794 |
| 15 | + @Test |
| 16 | + public void testUrlIsCorrectAfterForward() { |
| 17 | + getDriver().get(getTestURL(getRootURL(), FORWARD_TARGET_VIEW, null)); |
| 18 | + |
| 19 | + try { |
| 20 | + waitUntil(arg -> driver.getCurrentUrl() |
| 21 | + .endsWith(FORWARD_TARGET_VIEW)); |
| 22 | + } catch (TimeoutException e) { |
| 23 | + Assert.fail("URL wasn't updated to expected one: " |
| 24 | + + FORWARD_TARGET_VIEW); |
| 25 | + } |
| 26 | + |
| 27 | + getDriver().get(getTestURL(getRootURL(), |
| 28 | + "/view/com.vaadin.flow.ForwardingView", null)); |
| 29 | + |
| 30 | + try { |
| 31 | + waitUntil(arg -> driver.getCurrentUrl() |
| 32 | + .endsWith(FORWARD_TARGET_VIEW)); |
| 33 | + } catch (TimeoutException e) { |
| 34 | + Assert.fail("URL wasn't updated to expected one: " |
| 35 | + + FORWARD_TARGET_VIEW); |
| 36 | + } |
| 37 | + |
| 38 | + Assert.assertTrue("URL was not the expected one after forward call", |
| 39 | + driver.getCurrentUrl().endsWith(FORWARD_TARGET_VIEW)); |
| 40 | + } |
| 41 | + |
| 42 | + // Test for https://github.com/vaadin/flow/issues/19822 |
| 43 | + @Test |
| 44 | + public void testSetParameterCalledOnlyOnceAfterForward() { |
| 45 | + getDriver().get(getTestURL(getRootURL(), |
| 46 | + "/view/com.vaadin.flow.ForwardingToParametersView", null)); |
| 47 | + |
| 48 | + try { |
| 49 | + waitUntil(arg -> driver.getCurrentUrl().endsWith( |
| 50 | + "/view/com.vaadin.flow.ForwardTargetWithParametersView")); |
| 51 | + } catch (TimeoutException e) { |
| 52 | + Assert.fail("URL wasn't updated to expected one: " |
| 53 | + + "/view/com.vaadin.flow.ForwardTargetWithParametersView"); |
| 54 | + } |
| 55 | + |
| 56 | + Assert.assertEquals("setParameter was called more than once", 1, |
| 57 | + $(SpanElement.class).all().stream() |
| 58 | + .filter(span -> span.getText().equals("setParameter")) |
| 59 | + .count()); |
| 60 | + } |
| 61 | +} |
0 commit comments