-
Notifications
You must be signed in to change notification settings - Fork 23
Labels
Description
I expect ComponentEvent.isFromClient()
to return true when using TestWrappers.test()
in a SpringUIUnitTest
to execute the action, that triggers the ComponentEvent
.
Instead it returns false.
Steps to reproduce
MainView.java
package org.vaadin.example;
import com.vaadin.flow.component.html.NativeLabel;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.Route;
@Route
public class MainView extends VerticalLayout {
static final String TEXT_FIELD = "textField";
static final String NATIVE_LABEL = "nativeLabel";
public MainView() {
TextField textField = new TextField();
textField.setId(TEXT_FIELD);
NativeLabel nativeLabel = new NativeLabel();
nativeLabel.setId(NATIVE_LABEL);
textField.addValueChangeListener(event -> {
if (event.isFromClient()) {
nativeLabel.setText(event.getValue());
}
});
add(textField, nativeLabel);
}
}
MainViewTest.java
package org.vaadin.example;
import static org.assertj.core.api.Assertions.*;
import static org.vaadin.example.MainView.NATIVE_LABEL;
import static org.vaadin.example.MainView.TEXT_FIELD;
import com.vaadin.flow.component.html.NativeLabel;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.testbench.unit.SpringUIUnitTest;
import org.junit.jupiter.api.Test;
class MainViewTest extends SpringUIUnitTest {
@Test
void whenSetTextThenSetLabel() {
navigate(MainView.class);
test($(TextField.class).id(TEXT_FIELD)).setValue("new value");
String label = $(NativeLabel.class).id(NATIVE_LABEL).getText();
assertThat(label).isEqualTo("new value");
}
}
Expected Result
event.isFromClient()
should return true, when TestWrappers.test()
is used to set the value of a TextField
.
Then MainViewTest#whenSetTextThenSetLabel
would complete successfuly.
Actual Result
MainViewTest#whenSetTextThenSetLabel
fails with this AssertionError
:
org.opentest4j.AssertionFailedError:
expected: "new value"
but was: ""
Versions
Vaadin 24.4.6
Java 17
macOS 14.5
mgeuer, MarioTrappein, snerb, stefanuebe, OlliTietavainenVaadin and 3 more
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
✅ Closed
Status
Done