Procházet zdrojové kódy

Converted javascript tests to TB4 and added date tests (#16797, #16786)

Change-Id: I0ac58945d70676135d982f5b829b065b96b1ffa4
tags/7.4.6
Artur Signell před 9 roky
rodič
revize
cb9a01738a

+ 29
- 1
uitest/src/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.java Zobrazit soubor

@@ -36,7 +36,10 @@ import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.HasComponents;
import com.vaadin.ui.JavaScriptFunction;

import elemental.json.JsonArray;
import elemental.json.JsonObject;
import elemental.json.JsonValue;

public class BasicJavaScriptComponent extends AbstractTestUI {

@@ -103,6 +106,31 @@ public class BasicJavaScriptComponent extends AbstractTestUI {
}
});

addFunction("sendDifferentTypeOfData", new JavaScriptFunction() {
@Override
public void call(JsonArray arguments) {
for (int i = 0; i < arguments.length(); i++) {
JsonValue arg = arguments.get(i);
if (arg instanceof JsonObject) {
JsonObject o = (JsonObject) arg;
log.log("Argument[" + i + "] type: "
+ arg.getClass().getName());
for (String key : o.keys()) {
JsonValue v = o.get(key);
log.log("Argument[" + i + "][" + key
+ "] type: " + v.getClass().getName()
+ ", value: " + v.asString());

}
} else {
log.log("Argument[" + i + "] type: "
+ arg.getClass().getName() + ", value: "
+ arg.asString());
}
}
}
});

getRpcProxy(TestRpc.class).sendRpc("RPC message");
callFunction("messageToClient", "Callback message");

@@ -136,7 +164,7 @@ public class BasicJavaScriptComponent extends AbstractTestUI {
}
}

private final Log log = new Log(5);
private final Log log = new Log(15);

