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;
}
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);
}
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));
}
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);
}
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);
}
Aggregations