Search in sources :

Example 66 with Elements

use of org.jsoup.select.Elements in project flow by vaadin.

the class BootstrapHandlerTest method page_configurator_link_shorthands_are_added_correctly.

// 3203
@Test
public void page_configurator_link_shorthands_are_added_correctly() throws InvalidRouteConfigurationException {
    initUI(testUI, createVaadinRequest(), Collections.singleton(InitialPageConfiguratorLinkShorthands.class));
    Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
    Elements allElements = page.head().getAllElements();
    Assert.assertEquals("<link href=\"icons/favicon.ico\" rel=\"shortcut icon\">", allElements.get(allElements.size() - 2).toString());
    Assert.assertEquals("<link href=\"icons/icon-192.png\" rel=\"icon\" sizes=\"192x192\">", 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)

Example 67 with Elements

use of org.jsoup.select.Elements in project flow by vaadin.

the class BootstrapHandlerTest method page_configurator_inlines_javascript_from_content.

// 3036
@Test
public void page_configurator_inlines_javascript_from_content() throws InvalidRouteConfigurationException {
    initUI(testUI, createVaadinRequest(), Collections.singleton(InitialPageConfiguratorPrependContents.class));
    Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
    Elements allElements = page.head().getAllElements();
    // Note element 0 is the full head element.
    assertStringEquals("Content javascript should have been prepended to head element", "<script type=\"text/javascript\">window.messages = window.messages || [];\n" + "window.messages.push(\"content script\");</script>", allElements.get(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)

Example 68 with Elements

use of org.jsoup.select.Elements in project flow by vaadin.

the class BootstrapHandlerTest method headHasMetaTags.

@Test
public void headHasMetaTags() throws Exception {
    initUI(testUI, createVaadinRequest());
    Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
    Element head = page.head();
    Elements metas = head.getElementsByTag("meta");
    Assert.assertEquals(2, metas.size());
    Element meta = metas.get(0);
    assertEquals("Content-Type", meta.attr("http-equiv"));
    assertEquals("text/html; charset=utf-8", meta.attr("content"));
    meta = metas.get(1);
    assertEquals("X-UA-Compatible", meta.attr("http-equiv"));
    assertEquals("IE=edge", meta.attr("content"));
}
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) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 69 with Elements

use of org.jsoup.select.Elements in project flow by vaadin.

the class BootstrapHandlerTest method body_size_adds_styles_for_body.

// 2344
@Test
public void body_size_adds_styles_for_body() throws InvalidRouteConfigurationException {
    initUI(testUI, createVaadinRequest(), Collections.singleton(BodySizeAnnotated.class));
    Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
    Elements allElements = page.head().getAllElements();
    Optional<Element> styleTag = allElements.stream().filter(element -> element.tagName().equals("style")).findFirst();
    Assert.assertTrue("Expected a style element in head.", styleTag.isPresent());
    Assert.assertTrue("The first style tag should start with body style from @BodySize", styleTag.get().toString().startsWith("<style type=\"text/css\">body {height:100vh;width:100vw;margin:0;}"));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) Arrays(java.util.Arrays) Component(com.vaadin.flow.component.Component) JavaScript(com.vaadin.flow.component.dependency.JavaScript) Inline(com.vaadin.flow.component.page.Inline) BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) TargetElement(com.vaadin.flow.component.page.TargetElement) Registration(com.vaadin.flow.shared.Registration) PageTitle(com.vaadin.flow.router.PageTitle) Router(com.vaadin.flow.router.Router) Route(com.vaadin.flow.router.Route) RouteAlias(com.vaadin.flow.router.RouteAlias) Theme(com.vaadin.flow.theme.Theme) Assert.assertThat(org.junit.Assert.assertThat) Locale(java.util.Locale) Element(org.jsoup.nodes.Element) After(org.junit.After) UI(com.vaadin.flow.component.UI) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Document(org.jsoup.nodes.Document) LoadMode(com.vaadin.flow.shared.ui.LoadMode) BodySize(com.vaadin.flow.component.page.BodySize) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Elements(org.jsoup.select.Elements) ApplicationConstants(com.vaadin.flow.shared.ApplicationConstants) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) Matchers(org.mockito.Matchers) TestRouteRegistry(com.vaadin.flow.router.TestRouteRegistry) VaadinUriResolver(com.vaadin.flow.shared.VaadinUriResolver) Dependency(com.vaadin.flow.shared.ui.Dependency) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) HttpServletRequest(javax.servlet.http.HttpServletRequest) Tag(com.vaadin.flow.component.Tag) AbstractTheme(com.vaadin.flow.theme.AbstractTheme) Before(org.junit.Before) Text(com.vaadin.flow.component.Text) RouterLayout(com.vaadin.flow.router.RouterLayout) Html(com.vaadin.flow.component.Html) StyleSheet(com.vaadin.flow.component.dependency.StyleSheet) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) InlineTemplate(com.vaadin.flow.template.angular.InlineTemplate) HtmlImport(com.vaadin.flow.component.dependency.HtmlImport) Mockito(org.mockito.Mockito) Assert(org.junit.Assert) Collections(java.util.Collections) Viewport(com.vaadin.flow.component.page.Viewport) ParentLayout(com.vaadin.flow.router.ParentLayout) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) TargetElement(com.vaadin.flow.component.page.TargetElement) Element(org.jsoup.nodes.Element) BootstrapContext(com.vaadin.flow.server.BootstrapHandler.BootstrapContext) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Test(org.junit.Test)

Example 70 with Elements

use of org.jsoup.select.Elements in project flow by vaadin.

the class BootstrapHandlerTest method page_configurator_inlines_prepend_javascript_from_file.

// 3036
@Test
public void page_configurator_inlines_prepend_javascript_from_file() throws InvalidRouteConfigurationException {
    initUI(testUI, createVaadinRequest(), Collections.singleton(InitialPageConfiguratorPrependFile.class));
    Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
    Elements allElements = page.head().getAllElements();
    // Note element 0 is the full head element.
    assertStringEquals("Content javascript should have been prepended to head element", "<script type=\"text/javascript\">window.messages = window.messages || [];\n" + "window.messages.push(\"inline.js\");</script>", allElements.get(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

Elements (org.jsoup.select.Elements)709 Element (org.jsoup.nodes.Element)490 Document (org.jsoup.nodes.Document)362 ArrayList (java.util.ArrayList)213 IOException (java.io.IOException)151 Test (org.junit.Test)110 URL (java.net.URL)58 List (java.util.List)47 Matcher (java.util.regex.Matcher)42 Pattern (java.util.regex.Pattern)34 HashMap (java.util.HashMap)30 InputStream (java.io.InputStream)29 Jsoup (org.jsoup.Jsoup)28 Configuration (com.vaadin.addon.charts.model.Configuration)27 File (java.io.File)26 JSONObject (org.json.JSONObject)26 JSONException (org.json.JSONException)25 Collectors (java.util.stream.Collectors)23 URISyntaxException (java.net.URISyntaxException)22 BootstrapContext (com.vaadin.flow.server.BootstrapHandler.BootstrapContext)20