Search in sources :

Example 16 with BootstrapContext

use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.

the class BootstrapHandlerTest method bootstrap_page_has_viewport_for_route_alias_parent.

// #3008
@Test
public void bootstrap_page_has_viewport_for_route_alias_parent() throws InvalidRouteConfigurationException {
    HttpServletRequest httpRequest = Mockito.mock(HttpServletRequest.class);
    Mockito.doAnswer(invocation -> "").when(httpRequest).getServletPath();
    VaadinServletRequest vaadinRequest = new VaadinServletRequest(httpRequest, service);
    initUI(testUI, vaadinRequest, Collections.singleton(AliasLayout.class));
    Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(vaadinRequest, null, session, testUI));
    Assert.assertFalse("Viewport found even though not part of Route", page.toString().contains("<meta name=\"viewport\" content=\"width=device-width\">"));
    Mockito.doAnswer(invocation -> "/alias").when(httpRequest).getPathInfo();
    page = BootstrapHandler.getBootstrapPage(new BootstrapContext(vaadinRequest, null, session, testUI));
    Assert.assertTrue("Viewport meta tag was missing even tough alias route parent has annotation", page.toString().contains("<meta name=\"viewport\" content=\"width=device-width\">"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 17 with BootstrapContext

use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.

the class BootstrapHandlerTest method bootstrap_page_has_viewport_for_route_top_parent.

// #3008
@Test
public void bootstrap_page_has_viewport_for_route_top_parent() throws InvalidRouteConfigurationException {
    initUI(testUI, createVaadinRequest(), Collections.singleton(RootWithParents.class));
    Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
    Assert.assertTrue("Viewport meta tag was missing", page.toString().contains("<meta name=\"viewport\" content=\"width=device-width\">"));
}
Also used : BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 18 with BootstrapContext

use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.

the class BootstrapHandlerDependenciesTest method initUIAndGetPage.

private Document initUIAndGetPage(UI ui) {
    ui.getInternals().setSession(session);
    VaadinRequest request = new VaadinServletRequest(createRequest(), service);
    service.init();
    ui.doInit(request, 0);
    return BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, ui));
}
Also used : BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext)

Example 19 with BootstrapContext

use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.

the class BootstrapHandlerTest method testBody.

// #1134
@Test
public void testBody() throws Exception {
    initUI(testUI, createVaadinRequest());
    Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
    Element body = page.head().nextElementSibling();
    assertEquals("body", body.tagName());
    assertEquals("html", body.parent().tagName());
    assertEquals(2, body.parent().childNodeSize());
}
Also used : TargetElement(com.vaadin.flow.component.page.TargetElement) Element(org.jsoup.nodes.Element) BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 20 with BootstrapContext

use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.

the class BootstrapHandlerTest method use_inline_to_append_files_to_head.

// 3010
@Test
public void use_inline_to_append_files_to_head() throws InvalidRouteConfigurationException {
    initUI(testUI, createVaadinRequest(), Collections.singleton(InlineAnnotations.class));
    Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
    Elements allElements = page.head().getAllElements();
    assertStringEquals("File javascript should have been appended to head element", "<script type=\"text/javascript\">window.messages = window.messages || [];\n" + "window.messages.push(\"inline.js\");</script>", allElements.get(allElements.size() - 3).toString());
    assertStringEquals("File html should have been appended to head element", "<script type=\"text/javascript\">\n" + "    // document.body might not yet be accessible, so just leave a message\n" + "    window.messages = window.messages || [];\n" + "    window.messages.push(\"inline.html\");\n" + "</script>", allElements.get(allElements.size() - 2).toString());
    assertStringEquals("File css should have been appended to head element", "<style type=\"text/css\">/* inline.css */\n" + "\n" + "#preloadedDiv {\n" + "    color: rgba(255, 255, 0, 1);\n" + "}\n" + "\n" + "#inlineCssTestDiv {\n" + "    color: rgba(255, 255, 0, 1);\n" + "}</style>", allElements.get(allElements.size() - 1).toString());
}
Also used : BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Aggregations

BootstrapContext (com.vaadin.flow.server.BootstrapHandler.BootstrapContext)36 Test (org.junit.Test)32 Document (org.jsoup.nodes.Document)31 Elements (org.jsoup.select.Elements)21 TargetElement (com.vaadin.flow.component.page.TargetElement)13 Element (org.jsoup.nodes.Element)13 UI (com.vaadin.flow.component.UI)9 Registration (com.vaadin.flow.shared.Registration)9 Component (com.vaadin.flow.component.Component)8 Html (com.vaadin.flow.component.Html)8 Tag (com.vaadin.flow.component.Tag)8 Text (com.vaadin.flow.component.Text)8 HtmlImport (com.vaadin.flow.component.dependency.HtmlImport)8 JavaScript (com.vaadin.flow.component.dependency.JavaScript)8 StyleSheet (com.vaadin.flow.component.dependency.StyleSheet)8 BodySize (com.vaadin.flow.component.page.BodySize)8 Inline (com.vaadin.flow.component.page.Inline)8 Viewport (com.vaadin.flow.component.page.Viewport)8 PageTitle (com.vaadin.flow.router.PageTitle)8 ParentLayout (com.vaadin.flow.router.ParentLayout)8