aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/ui/PushStateAndReplaceStateTest.java
blob: 9991eb313b0304569ed8ca871414cdffca9bca8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.vaadin.tests.components.ui;

import static org.junit.Assert.assertEquals;

import java.net.URI;

import org.junit.Test;

import com.vaadin.testbench.By;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class PushStateAndReplaceStateTest extends MultiBrowserTest {

    @Test
    public void testUriFragment() throws Exception {
        driver.get(getTestUrl());
        assertUri(getTestUrl());

        hitButton("test");

        assertUri(getTestUrl() + "/test");

        driver.navigate().back();

        driver.findElement(By.className("v-Notification")).getText()
                .contains("Popstate event");

        assertUri(getTestUrl());

        hitButton("test");
        URI base = new URI(getTestUrl() + "/test");
        hitButton("X");
        URI current = base.resolve("X");
        driver.findElement(By.xpath("//*[@id = 'replace']/input")).click();
        hitButton("root_X");
        current = current.resolve("/X");

        assertUri(current.toString());

        // Now that last change was with replace state, two back calls should go
        // to initial
        driver.navigate().back();
        driver.navigate().back();

        assertUri(getTestUrl());

    }

    private void assertUri(String uri) {
        final String expectedText = "Current Location: " + uri;
        waitUntil(input -> expectedText.equals(getLocationLabelValue()));

        assertEquals(uri, driver.getCurrentUrl());
    }

    private String getLocationLabelValue() {
        String text = vaadinElementById("locationLabel").getText();
        return text;
    }

}