Search in sources :

Example 6 with JavaScriptBootstrapUI

use of com.vaadin.flow.component.internal.JavaScriptBootstrapUI in project flow by vaadin.

the class UidlRequestHandlerTest method should_changeURL_when_v7LocationProvided.

@Test
public void should_changeURL_when_v7LocationProvided() throws Exception {
    JavaScriptBootstrapUI ui = mock(JavaScriptBootstrapUI.class);
    UidlRequestHandler handler = spy(new UidlRequestHandler());
    StringWriter writer = new StringWriter();
    JsonObject uidl = generateUidl(true, true);
    doReturn(uidl).when(handler).createUidl(ui, false);
    handler.writeUidl(ui, writer, false);
    String out = writer.toString();
    uidl = JsonUtil.parse(out.substring(9, out.length() - 1));
    assertEquals("setTimeout(() => history.pushState(null, null, 'http://localhost:9998/#!away'));", uidl.getArray("execute").getArray(1).getString(1));
}
Also used : StringWriter(java.io.StringWriter) JsonObject(elemental.json.JsonObject) JavaScriptBootstrapUI(com.vaadin.flow.component.internal.JavaScriptBootstrapUI) Test(org.junit.Test)

Example 7 with JavaScriptBootstrapUI

use of com.vaadin.flow.component.internal.JavaScriptBootstrapUI in project flow by vaadin.

the class UidlRequestHandlerTest method should_not_modify_non_MPR_Uidl.

@Test
public void should_not_modify_non_MPR_Uidl() throws Exception {
    JavaScriptBootstrapUI ui = mock(JavaScriptBootstrapUI.class);
    UidlRequestHandler handler = spy(new UidlRequestHandler());
    StringWriter writer = new StringWriter();
    JsonObject uidl = generateUidl(true, true);
    uidl.getArray("execute").getArray(2).remove(1);
    doReturn(uidl).when(handler).createUidl(ui, false);
    handler.writeUidl(ui, writer, false);
    String expected = uidl.toJson();
    String out = writer.toString();
    uidl = JsonUtil.parse(out.substring(9, out.length() - 1));
    String actual = uidl.toJson();
    assertEquals(expected, actual);
}
Also used : StringWriter(java.io.StringWriter) JsonObject(elemental.json.JsonObject) JavaScriptBootstrapUI(com.vaadin.flow.component.internal.JavaScriptBootstrapUI) Test(org.junit.Test)

Example 8 with JavaScriptBootstrapUI

use of com.vaadin.flow.component.internal.JavaScriptBootstrapUI 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)8 Test (org.junit.Test)7 JsonObject (elemental.json.JsonObject)6 StringWriter (java.io.StringWriter)5 TestNodeVisitor (com.vaadin.flow.dom.TestNodeVisitor)2 VaadinRequest (com.vaadin.flow.server.VaadinRequest)2