Skip to content

Commit

Permalink
test: fix issues in signal test (#928)
Browse files Browse the repository at this point in the history
Fixes compilation and runtime issues
  • Loading branch information
mcollovati authored Sep 7, 2024
1 parent 926fe8b commit 2d3d2c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.vaadin.flow.server.auth.AnonymousAllowed;
import com.vaadin.hilla.BrowserCallable;
import com.vaadin.hilla.signals.NumberSignal;
import com.vaadin.hilla.signals.core.StateEvent;
import com.vaadin.hilla.signals.core.event.StateEvent;

@BrowserCallable
public class SecureNumberSignalService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
@AnonymousAllowed
@BrowserCallable
public class NumberSignalService {
public static final double INITIAL_SHARED_VALUE = 0.5;
private final NumberSignal counter = new NumberSignal();
private final NumberSignal sharedValue = new NumberSignal(0.5);
private final NumberSignal sharedValue = new NumberSignal(INITIAL_SHARED_VALUE);

public NumberSignal counter() {
return counter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;
import static com.codeborne.selenide.Selenide.Wait;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

Expand Down Expand Up @@ -60,8 +61,15 @@ public void shouldUpdateValue_both_on_browser_and_server() {

@Test
public void shouldUpdateValue_forOtherClients() {
var currentSharedValue = getSharedValue();
var currentSharedValue = Wait().until(d -> {
var value = getSharedValue();
if (value > 0.0) {
return value;
}
return null;
});
var currentCounterValue = getCounterValue();

var firstWindowHandle = Selenide.webdriver().driver().getWebDriver().getWindowHandle();

var secondWindowDriver = Selenide.switchTo().newWindow(WindowType.WINDOW);
Expand Down Expand Up @@ -103,12 +111,11 @@ public void shouldUpdateValue_forOtherClients() {

private double getSharedValue() {
return Double.parseDouble(
$("span[id=\"sharedValue\"]").shouldNotBe(Condition.empty).getText());
$(By.id("sharedValue")).shouldNotBe(Condition.empty).getText());
}

private long getCounterValue() {
return Long.parseLong(
$("span[id=\"counter\"]").shouldNotBe(Condition.empty).getText());
return Long.parseLong($(By.id("counter")).shouldNotBe(Condition.empty).getText());
}

private double fetchSharedValue() {
Expand Down

0 comments on commit 2d3d2c0

Please sign in to comment.