Search in sources :

Example 1 with Text

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

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

the class AnchorTest method createWithComponent.

@Test
public void createWithComponent() {
    Anchor anchor = new Anchor("#", new Text("Home"));
    Assert.assertEquals(anchor.getElement().getAttribute("href"), "#");
    Assert.assertEquals(anchor.getHref(), "#");
    Assert.assertEquals(anchor.getElement().getText(), "Home");
    Assert.assertEquals(anchor.getText(), "Home");
}
Also used : Text(com.vaadin.flow.component.Text) Test(org.junit.Test)

Example 3 with Text

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

the class DependencyView method onShow.

@Override
protected void onShow() {
    add(new Text("This test initially loads a stylesheet which makes all text red, a JavaScript for logging window messages, a JavaScript for handling body click events and an HTML which sends a window message"), new Hr(), new Hr());
    Div clickBody = new Div();
    clickBody.setText("Hello, click the body please");
    clickBody.setId("hello");
    add(clickBody);
    NativeButton jsOrder = new NativeButton("Test JS order", e -> {
        getPage().addJavaScript("/test-files/js/set-global-var.js");
        getPage().addJavaScript("/test-files/js/read-global-var.js", LoadMode.LAZY);
    });
    jsOrder.setId("loadJs");
    NativeButton allBlue = new NativeButton("Load 'everything blue' stylesheet", e -> {
        getPage().addStyleSheet("/test-files/css/allblueimportant.css");
    });
    allBlue.setId("loadBlue");
    NativeButton loadUnavailableResources = new NativeButton("Load unavailable resources", e -> {
        getPage().addStyleSheet("/not-found.css");
        getPage().addJavaScript("/not-found.js");
    });
    loadUnavailableResources.setId("loadUnavailableResources");
    Div log = new Div();
    log.setId("log");
    add(jsOrder, allBlue, loadUnavailableResources, new Hr(), log);
}
Also used : Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) Text(com.vaadin.flow.component.Text) Hr(com.vaadin.flow.component.html.Hr)

Example 4 with Text

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

the class SynchronizedPropertyView method addSyncMultipleProperties.

private void addSyncMultipleProperties() {
    add(new Text("Synchronize 'value' on 'input' event and 'valueAsNumber' on 'blur'"));
    Div valueLabel = new Div();
    valueLabel.setId("multiSyncValueLabel");
    Div valueAsNumberLabel = new Div();
    valueAsNumberLabel.setId("multiSyncValueAsNumberLabel");
    Element multiSync = ElementFactory.createInput("number");
    multiSync.setAttribute("id", "multiSyncValue");
    multiSync.addPropertyChangeListener("valueAsNumber", "blur", event -> {
    });
    multiSync.addPropertyChangeListener("value", "input", event -> {
    });
    multiSync.addEventListener("input", e -> {
        valueLabel.setText("Server value: " + multiSync.getProperty("value"));
    });
    multiSync.addEventListener("blur", e -> {
        valueAsNumberLabel.setText("Server valueAsNumber: " + multiSync.getProperty("valueAsNumber"));
    });
    getElement().appendChild(multiSync);
    add(valueLabel, valueAsNumberLabel);
}
Also used : Div(com.vaadin.flow.component.html.Div) Element(com.vaadin.flow.dom.Element) Text(com.vaadin.flow.component.Text)

Example 5 with Text

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

the class SynchronizedPropertyView method addSyncWithInitialValue.

private void addSyncWithInitialValue() {
    add(new Text("Synchronized on 'change' event with initial value"));
    final Div syncOnChangeInitialValueLabel = new Div();
    syncOnChangeInitialValueLabel.setId("syncOnChangeInitialValueLabel");
    Element syncOnChangeInitialValue = ElementFactory.createInput();
    syncOnChangeInitialValueLabel.setText("Server value on create: " + syncOnChangeInitialValue.getProperty("value"));
    syncOnChangeInitialValue.setAttribute("id", "syncOnChangeInitialValue");
    syncOnChangeInitialValue.addPropertyChangeListener("value", "change", event -> {
    });
    syncOnChangeInitialValue.addEventListener("change", e -> {
        syncOnChangeInitialValueLabel.setText("Server value in change listener: " + syncOnChangeInitialValue.getProperty("value"));
    });
    syncOnChangeInitialValue.setProperty("value", "initial");
    getElement().appendChild(syncOnChangeInitialValue);
    add(syncOnChangeInitialValueLabel);
}
Also used : Div(com.vaadin.flow.component.html.Div) Element(com.vaadin.flow.dom.Element) Text(com.vaadin.flow.component.Text)

Aggregations

Text (com.vaadin.flow.component.Text)26 Div (com.vaadin.flow.component.html.Div)13 Test (org.junit.Test)10 Component (com.vaadin.flow.component.Component)8 UI (com.vaadin.flow.component.UI)8 Location (com.vaadin.flow.router.Location)6 Route (com.vaadin.flow.router.Route)6 Router (com.vaadin.flow.router.Router)6 TestRouteRegistry (com.vaadin.flow.router.TestRouteRegistry)6 Html (com.vaadin.flow.component.Html)5 Tag (com.vaadin.flow.component.Tag)5 JavaScript (com.vaadin.flow.component.dependency.JavaScript)5 StyleSheet (com.vaadin.flow.component.dependency.StyleSheet)5 BodySize (com.vaadin.flow.component.page.BodySize)5 Inline (com.vaadin.flow.component.page.Inline)5 TargetElement (com.vaadin.flow.component.page.TargetElement)5 Viewport (com.vaadin.flow.component.page.Viewport)5 PageTitle (com.vaadin.flow.router.PageTitle)5 ParentLayout (com.vaadin.flow.router.ParentLayout)5 RouteAlias (com.vaadin.flow.router.RouteAlias)5