Search in sources :

Example 1 with Tag

use of com.vaadin.flow.component.Tag 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 2 with Tag

use of com.vaadin.flow.component.Tag in project flow by vaadin.

the class BootstrapHandlerTest method no_body_size_or_page_configurator_still_adds_margin_for_body.

// 2344
@Test
public void no_body_size_or_page_configurator_still_adds_margin_for_body() throws InvalidRouteConfigurationException {
    initUI(testUI, createVaadinRequest(), Collections.singleton(RootNavigationTarget.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 containing margin", styleTag.get().toString().startsWith("<style type=\"text/css\">body {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 3 with Tag

use of com.vaadin.flow.component.Tag in project flow by vaadin.

the class TemplateInitializer method injectClientSideElement.

private void injectClientSideElement(String tagName, String id, Field field) {
    Class<?> fieldType = field.getType();
    Tag tag = fieldType.getAnnotation(Tag.class);
    if (tag != null && !tagName.equalsIgnoreCase(tag.value())) {
        String msg = String.format("Class '%s' has field '%s' whose type '%s' is annotated with " + "tag '%s' but the element defined in the HTML " + "template with id '%s' has tag name '%s'", templateClass.getName(), field.getName(), fieldType.getName(), tag.value(), id, tagName);
        throw new IllegalStateException(msg);
    }
    attachExistingElementById(tagName, id, field);
}
Also used : Tag(com.vaadin.flow.component.Tag)

Example 4 with Tag

use of com.vaadin.flow.component.Tag in project flow by vaadin.

the class TemplateInitializerTest method setUp.

@Before
public void setUp() throws NoSuchFieldException {
    String parentTemplateId = InTemplateClass.class.getAnnotation(Tag.class).value();
    assertThat("Both classes should have the same '@Tag' annotation", OutsideTemplateClass.class.getAnnotation(Tag.class).value(), is(parentTemplateId));
    String inTemplateElementId = InTemplateClass.class.getField("element").getAnnotation(Id.class).value();
    String outsideTemplateElementId = OutsideTemplateClass.class.getField("element").getAnnotation(Id.class).value();
    templateParser = (clazz, tag) -> new TemplateData("", Jsoup.parse(String.format("<dom-module id='%s'><template>" + "    <template><div id='%s'>Test</div></template>" + "    <div id='%s'></div>" + "    <div a='{{twoWay}}' b='{{invalid}} syntax' c='{{two.way}}'" + "        d='{{invalidSyntax' e='{{withEvent::eventName}}' f='[[oneWay]]'></div>" + "</template></dom-module>", parentTemplateId, inTemplateElementId, outsideTemplateElementId)));
}
Also used : TemplateData(com.vaadin.flow.component.polymertemplate.TemplateParser.TemplateData) Tag(com.vaadin.flow.component.Tag) Before(org.junit.Before)

Example 5 with Tag

use of com.vaadin.flow.component.Tag in project flow by vaadin.

the class HtmlComponentSmokeTest method testStringConstructor.

private static void testStringConstructor(Class<? extends HtmlComponent> clazz) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    try {
        String parameterValue = "Lorem";
        Constructor<? extends HtmlComponent> constructor = clazz.getConstructor(String.class);
        HtmlComponent instance = constructor.newInstance(parameterValue);
        if (clazz.getAnnotation(Tag.class) == null) {
            Assert.assertEquals(constructor + " should set the tag for a class without @Tag", parameterValue, instance.getElement().getTag());
        } else {
            Assert.assertEquals(constructor + " should set the text content for a class with @Tag", parameterValue, instance.getElement().getText());
        }
    } catch (NoSuchMethodException e) {
        // No constructor to test
        return;
    }
}
Also used : HtmlComponent(com.vaadin.flow.component.HtmlComponent) Tag(com.vaadin.flow.component.Tag)

Aggregations

Tag (com.vaadin.flow.component.Tag)5 Before (org.junit.Before)3 Component (com.vaadin.flow.component.Component)2 Html (com.vaadin.flow.component.Html)2 Text (com.vaadin.flow.component.Text)2 UI (com.vaadin.flow.component.UI)2 HtmlImport (com.vaadin.flow.component.dependency.HtmlImport)2 JavaScript (com.vaadin.flow.component.dependency.JavaScript)2 StyleSheet (com.vaadin.flow.component.dependency.StyleSheet)2 BodySize (com.vaadin.flow.component.page.BodySize)2 Inline (com.vaadin.flow.component.page.Inline)2 TargetElement (com.vaadin.flow.component.page.TargetElement)2 Viewport (com.vaadin.flow.component.page.Viewport)2 PageTitle (com.vaadin.flow.router.PageTitle)2 ParentLayout (com.vaadin.flow.router.ParentLayout)2 Route (com.vaadin.flow.router.Route)2 RouteAlias (com.vaadin.flow.router.RouteAlias)2 Router (com.vaadin.flow.router.Router)2 RouterLayout (com.vaadin.flow.router.RouterLayout)2 TestRouteRegistry (com.vaadin.flow.router.TestRouteRegistry)2