-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d08a9a
commit fb786ec
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/test/java/com/flowingcode/addons/simpletimer/integration/IntegrationCallables.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.flowingcode.addons.simpletimer.integration; | ||
|
||
public interface IntegrationCallables { | ||
|
||
void setStartTime(Integer startTime); | ||
|
||
void setEndTime(Integer endTime); | ||
|
||
void start(); | ||
|
||
void pause(); | ||
|
||
void reset(); | ||
|
||
boolean isRunning(); | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/test/java/com/flowingcode/addons/simpletimer/integration/IntegrationView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.flowingcode.addons.simpletimer.integration; | ||
|
||
import com.flowingcode.vaadin.addons.simpletimer.SimpleTimer; | ||
import com.vaadin.flow.component.ClientCallable; | ||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route("/it") | ||
public class IntegrationView extends Div implements IntegrationCallables { | ||
|
||
private SimpleTimer timer = new SimpleTimer(); | ||
|
||
public IntegrationView() { | ||
add(timer); | ||
} | ||
|
||
@Override | ||
@ClientCallable | ||
public void setStartTime(Integer startTime) { | ||
timer.setStartTime(startTime); | ||
} | ||
|
||
@Override | ||
@ClientCallable | ||
public void setEndTime(Integer endTime) { | ||
timer.setEndTime(endTime); | ||
} | ||
|
||
@Override | ||
@ClientCallable | ||
public void start() { | ||
timer.start(); | ||
} | ||
|
||
@Override | ||
@ClientCallable | ||
public void pause() { | ||
timer.pause(); | ||
} | ||
|
||
@Override | ||
@ClientCallable | ||
public void reset() { | ||
timer.reset(); | ||
} | ||
|
||
@Override | ||
@ClientCallable | ||
public boolean isRunning() { | ||
return timer.isRunning(); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/com/flowingcode/addons/simpletimer/integration/SimpleIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.flowingcode.addons.simpletimer.integration; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
import static org.hamcrest.Matchers.lessThan; | ||
import static org.hamcrest.Matchers.nullValue; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport; | ||
import org.junit.Test; | ||
|
||
public class SimpleIT extends AbstractViewTest implements HasRpcSupport { | ||
|
||
IntegrationCallables $server = createCallableProxy(IntegrationCallables.class); | ||
|
||
public SimpleIT() { | ||
super("it"); | ||
} | ||
|
||
private Double currentTime() { | ||
return $(SimpleTimerElement.class).first().currentTime(); | ||
} | ||
|
||
@Test | ||
public void countDown() { | ||
assertThat(currentTime(), nullValue()); | ||
assertFalse($server.isRunning()); | ||
|
||
$server.setStartTime(1); | ||
assertThat(currentTime(), equalTo(1.0)); | ||
|
||
$server.start(); | ||
assertTrue($server.isRunning()); | ||
double t0 = currentTime(); | ||
double t1 = currentTime(); | ||
assertThat(t0, lessThan(1.0)); | ||
assertThat(t1, lessThan(t0)); | ||
} | ||
|
||
@Test | ||
public void countUp() { | ||
assertThat(currentTime(), nullValue()); | ||
assertFalse($server.isRunning()); | ||
|
||
$server.setEndTime(1); | ||
assertThat(currentTime(), equalTo(0.0)); | ||
|
||
$server.start(); | ||
assertTrue($server.isRunning()); | ||
double t0 = currentTime(); | ||
double t1 = currentTime(); | ||
assertThat(t0, greaterThan(0.0)); | ||
assertThat(t1, greaterThan(t0)); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/com/flowingcode/addons/simpletimer/integration/SimpleTimerElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.flowingcode.addons.simpletimer.integration; | ||
|
||
import com.vaadin.testbench.TestBenchElement; | ||
import com.vaadin.testbench.elementsbase.Element; | ||
import java.util.Optional; | ||
|
||
@Element("simple-timer") | ||
public class SimpleTimerElement extends TestBenchElement { | ||
|
||
Double currentTime() { | ||
Number time = (Number) executeScript("return arguments[0].currentTime", this); | ||
return Optional.ofNullable(time).map(Number::doubleValue).orElse(null); | ||
} | ||
|
||
} |