Skip to content

Commit 784a164

Browse files
committed
fix: fix support for modality in MockedUI
1 parent 8e5209d commit 784a164

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

vaadin-testbench-unit-junit5/src/test/java/com/vaadin/flow/component/dialog/DialogTesterTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.junit.jupiter.api.BeforeEach;
1313
import org.junit.jupiter.api.Test;
1414

15+
import com.vaadin.flow.component.ModalityMode;
1516
import com.vaadin.flow.component.button.Button;
1617
import com.vaadin.flow.component.button.ButtonTester;
1718
import com.vaadin.flow.router.RouteConfiguration;
@@ -56,7 +57,18 @@ void programmaticallyClose_dialogIsDetached() {
5657
}
5758

5859
@Test
59-
void modalDialog_blocksUIComponents() {
60+
void modalDialog_visual_doNotBlockUIComponents() {
61+
view.dialog.setModality(ModalityMode.VISUAL);
62+
dialog_.open();
63+
ButtonTester<Button> button_ = test(view.button);
64+
Assertions.assertTrue(button_.isUsable(),
65+
"Default VISUAL modal dialog should not block button");
66+
}
67+
68+
@Test
69+
void modalDialog_strict_blocksUIComponents() {
70+
view.dialog.setModality(ModalityMode.STRICT);
71+
// view.dialog.setModal(true);
6072
dialog_.open();
6173
ButtonTester<Button> button_ = test(view.button);
6274
Assertions.assertFalse(button_.isUsable(),
@@ -70,7 +82,7 @@ void modalDialog_blocksUIComponents() {
7082

7183
@Test
7284
void nonModalDialog_UIComponentsUsable() {
73-
view.dialog.setModal(false);
85+
view.dialog.setModality(ModalityMode.MODELESS);
7486
dialog_.open();
7587
ButtonTester<Button> button_ = test(view.button);
7688
Assertions.assertTrue(button_.isUsable(),

vaadin-testbench-unit-shared/src/main/java/com/vaadin/flow/component/dialog/DialogTester.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public DialogTester(Dialog component) {
2929
public void open() {
3030
getComponent().open();
3131
roundTrip();
32+
roundTrip();
3233
}
3334

3435
/**

vaadin-testbench-unit-shared/src/main/kotlin/com/vaadin/testbench/unit/mocks/MockedUI.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package com.vaadin.testbench.unit.mocks
1111

1212
import com.vaadin.flow.component.Component
1313
import com.vaadin.flow.component.ComponentEventListener
14+
import com.vaadin.flow.component.ModalityMode
1415
import com.vaadin.flow.component.UI
1516
import com.vaadin.flow.shared.Registration
1617
import java.util.concurrent.atomic.AtomicReference
@@ -26,9 +27,9 @@ import com.vaadin.testbench.unit.internal.simulateClosedEvent
2627
*/
2728
open class MockedUI : UI() {
2829

29-
override fun setChildComponentModal(childComponent: Component?, modal: Boolean) {
30-
super.setChildComponentModal(childComponent, modal)
31-
if (modal) {
30+
override fun setChildComponentModal(childComponent: Component?, mode: ModalityMode) {
31+
super.setChildComponentModal(childComponent, mode)
32+
if (mode != ModalityMode.MODELESS) {
3233
val registrationCombination: AtomicReference<Registration?> = AtomicReference<Registration?>()
3334
registrationCombination.set(childComponent?.addDetachListener(ComponentEventListener {
3435
roundTrip()

0 commit comments

Comments
 (0)