use of com.vaadin.flow.component.internal.PendingJavaScriptInvocation in project flow by vaadin.
the class PublishedServerEventHandlerRpcHandlerTest method promiseSuccess.
@Test
public void promiseSuccess() {
int promiseId = 4;
JsonArray args = Json.createArray();
args.set(0, 36);
ComponentWithCompute component = new ComponentWithCompute();
UI ui = new UI();
ui.getInternals().setSession(session);
ui.add(component);
// Get rid of attach invocations
ui.getInternals().getStateTree().runExecutionsBeforeClientResponse();
ui.getInternals().dumpPendingJavaScriptInvocations();
PublishedServerEventHandlerRpcHandler.invokeMethod(component, component.getClass(), "compute", args, promiseId);
ui.getInternals().getStateTree().runExecutionsBeforeClientResponse();
List<PendingJavaScriptInvocation> pendingJavaScriptInvocations = ui.getInternals().dumpPendingJavaScriptInvocations();
Assert.assertEquals(1, pendingJavaScriptInvocations.size());
JavaScriptInvocation invocation = pendingJavaScriptInvocations.get(0).getInvocation();
Assert.assertTrue("Invocation does not look like a promise callback", invocation.getExpression().contains(JsonConstants.RPC_PROMISE_CALLBACK_NAME));
List<Object> parameters = invocation.getParameters();
Assert.assertEquals("Expected three paramters: promiseId, value, target", 3, parameters.size());
Assert.assertEquals("Promise id should match the value passed to invokeMethod", Integer.valueOf(promiseId), parameters.get(0));
Assert.assertEquals("Promise value should be sqrt(36) = 6", Integer.valueOf(6), parameters.get(1));
Assert.assertEquals("Target should be the component's element", component.getElement(), parameters.get(2));
}
use of com.vaadin.flow.component.internal.PendingJavaScriptInvocation in project flow by vaadin.
the class UITest method localeSet_directionUpdated.
@Test
public void localeSet_directionUpdated() {
MockUI ui = new MockUI();
ui.setDirection(Direction.RIGHT_TO_LEFT);
ui.getInternals().getStateTree().runExecutionsBeforeClientResponse();
List<PendingJavaScriptInvocation> pendingJavaScriptInvocations = ui.dumpPendingJsInvocations();
Assert.assertEquals(1, pendingJavaScriptInvocations.size());
Assert.assertEquals("rtl", pendingJavaScriptInvocations.get(0).getInvocation().getParameters().get(0));
}
use of com.vaadin.flow.component.internal.PendingJavaScriptInvocation in project flow by vaadin.
the class ShortcutRegistrationTest method listenOnComponentHasElementLocatorJs_allowBrowserDefault_JsExecutionDoesNotPreventDefault.
@Test
public void listenOnComponentHasElementLocatorJs_allowBrowserDefault_JsExecutionDoesNotPreventDefault() {
final ElementLocatorTestFixture fixture = new ElementLocatorTestFixture();
final Key key = Key.KEY_A;
fixture.createNewShortcut(key).allowBrowserDefault();
List<PendingJavaScriptInvocation> pendingJavaScriptInvocations = fixture.writeResponse();
final PendingJavaScriptInvocation js = pendingJavaScriptInvocations.get(0);
final String expression = js.getInvocation().getExpression();
Assert.assertFalse("JS execution string should NOT have event.preventDefault() in it" + expression, expression.contains("event.preventDefault();"));
}
use of com.vaadin.flow.component.internal.PendingJavaScriptInvocation in project flow by vaadin.
the class ShortcutRegistrationTest method listenOnComponentHasElementLocatorJs_jsExecutionScheduled.
@Test
public void listenOnComponentHasElementLocatorJs_jsExecutionScheduled() {
final ElementLocatorTestFixture fixture = new ElementLocatorTestFixture();
final Key key = Key.KEY_A;
fixture.createNewShortcut(key);
List<PendingJavaScriptInvocation> pendingJavaScriptInvocations = fixture.writeResponse();
final PendingJavaScriptInvocation js = pendingJavaScriptInvocations.get(0);
final String expression = js.getInvocation().getExpression();
Assert.assertTrue("element locator string " + fixture.elementLocatorJs + " missing from JS execution string " + expression, expression.contains("const delegate=" + fixture.elementLocatorJs + ";"));
Assert.assertTrue("JS execution string should have event.preventDefault() in it" + expression, expression.contains("event.preventDefault();"));
Assert.assertTrue("JS execution string should always have event.stopPropagation() in it" + expression, expression.contains("event.stopPropagation();"));
Assert.assertTrue("JS execution string missing the key" + key, expression.contains(key.getKeys().get(0)));
fixture.registration.remove();
fixture.createNewShortcut(Key.KEY_X);
pendingJavaScriptInvocations = fixture.writeResponse();
Assert.assertEquals(0, pendingJavaScriptInvocations.size());
}
use of com.vaadin.flow.component.internal.PendingJavaScriptInvocation in project flow by vaadin.
the class AbstractDnDUnitTest method testExtension_mobileDnDpolyfillScriptInjected.
@Test
public void testExtension_mobileDnDpolyfillScriptInjected() {
ui.getInternals().dumpPendingJavaScriptInvocations();
RouterLink component = new RouterLink();
ui.add(component);
runStaticCreateMethodForExtension(component);
List<PendingJavaScriptInvocation> pendingJavaScriptInvocations = ui.getInternals().dumpPendingJavaScriptInvocations();
Assert.assertEquals(1, pendingJavaScriptInvocations.size());
PendingJavaScriptInvocation pendingJavaScriptInvocation = pendingJavaScriptInvocations.get(0);
// the urls are switched to "" by the mocked service method
String fake = String.format(DnDUtilHelper.MOBILE_DND_INJECT_SCRIPT, "", "");
Assert.assertEquals(fake, pendingJavaScriptInvocation.getInvocation().getExpression());
}
Aggregations