@Override
protected void setup(VaadinRequest request) {

+ 1
- 1
uitest/src/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponentConnector.js Zobrazit soubor

@@ -6,8 +6,8 @@ window.com_vaadin_tests_components_javascriptcomponent_BasicJavaScriptComponent_
parentIds.push(connectorId);
connectorId = this.getParentId(connectorId);
}
this.sendDifferentTypeOfData(new Date(123), "a string", 556, true ,{"aString": "value1","anInt":556,"aBoolean":false,"aDate":new Date(111)});
this.reportParentIds(parentIds);
this.onStateChange = function() {
var e = this.getElement();

+ 97
- 0
uitest/src/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponentTest.java Zobrazit soubor

@@ -0,0 +1,97 @@
package com.vaadin.tests.components.javascriptcomponent;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;

import com.vaadin.testbench.elements.AbstractComponentElement;
import com.vaadin.testbench.elements.AbstractJavaScriptComponentElement;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.parallel.BrowserUtil;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class BasicJavaScriptComponentTest extends MultiBrowserTest {
@Test
public void javascriptCommunication() throws Exception {
openTestURL();
int idx = 0;
Assert.assertEquals(
"12. Got callback message: Callback message processed",
getLogRow(idx++));
Assert.assertEquals("11. Got RPC message: RPC message processed",
getLogRow(idx++));
Assert.assertEquals("10. Parent ids checked", getLogRow(idx++));

// Data types in JS functions
String expected = "1970-01-01T00:00:00.111Z";
if (BrowserUtil.isIE8(getDesiredCapabilities())) {
expected = "1970-01-01T00:00:00Z";
}
Assert.assertEquals(
"9. Argument[4][aDate] type: elemental.json.impl.JreJsonString, value: "
+ expected, getLogRow(idx++));
Assert.assertEquals(
"8. Argument[4][aBoolean] type: elemental.json.impl.JreJsonBoolean, value: false",
getLogRow(idx++));
Assert.assertEquals(
"7. Argument[4][anInt] type: elemental.json.impl.JreJsonNumber, value: 556",
getLogRow(idx++));
Assert.assertEquals(
"6. Argument[4][aString] type: elemental.json.impl.JreJsonString, value: value1",
getLogRow(idx++));
Assert.assertEquals(
"5. Argument[4] type: elemental.json.impl.JreJsonObject",
getLogRow(idx++));
Assert.assertEquals(
"4. Argument[3] type: elemental.json.impl.JreJsonBoolean, value: true",
getLogRow(idx++));
Assert.assertEquals(
"3. Argument[2] type: elemental.json.impl.JreJsonNumber, value: 556",
getLogRow(idx++));
Assert.assertEquals(
"2. Argument[1] type: elemental.json.impl.JreJsonString, value: a string",
getLogRow(idx++));

expected = "1970-01-01T00:00:00.123Z";
if (BrowserUtil.isIE8(getDesiredCapabilities())) {
expected = "1970-01-01T00:00:00Z";
}

Assert.assertEquals(
"1. Argument[0] type: elemental.json.impl.JreJsonString, value: "
+ expected, getLogRow(idx++));

// Component attributes
AbstractJavaScriptComponentElement jsComponent = $(
AbstractJavaScriptComponentElement.class).first();
Assert.assertEquals("Component caption", getCaption(jsComponent));

// app://APP/connector/[uiid]/[cid]/[key]/[filename]
Assert.assertTrue(getChildText(jsComponent, 0).matches(
"4. Url: .*/run/APP/connector/0/\\d+/test"));
Assert.assertEquals("3. State message: Second state message",
getChildText(jsComponent, 1));
Assert.assertEquals("2. State message: First state message",
getChildText(jsComponent, 2));

// Can't/shouldn't check parent class name as we used to because it
// relies on parent state change events being fired before child state
// change events and this is not guaranteed

// Modifications
ButtonElement button = $(ButtonElement.class).first();
button.click();
Assert.assertEquals("Remove component\nDon't mess with me",
button.getText());
}

private String getCaption(AbstractComponentElement c) {
return c.findElement(By.xpath("../div[@class='v-caption']")).getText();
}

private String getChildText(AbstractComponentElement e, int index) {
return e.findElement(By.xpath("(./div)[" + (index + 1) + "]"))
.getText();
}

}

+ 19
- 2
uitest/src/com/vaadin/tests/serialization/SerializerTest.java Zobrazit soubor

@@ -51,7 +51,7 @@ import elemental.json.JsonValue;
@Widgetset("com.vaadin.tests.widgetset.TestingWidgetSet")
public class SerializerTest extends AbstractTestUI {

private Log log = new Log(50);
private Log log = new Log(80);

@Override
protected void setup(VaadinRequest request) {
@@ -63,7 +63,7 @@ public class SerializerTest extends AbstractTestUI {
log.setNumberLogRows(false);
addComponent(log);

SerializerTestRpc rpc = testExtension
final SerializerTestRpc rpc = testExtension
.getRpcProxy(SerializerTestRpc.class);
SerializerTestState state = testExtension.getState();

@@ -263,12 +263,15 @@ public class SerializerTest extends AbstractTestUI {

rpc.sendDate(new Date(1));
rpc.sendDate(new Date(2013 - 1900, 5 - 1, 31, 11, 12, 13));
rpc.sendDateArray(new Date[] { new Date(2013 - 1900, 1, 1),
new Date(2012 - 1900, 1, 1) });

state.jsonNull = Json.createNull();
state.jsonString = Json.create("a string");
state.jsonBoolean = Json.create(false);
rpc.sendJson(Json.create(true), Json.createNull(), Json.create("JSON"));

state.dateArray = new Date[] { new Date(1), new Date(2) };
state.date1 = new Date(1);
state.date2 = new Date(2013 - 1900, 5 - 1, 31, 11, 12, 13);

@@ -468,6 +471,20 @@ public class SerializerTest extends AbstractTestUI {
log.log("sendDate: " + format.format(date));
}

@Override
public void sendDateArray(Date[] dateArray) {
DateFormat format = DateFormat.getDateTimeInstance(
DateFormat.LONG, DateFormat.FULL,
new Locale("en", "fi"));
format.setTimeZone(TimeZone.getTimeZone("UTC"));
String dates = "";

for (Date date : dateArray) {
dates += " " + format.format(date);
}
log.log("sendDateArray: " + dates);
}

@Override
public void sendJson(JsonValue value1, JsonValue value2,
JsonString string) {

+ 10
- 0
uitest/src/com/vaadin/tests/serialization/SerializerTestTest.java Zobrazit soubor

@@ -30,6 +30,9 @@ public class SerializerTestTest extends MultiBrowserTest {
Assert.assertEquals(
"sendJson: {\"b\":false,\"s\":\"JSON\"}, null, \"value\"",
getLogRow(logRow++));
Assert.assertEquals(
"sendDateArray: January 31, 2013 10:00:00 PM UTC January 31, 2012 10:00:00 PM UTC",
getLogRow(logRow++));
Assert.assertEquals("sendDate: May 31, 2013 8:12:13 AM UTC",
getLogRow(logRow++));
Assert.assertEquals("sendDate: January 1, 1970 12:00:00 AM UTC",
@@ -80,6 +83,13 @@ public class SerializerTestTest extends MultiBrowserTest {
"sendBoolean: false, false, [false, false, true, false, true, true]",
getLogRow(logRow++));
Assert.assertEquals("sendBeanSubclass: 43", getLogRow(logRow++));
Assert.assertEquals(
"state.dateArray: Thu Jan 01 02:00:00 GMT+200 1970 Thu Jan 01 02:00:00 GMT+200 1970",
getLogRow(logRow++));
Assert.assertEquals("state.date2: Fri May 31 11:12:13 GMT+300 2013",
getLogRow(logRow++));
Assert.assertEquals("state.date1: Thu Jan 01 02:00:00 GMT+200 1970",
getLogRow(logRow++));
Assert.assertEquals("state.jsonBoolean: false", getLogRow(logRow++));
Assert.assertEquals("state.jsonString: a string", getLogRow(logRow++));
Assert.assertEquals("state.jsonNull: NULL", getLogRow(logRow++));

+ 13
- 0
uitest/src/com/vaadin/tests/widgetset/client/SerializerTestConnector.java Zobrazit soubor

@@ -266,6 +266,11 @@ public class SerializerTestConnector extends AbstractExtensionConnector {
rpc.sendDate(date);
}

@Override
public void sendDateArray(Date[] date) {
rpc.sendDateArray(date);
}

@Override
public void sendJson(JsonValue value1, JsonValue value2,
JsonString string) {
@@ -348,6 +353,14 @@ public class SerializerTestConnector extends AbstractExtensionConnector {
+ ((JsonString) getState().jsonString).getString());
rpc.log("state.jsonBoolean: " + getState().jsonBoolean.getBoolean());

rpc.log("state.date1: " + getState().date1);
rpc.log("state.date2: " + getState().date2);
String arrStr = "";
for (Date d : getState().dateArray) {
arrStr += d + " ";
}
rpc.log("state.dateArray: " + arrStr);

/*
* TODO public double doubleValue; public Double DoubleValue; public
* double[] doubleArray; ;

+ 3
- 0
uitest/src/com/vaadin/tests/widgetset/client/SerializerTestRpc.java Zobrazit soubor

@@ -85,7 +85,10 @@ public interface SerializerTestRpc extends ServerRpc, ClientRpc {

public void sendDate(Date date);

public void sendDateArray(Date[] dates);

public void sendJson(JsonValue value1, JsonValue value2, JsonString string);

public void log(String string);

}

+ 1
- 0
uitest/src/com/vaadin/tests/widgetset/client/SerializerTestState.java Zobrazit soubor

@@ -100,6 +100,7 @@ public class SerializerTestState extends AbstractComponentState {

public Date date1;
public Date date2;
public Date[] dateArray;

public BeanWithAbstractSuperclass beanWithAbstractSuperclass;


+ 0
- 71
uitest/tb2/com/vaadin/tests/components/javascriptcomponent/BasicJavaScriptComponent.html Zobrazit soubor

@@ -1,71 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/run/com.vaadin.tests.components.javascriptcomponent.BasicJavaScriptComponent?restartApplication</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td>
<td>3. Got callback message: Callback message processed</td>
</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1]</td>
<td>2. Got RPC message: RPC message processed</td>
</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[2]</td>
<td>1. Parent ids checked</td>
</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/domChild[1]/domChild[0]/domChild[0]</td>
<td>Component caption</td>
</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/JavaScriptWidget[0]/domChild[0]</td>
<td>4. Url: */run/APP/connector/0/10/test</td>
</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/JavaScriptWidget[0]/domChild[1]</td>
<td>3. State message: Second state message</td>
</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/JavaScriptWidget[0]/domChild[2]</td>
<td>2. State message: First state message</td>
</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::/VVerticalLayout[0]/VVerticalLayout[0]/JavaScriptWidget[0]/domChild[3]</td>
<td>1. Parent element className: v-verticallayout v-layout v-vertical v-widget v-has-width</td>
</tr>
<tr>
<td>click</td>
<td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::PID_SRemoveButton/domChild[0]/domChild[0]</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsjavascriptcomponentBasicJavaScriptComponent::PID_SRemoveButton</td>
<td>Remove componentDon't mess with me</td>
</tr>
</tbody></table>
</body>
</html>

Načítá se…
Zrušit
Uložit