use of com.vaadin.client.flow.ExecuteJavaScriptProcessor in project flow by vaadin.
the class GwtExecuteJavaScriptElementUtilsTest method testReturnChannel_passedToExecJavaScript_messageSentToServer.
public void testReturnChannel_passedToExecJavaScript_messageSentToServer() {
ApplicationConfiguration applicationConfiguration = new ApplicationConfiguration();
applicationConfiguration.setApplicationId("test");
// Pass a number to the channel
String expression = "$0(2)";
int expectedNodeId = 10;
int expectedChannelId = 20;
int[] runCountHolder = { 0 };
ExecuteJavaScriptProcessor processor = new ExecuteJavaScriptProcessor(new Registry() {
{
set(StateTree.class, new StateTree(this));
set(ApplicationConfiguration.class, applicationConfiguration);
set(ServerConnector.class, new ServerConnector(this) {
@Override
public void sendReturnChannelMessage(int stateNodeId, int channelId, JsonArray arguments) {
assertEquals(expectedNodeId, stateNodeId);
assertEquals(expectedChannelId, channelId);
assertEquals("Args array should contain the value passed to the channel function", "[2]", arguments.toJson());
runCountHolder[0]++;
}
});
}
});
JsonArray serializedChannel = Json.createArray();
serializedChannel.set(0, JsonCodec.RETURN_CHANNEL_TYPE);
serializedChannel.set(1, expectedNodeId);
serializedChannel.set(2, expectedChannelId);
JsonArray invocation = Json.createArray();
// Assign channel as $0
invocation.set(0, serializedChannel);
invocation.set(1, expression);
JsonArray invocations = Json.createArray();
invocations.set(0, invocation);
processor.execute(invocations);
assertEquals(1, runCountHolder[0]);
}
Aggregations