use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method theme_contents_added_also_when_theme_in_super_class.
// 3384
@Test
public void theme_contents_added_also_when_theme_in_super_class() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(ExtendingView.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Elements allElements = page.head().getAllElements();
Assert.assertTrue("Custom style should have been added to head.", allElements.stream().map(Object::toString).anyMatch(element -> element.equals("<link rel=\"import\" href=\"./frontend/bower_components/vaadin-lumo-styles/color.html\">")));
allElements = page.body().getAllElements();
// Note element 0 is the full head element.
assertStringEquals("Custom style should have been added to head.", "<custom-style><style include=\"lumo-typography\"></style></custom-style>", allElements.get(2).toString());
Assert.assertTrue("Style should have been wrapped in custom style", page.body().toString().contains("<custom-style><style include=\"lumo-typography\"></style></custom-style>"));
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method renderUI.
@Test
public void renderUI() throws IOException {
TestUI anotherUI = new TestUI();
initUI(testUI);
anotherUI.getInternals().setSession(session);
VaadinRequest vaadinRequest = createVaadinRequest();
anotherUI.doInit(vaadinRequest, 0);
BootstrapContext bootstrapContext = new BootstrapContext(vaadinRequest, null, session, anotherUI);
Document page = BootstrapHandler.getBootstrapPage(bootstrapContext);
Element body = page.body();
assertEquals(1, body.childNodeSize());
assertEquals("noscript", body.child(0).tagName());
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method bootstrap_page_has_viewport_for_route.
// #3008
@Test
public void bootstrap_page_has_viewport_for_route() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(RootNavigationTarget.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Assert.assertTrue("Viewport meta tag was missing", page.toString().contains("<meta name=\"viewport\" content=\"width=device-width\">"));
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method use_inline_to_append_files_to_body.
// 3010
@Test
public void use_inline_to_append_files_to_body() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(InlineAnnotationsBodyTarget.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Elements allElements = page.body().getAllElements();
assertStringEquals("File css should have been appended to body element", "<style type=\"text/css\">/* inline.css */\n" + "\n" + "#preloadedDiv {\n" + " color: rgba(255, 255, 0, 1);\n" + "}\n" + "\n" + "#inlineCssTestDiv {\n" + " color: rgba(255, 255, 0, 1);\n" + "}</style>", allElements.get(allElements.size() - 3).toString());
assertStringEquals("File html should have been appended to body element", "<script type=\"text/javascript\">\n" + " // document.body might not yet be accessible, so just leave a message\n" + " window.messages = window.messages || [];\n" + " window.messages.push(\"inline.html\");\n" + "</script>", allElements.get(allElements.size() - 2).toString());
assertStringEquals("File javascript should have been appended to body element", "<script type=\"text/javascript\">window.messages = window.messages || [];\n" + "window.messages.push(\"inline.js\");</script>", allElements.get(allElements.size() - 1).toString());
}
use of com.vaadin.flow.server.BootstrapHandler.BootstrapContext in project flow by vaadin.
the class BootstrapHandlerTest method page_configurator_append_inline_form_files.
// 3036
@Test
public void page_configurator_append_inline_form_files() throws InvalidRouteConfigurationException {
initUI(testUI, createVaadinRequest(), Collections.singleton(InitialPageConfiguratorAppendFiles.class));
Document page = BootstrapHandler.getBootstrapPage(new BootstrapContext(request, null, session, testUI));
Elements allElements = page.head().getAllElements();
// Note element 0 is the full head element.
assertStringEquals("File javascript should have been appended to head element", "<script type=\"text/javascript\">window.messages = window.messages || [];\n" + "window.messages.push(\"inline.js\");</script>", allElements.get(allElements.size() - 3).toString());
assertStringEquals("File html should have been appended to head element", "<script type=\"text/javascript\">\n" + " // document.body might not yet be accessible, so just leave a message\n" + " window.messages = window.messages || [];\n" + " window.messages.push(\"inline.html\");\n" + "</script>", allElements.get(allElements.size() - 2).toString());
assertStringEquals("File css should have been appended to head element", "<style type=\"text/css\">/* inline.css */\n" + "\n" + "#preloadedDiv {\n" + " color: rgba(255, 255, 0, 1);\n" + "}\n" + "\n" + "#inlineCssTestDiv {\n" + " color: rgba(255, 255, 0, 1);\n" + "}</style>", allElements.get(allElements.size() - 1).toString());
}
Aggregations