Skip to content

Commit d5a11b6

Browse files
committed
WIP: integration tests
1 parent afbae48 commit d5a11b6

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<description>Simple Timer for Vaadin Flow</description>
1010

1111
<properties>
12-
<vaadin.version>14.11.12</vaadin.version>
12+
<vaadin.version>14.11.13</vaadin.version>
1313
<maven.compiler.source>1.8</maven.compiler.source>
1414
<maven.compiler.target>1.8</maven.compiler.target>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/test/java/com/flowingcode/addons/simpletimer/integration/IntegrationCallables.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@ public interface IntegrationCallables {
1414

1515
boolean isRunning();
1616

17+
void openDialog();
18+
19+
void closeDialog();
20+
// BigDecimal getCurrentTime();
21+
//
22+
// CompletableFuture<BigDecimal> getCurrentTimeAsync();
23+
//
24+
// Registration addCurrentTimeChangeListener(PropertyChangeListener listener, long period,
25+
// TimeUnit periodUnit);
26+
//
27+
// Registration addTimerEndEvent(ComponentEventListener<TimerEndedEvent> listener);
28+
1729
}

src/test/java/com/flowingcode/addons/simpletimer/integration/IntegrationView.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.flowingcode.vaadin.addons.simpletimer.SimpleTimer;
44
import com.vaadin.flow.component.ClientCallable;
5+
import com.vaadin.flow.component.dialog.Dialog;
56
import com.vaadin.flow.component.html.Div;
67
import com.vaadin.flow.router.Route;
78

@@ -10,10 +11,26 @@ public class IntegrationView extends Div implements IntegrationCallables {
1011

1112
private SimpleTimer timer = new SimpleTimer();
1213

14+
private Dialog dialog;
1315
public IntegrationView() {
1416
add(timer);
1517
}
1618

19+
@Override
20+
@ClientCallable
21+
public void openDialog() {
22+
if (dialog == null) {
23+
dialog = new Dialog(timer);
24+
}
25+
dialog.open();
26+
}
27+
28+
@Override
29+
@ClientCallable
30+
public void closeDialog() {
31+
dialog.close();
32+
}
33+
1734
@Override
1835
@ClientCallable
1936
public void setStartTime(Integer startTime) {

src/test/java/com/flowingcode/addons/simpletimer/integration/SimpleIT.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import static org.junit.Assert.assertFalse;
99
import static org.junit.Assert.assertTrue;
1010
import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport;
11+
import java.util.concurrent.TimeUnit;
12+
import org.junit.Ignore;
1113
import org.junit.Test;
1214

1315
public class SimpleIT extends AbstractViewTest implements HasRpcSupport {
@@ -18,6 +20,14 @@ public SimpleIT() {
1820
super("it");
1921
}
2022

23+
private static void sleep(long millis) {
24+
try {
25+
Thread.sleep(millis);
26+
} catch (InterruptedException e) {
27+
Thread.currentThread().interrupt();
28+
}
29+
}
30+
2131
private Double currentTime() {
2232
return $(SimpleTimerElement.class).first().currentTime();
2333
}
@@ -54,4 +64,33 @@ public void countUp() {
5464
assertThat(t1, greaterThan(t0));
5565
}
5666

67+
@Test
68+
@Ignore
69+
public void countUpInDialog() {
70+
$server.openDialog();
71+
$server.setEndTime(100);
72+
assertThat(currentTime(), equalTo(0.0));
73+
74+
long w0 = System.nanoTime();
75+
$server.start();
76+
double t0 = currentTime();
77+
assertThat(t0, greaterThan(0.0));
78+
long w1 = System.nanoTime();
79+
80+
$server.closeDialog();
81+
sleep(0);
82+
$server.openDialog();
83+
84+
long w2 = System.nanoTime();
85+
// double delta = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - now) / 1000.0;
86+
double t1 = currentTime();
87+
long w3 = System.nanoTime();
88+
// assertThat(t1, greaterThan(t0 + delta));
89+
System.out.println(TimeUnit.NANOSECONDS.toMillis(w3 - w0) / 1000.0);
90+
System.out.println(TimeUnit.NANOSECONDS.toMillis(w2 - w1) / 1000.0);
91+
System.out.println(t1 - t0);
92+
System.out.println(t0);
93+
System.out.println(t1);
94+
}
95+
5796
}

0 commit comments

Comments
 (0)