Search in sources :

Example 1 with TestNodeVisitor

use of com.vaadin.flow.dom.TestNodeVisitor in project flow by vaadin.

the class JavaScriptBootstrapHandlerTest method should_attachViewTo_Body_when_serverRouting.

@Test
public void should_attachViewTo_Body_when_serverRouting() throws Exception {
    VaadinRequest request = mocks.createRequest(mocks, "/", "v-r=init&location=bar%3Fpar1%26par2&serverSideRouting");
    jsInitHandler.handleRequest(session, request, response);
    JavaScriptBootstrapUI ui = (JavaScriptBootstrapUI) UI.getCurrent();
    TestNodeVisitor visitor = new TestNodeVisitor(true);
    BasicElementStateProvider.get().visit(ui.getElement().getNode(), visitor);
    Assert.assertTrue(hasNodeTag(visitor, "^<body>.*", ElementType.REGULAR));
    Assert.assertTrue(hasNodeTag(visitor, "^<div>.*", ElementType.REGULAR));
    Assert.assertTrue(hasNodeTag(visitor, "^<div>.*Could not navigate to 'bar'.*", ElementType.REGULAR));
    Mockito.verify(session, Mockito.times(1)).setAttribute(SERVER_ROUTING, Boolean.TRUE);
}
Also used : TestNodeVisitor(com.vaadin.flow.dom.TestNodeVisitor) VaadinRequest(com.vaadin.flow.server.VaadinRequest) JavaScriptBootstrapUI(com.vaadin.flow.component.internal.JavaScriptBootstrapUI) Test(org.junit.Test)

Example 2 with TestNodeVisitor

use of com.vaadin.flow.dom.TestNodeVisitor in project flow by vaadin.

the class JavaScriptBootstrapHandlerTest method should_attachViewTo_UiContainer.

@Test
public void should_attachViewTo_UiContainer() throws Exception {
    VaadinRequest request = mocks.createRequest(mocks, "/", "v-r=init&foo&location=");
    jsInitHandler.handleRequest(session, request, response);
    JavaScriptBootstrapUI ui = (JavaScriptBootstrapUI) UI.getCurrent();
    ui.connectClient("a-tag", "an-id", "a-route", "", null);
    TestNodeVisitor visitor = new TestNodeVisitor(true);
    BasicElementStateProvider.get().visit(ui.getElement().getNode(), visitor);
    Assert.assertTrue(hasNodeTag(visitor, "^<body>.*", ElementType.REGULAR));
    Assert.assertTrue(hasNodeTag(visitor, "^<a-tag>.*", ElementType.VIRTUAL_ATTACHED));
    Assert.assertTrue(hasNodeTag(visitor, "^<div>.*", ElementType.REGULAR));
    Assert.assertTrue(hasNodeTag(visitor, "^<div>.*Could not navigate to 'a-route'.*", ElementType.REGULAR));
}
Also used : TestNodeVisitor(com.vaadin.flow.dom.TestNodeVisitor) VaadinRequest(com.vaadin.flow.server.VaadinRequest) JavaScriptBootstrapUI(com.vaadin.flow.component.internal.JavaScriptBootstrapUI) Test(org.junit.Test)

Aggregations

JavaScriptBootstrapUI (com.vaadin.flow.component.internal.JavaScriptBootstrapUI)2 TestNodeVisitor (com.vaadin.flow.dom.TestNodeVisitor)2 VaadinRequest (com.vaadin.flow.server.VaadinRequest)2 Test (org.junit.Test)2