From 5169ce78da43fc2cef44d82848a65113ef565757 Mon Sep 17 00:00:00 2001 From: Sun Zhe <31067185+ZheSun88@users.noreply.github.com> Date: Thu, 5 Apr 2018 15:55:27 +0300 Subject: [PATCH] Correct link usage for productionMode (#432) * Correct link usage for productionMode Fix Test for both modes --- .../vaadin/flow/demo/website/ResourcesView.java | 15 ++++++++++----- .../com/vaadin/flow/demo/website/WebSiteIT.java | 12 ++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/demo-web-site/src/main/java/com/vaadin/flow/demo/website/ResourcesView.java b/demo-web-site/src/main/java/com/vaadin/flow/demo/website/ResourcesView.java index 8f7edfe59..c10a9d7dc 100644 --- a/demo-web-site/src/main/java/com/vaadin/flow/demo/website/ResourcesView.java +++ b/demo-web-site/src/main/java/com/vaadin/flow/demo/website/ResourcesView.java @@ -28,6 +28,7 @@ import com.vaadin.flow.dom.ElementFactory; import com.vaadin.flow.router.RouterLink; import com.vaadin.flow.router.legacy.LocationChangeEvent; +import com.vaadin.flow.server.VaadinServlet; import com.vaadin.flow.server.VaadinServletService; /** @@ -67,8 +68,10 @@ public ResourcesView() { content.setClassName("content"); HtmlContainer links = new HtmlContainer("ul"); - links.add(createLink("", "")); - links.add(createLink("frontend/images/vaadin-logo-small.png")); + links.add(createLink("", "", "none")); + links.add(createLink(VaadinServlet.getCurrent() + .resolveResource("frontend://images/vaadin-logo-small.png"), + "logo")); HtmlContainer header = new HtmlContainer("p"); HtmlContainer strong = new HtmlContainer("strong"); @@ -83,13 +86,15 @@ public ResourcesView() { add(content); } - private static Component createLink(String resource) { - return createLink(resource, resource); + private static Component createLink(String resource, String id) { + return createLink(resource, resource, id); } - private static Component createLink(String resource, String caption) { + private static Component createLink(String resource, String caption, + String id) { RouterLink link = new RouterLink(caption, ResourcesView.class, resource); + link.setId(id); HtmlContainer li = new HtmlContainer("li"); li.add(link); return li; diff --git a/demo-web-site/src/test/java/com/vaadin/flow/demo/website/WebSiteIT.java b/demo-web-site/src/test/java/com/vaadin/flow/demo/website/WebSiteIT.java index e54b55eb0..1dc4e4fb9 100644 --- a/demo-web-site/src/test/java/com/vaadin/flow/demo/website/WebSiteIT.java +++ b/demo-web-site/src/test/java/com/vaadin/flow/demo/website/WebSiteIT.java @@ -20,6 +20,7 @@ import java.util.Map; import java.util.stream.Collectors; +import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.By; @@ -124,16 +125,11 @@ public void testWildcardView() { .findElement(By.xpath("./*[4]")); Assert.assertEquals("No resource selected", selectedResource.getText()); - getContent() - .findElement( - By.xpath( - "//a[text()='frontend/images/vaadin-logo-small.png']")) - .click(); - assertLocation("resource/frontend/images/vaadin-logo-small.png"); + getContent().findElement(By.id("logo")).click(); WebElement iframe = findElement(By.xpath("//iframe")); - assertLocation("frontend/images/vaadin-logo-small.png", - iframe.getAttribute("src")); + Assert.assertThat(iframe.getAttribute("src"), + CoreMatchers.containsString("images/vaadin-logo-small.png")); } @Test