Search in sources :

Example 1 with BodySize

use of com.vaadin.flow.component.page.BodySize 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)

Aggregations

Component (com.vaadin.flow.component.Component)1 Html (com.vaadin.flow.component.Html)1 Tag (com.vaadin.flow.component.Tag)1 Text (com.vaadin.flow.component.Text)1 UI (com.vaadin.flow.component.UI)1 HtmlImport (com.vaadin.flow.component.dependency.HtmlImport)1 JavaScript (com.vaadin.flow.component.dependency.JavaScript)1 StyleSheet (com.vaadin.flow.component.dependency.StyleSheet)1 BodySize (com.vaadin.flow.component.page.BodySize)1 Inline (com.vaadin.flow.component.page.Inline)1 TargetElement (com.vaadin.flow.component.page.TargetElement)1 Viewport (com.vaadin.flow.component.page.Viewport)1 PageTitle (com.vaadin.flow.router.PageTitle)1 ParentLayout (com.vaadin.flow.router.ParentLayout)1 Route (com.vaadin.flow.router.Route)1 RouteAlias (com.vaadin.flow.router.RouteAlias)1 Router (com.vaadin.flow.router.Router)1 RouterLayout (com.vaadin.flow.router.RouterLayout)1 TestRouteRegistry (com.vaadin.flow.router.TestRouteRegistry)1 BootstrapContext (com.vaadin.flow.server.BootstrapHandler.BootstrapContext)1