Search in sources :

Example 1 with Dependency

use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.

the class GwtDependencyLoaderTest method createInlineDependency.

private JsonObject createInlineDependency(Dependency.Type dependencyType, String contents) {
    JsonObject json = new Dependency(dependencyType, "", LoadMode.INLINE).toJson();
    json.remove(Dependency.KEY_URL);
    json.put(Dependency.KEY_CONTENTS, contents);
    return json;
}
Also used : JsonObject(elemental.json.JsonObject) Dependency(com.vaadin.flow.shared.ui.Dependency)

Example 2 with Dependency

use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.

the class GwtDependencyLoaderTest method testAllEagerDependenciesAreLoadedFirst.

public void testAllEagerDependenciesAreLoadedFirst() {
    String eagerJsUrl = "https://foo.bar/eager_script.js";
    String eagerHtmlUrl = "https://foo.bar/eager_page.html";
    String eagerCssUrl = "https://foo.bar/eager_style.css";
    String lazyJsUrl = "https://foo.bar/script.js";
    String lazyHtmlUrl = "https://foo.bar/page.html";
    String lazyCssUrl = "https://foo.bar/style.css";
    new DependencyLoader(registry).loadDependencies(createDependenciesMap(new Dependency(Dependency.Type.JAVASCRIPT, lazyJsUrl, LoadMode.LAZY).toJson(), new Dependency(Dependency.Type.HTML_IMPORT, lazyHtmlUrl, LoadMode.LAZY).toJson(), new Dependency(Dependency.Type.STYLESHEET, lazyCssUrl, LoadMode.LAZY).toJson(), new Dependency(Dependency.Type.JAVASCRIPT, eagerJsUrl, LoadMode.EAGER).toJson(), new Dependency(Dependency.Type.HTML_IMPORT, eagerHtmlUrl, LoadMode.EAGER).toJson(), new Dependency(Dependency.Type.STYLESHEET, eagerCssUrl, LoadMode.EAGER).toJson()));
    assertEquals(Arrays.asList(eagerJsUrl, lazyJsUrl), mockResourceLoader.loadingScripts);
    assertEquals("2 style files should be imported, eager first", Arrays.asList(eagerCssUrl, lazyCssUrl), mockResourceLoader.loadingStyles);
    assertEquals("2 html files should be imported, eager first", Arrays.asList(eagerHtmlUrl, lazyHtmlUrl), mockResourceLoader.loadingHtml);
}
Also used : Dependency(com.vaadin.flow.shared.ui.Dependency)

Example 3 with Dependency

use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.

the class GwtDependencyLoaderTest method testDependenciesWithAllLoadModesAreProcessed.

public void testDependenciesWithAllLoadModesAreProcessed() {
    String eagerJsUrl = "/eager.js";
    String lazyJsUrl = "/lazy.js";
    String inlineJsContents = "/inline.js";
    String eagerCssUrl = "/eager.css";
    String lazyCssUrl = "/lazy.css";
    String inlineCssContents = "/inline.css";
    String eagerHtmlUrl = "/eager.html";
    String lazyHtmlUrl = "/lazy.html";
    String inlineHtmlContents = "/inline.html";
    new DependencyLoader(registry).loadDependencies(createDependenciesMap(createInlineDependency(Dependency.Type.JAVASCRIPT, inlineJsContents), new Dependency(Dependency.Type.JAVASCRIPT, lazyJsUrl, LoadMode.LAZY).toJson(), new Dependency(Dependency.Type.JAVASCRIPT, eagerJsUrl, LoadMode.EAGER).toJson(), createInlineDependency(Dependency.Type.STYLESHEET, inlineCssContents), new Dependency(Dependency.Type.STYLESHEET, lazyCssUrl, LoadMode.LAZY).toJson(), new Dependency(Dependency.Type.STYLESHEET, eagerCssUrl, LoadMode.EAGER).toJson(), createInlineDependency(Dependency.Type.HTML_IMPORT, inlineHtmlContents), new Dependency(Dependency.Type.HTML_IMPORT, lazyHtmlUrl, LoadMode.LAZY).toJson(), new Dependency(Dependency.Type.HTML_IMPORT, eagerHtmlUrl, LoadMode.EAGER).toJson()));
    // When multiple LoadModes are used, no guarantees on the order can be made except
    // for the fact that the last dependencies to be loaded are the lazy ones
    assertEquals("All type of dependencies should be added", Stream.of(eagerJsUrl, inlineJsContents, lazyJsUrl).collect(Collectors.toSet()), new HashSet<>(mockResourceLoader.loadingScripts));
    assertEquals("All type of dependencies should be added", Stream.of(eagerCssUrl, inlineCssContents, lazyCssUrl).collect(Collectors.toSet()), new HashSet<>(mockResourceLoader.loadingStyles));
    assertEquals("All type of dependencies should be added", Stream.of(eagerHtmlUrl, inlineHtmlContents, lazyHtmlUrl).collect(Collectors.toSet()), new HashSet<>(mockResourceLoader.loadingHtml));
}
Also used : Dependency(com.vaadin.flow.shared.ui.Dependency)

Example 4 with Dependency

use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.

the class DependencyLoaderTest method loadHtml.

@Test
public void loadHtml() {
    String TEST_URL = "http://foo.bar/baz.html";
    new DependencyLoader(registry).loadDependencies(createDependenciesMap(new Dependency(Dependency.Type.HTML_IMPORT, TEST_URL, LoadMode.EAGER).toJson()));
    assertEquals(Collections.singletonList(TEST_URL), mockResourceLoader.loadingHtml);
}
Also used : Dependency(com.vaadin.flow.shared.ui.Dependency) Test(org.junit.Test)

Example 5 with Dependency

use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.

the class DependencyLoaderTest method loadStylesheet.

@Test
public void loadStylesheet() {
    String TEST_URL = "http://foo.bar/baz";
    new DependencyLoader(registry).loadDependencies(createDependenciesMap(new Dependency(Dependency.Type.STYLESHEET, TEST_URL, LoadMode.EAGER).toJson()));
    assertEquals(Collections.singletonList(TEST_URL), mockResourceLoader.loadingStyles);
}
Also used : Dependency(com.vaadin.flow.shared.ui.Dependency) Test(org.junit.Test)

Aggregations

Dependency (com.vaadin.flow.shared.ui.Dependency)30 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)8 LoadMode (com.vaadin.flow.shared.ui.LoadMode)7 List (java.util.List)7 HtmlImport (com.vaadin.flow.component.dependency.HtmlImport)6 JsonObject (elemental.json.JsonObject)6 DependencyFilter (com.vaadin.flow.server.DependencyFilter)5 VaadinUriResolver (com.vaadin.flow.shared.VaadinUriResolver)5 StandardCharsets (java.nio.charset.StandardCharsets)5 Collections (java.util.Collections)5 Element (org.jsoup.nodes.Element)5 Tag (com.vaadin.flow.component.Tag)4 UI (com.vaadin.flow.component.UI)4 VaadinService (com.vaadin.flow.server.VaadinService)3 VaadinServlet (com.vaadin.flow.server.VaadinServlet)3 VaadinSession (com.vaadin.flow.server.VaadinSession)3 Type (com.vaadin.flow.shared.ui.Dependency.Type)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3