Skip to content

Commit 4969cd1

Browse files
authored
feat: add CrudElement.getForm, deprecate CrudElement.getEditor (#7797)
1 parent 2919f95 commit 4969cd1

File tree

7 files changed

+50
-24
lines changed

7 files changed

+50
-24
lines changed

vaadin-crud-flow-parent/vaadin-crud-flow-integration-tests/src/test/java/com/vaadin/flow/component/crud/tests/CustomGridIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void editTest() {
3434
Assert.assertFalse(crud.isEditorOpen());
3535
crud.openRowForEditing(0);
3636
Assert.assertTrue(crud.isEditorOpen());
37-
TextFieldElement lastNameField = crud.getEditor()
37+
TextFieldElement lastNameField = crud.getForm()
3838
.$(TextFieldElement.class)
3939
.withAttribute("editor-role", "last-name").first();
4040

@@ -54,7 +54,7 @@ public void cancelChangesTest() {
5454
Assert.assertFalse(crud.isEditorOpen());
5555
crud.openRowForEditing(0);
5656
Assert.assertTrue(crud.isEditorOpen());
57-
TextFieldElement lastNameField = crud.getEditor()
57+
TextFieldElement lastNameField = crud.getForm()
5858
.$(TextFieldElement.class)
5959
.withAttribute("editor-role", "last-name").first();
6060

vaadin-crud-flow-parent/vaadin-crud-flow-integration-tests/src/test/java/com/vaadin/flow/component/crud/tests/DetachAttachIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void disableSaveBtn_detach_reattach_btnDisabled() {
4747
private void editItemAndChangeField() {
4848
crud = $(CrudElement.class).waitForFirst();
4949
crud.openRowForEditing(0);
50-
TextFieldElement lastNameField = crud.getEditor()
50+
TextFieldElement lastNameField = crud.getForm()
5151
.$(TextFieldElement.class)
5252
.withAttribute("editor-role", "last-name").first();
5353
lastNameField.setValue("Otto");

vaadin-crud-flow-parent/vaadin-crud-flow-integration-tests/src/test/java/com/vaadin/flow/component/crud/tests/EditorButtonsIT.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void saveBtnIsAlwaysDisabled() {
4545
getTestButton("disable-save-button").click();
4646
CrudElement crud = getCrud();
4747
crud.openRowForEditing(0);
48-
TextFieldElement lastNameField = crud.getEditor()
48+
TextFieldElement lastNameField = crud.getForm()
4949
.$(TextFieldElement.class)
5050
.withAttribute("editor-role", "last-name").first();
5151
lastNameField.setValue("Otto");
@@ -60,7 +60,7 @@ public void saveButtonCanBeDisabledOnTheServer() {
6060
crud.getNewItemButton().get().click();
6161
assertTrue(crud.isEditorOpen());
6262

63-
TextFieldElement lastNameField = crud.getEditor()
63+
TextFieldElement lastNameField = crud.getForm()
6464
.$(TextFieldElement.class)
6565
.withAttribute("editor-role", "last-name").first();
6666
lastNameField.setValue("Otto");
@@ -79,7 +79,7 @@ public void saveButtonBecomesEnabledWhenFormBecomesDirty() {
7979
ButtonElement saveButton = crud.getEditorSaveButton();
8080
assertFalse(saveButton.isEnabled());
8181

82-
TextFieldElement lastNameField = crud.getEditor()
82+
TextFieldElement lastNameField = crud.getForm()
8383
.$(TextFieldElement.class)
8484
.withAttribute("editor-role", "last-name").first();
8585
lastNameField.setValue("Otto");
@@ -98,7 +98,7 @@ public void saveButtonDisabledStateCanBeControlledOnTheServer() {
9898
ButtonElement saveButton = crud.getEditorSaveButton();
9999
assertFalse("Save button should be disabled", saveButton.isEnabled());
100100

101-
TextFieldElement lastNameField = crud.getEditor()
101+
TextFieldElement lastNameField = crud.getForm()
102102
.$(TextFieldElement.class)
103103
.withAttribute("editor-role", "last-name").first();
104104
lastNameField.setValue("Otto");
@@ -122,7 +122,7 @@ public void cancelButtonDisabledStateCanBeControlledOnTheServer() {
122122
assertFalse("Cancel button should be disabled",
123123
cancelButton.isEnabled());
124124

125-
TextFieldElement lastNameField = crud.getEditor()
125+
TextFieldElement lastNameField = crud.getForm()
126126
.$(TextFieldElement.class)
127127
.withAttribute("editor-role", "last-name").first();
128128
lastNameField.setValue("Otto");
@@ -146,7 +146,7 @@ public void deleteButtonDisabledStateCanBeControlledOnTheServer() {
146146
assertFalse("Delete button should be disabled",
147147
deleteButton.isEnabled());
148148

149-
TextFieldElement lastNameField = crud.getEditor()
149+
TextFieldElement lastNameField = crud.getForm()
150150
.$(TextFieldElement.class)
151151
.withAttribute("editor-role", "last-name").first();
152152
lastNameField.setValue("Otto");
@@ -167,7 +167,7 @@ public void buttonsCanWorkWithShortcutsDefinedOnServer() {
167167

168168
getTestButton("add-enter-shortcut-button").click();
169169

170-
TextFieldElement lastNameField = crud.getEditor()
170+
TextFieldElement lastNameField = crud.getForm()
171171
.$(TextFieldElement.class)
172172
.withAttribute("editor-role", "last-name").first();
173173
lastNameField.setValue(lastNameExpected);

vaadin-crud-flow-parent/vaadin-crud-flow-integration-tests/src/test/java/com/vaadin/flow/component/crud/tests/EventHandlingIT.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ public void editTest() {
8787
"Edit: Person{id=3, firstName='Guille', lastName='Guille'}",
8888
getLastEvent());
8989

90-
Assert.assertEquals("Guille", crud.getEditor().$(TextFieldElement.class)
90+
Assert.assertEquals("Guille", crud.getForm().$(TextFieldElement.class)
9191
.withAttribute("editor-role", "first-name").first().getValue());
9292

93-
Assert.assertEquals("Guille", crud.getEditor().$(TextFieldElement.class)
93+
Assert.assertEquals("Guille", crud.getForm().$(TextFieldElement.class)
9494
.withAttribute("editor-role", "last-name").first().getValue());
9595
}
9696

@@ -110,7 +110,7 @@ public void editTest_serverSide() {
110110

111111
// Ensure editor is marked dirty on edit
112112
getTestButton("editServerItem").click();
113-
crud.getEditor().$(TextFieldElement.class)
113+
crud.getForm().$(TextFieldElement.class)
114114
.withAttribute("editor-role", "first-name").first()
115115
.setValue("Vaadin");
116116

@@ -149,7 +149,7 @@ public void deleteTest() {
149149
public void saveTest() {
150150
CrudElement crud = $(CrudElement.class).waitForFirst();
151151
crud.openRowForEditing(0);
152-
TextFieldElement lastNameField = crud.getEditor()
152+
TextFieldElement lastNameField = crud.getForm()
153153
.$(TextFieldElement.class)
154154
.withAttribute("editor-role", "last-name").first();
155155
Assert.assertTrue(lastNameField.isInvalid());
@@ -178,14 +178,14 @@ public void emptyInvalidFieldsIndicatedOnSave() {
178178
CrudElement crud = $(CrudElement.class).waitForFirst();
179179
crud.getNewItemButton().get().click();
180180

181-
TextFieldElement firstNameField = crud.getEditor()
181+
TextFieldElement firstNameField = crud.getForm()
182182
.$(TextFieldElement.class)
183183
.withAttribute("editor-role", "first-name").first();
184184

185185
Assert.assertFalse(firstNameField.isInvalid());
186186

187187
// To avoid editor being dirty
188-
TextFieldElement lastNameField = crud.getEditor()
188+
TextFieldElement lastNameField = crud.getForm()
189189
.$(TextFieldElement.class)
190190
.withAttribute("editor-role", "last-name").first();
191191
lastNameField.setValue("Oladeji");
@@ -200,7 +200,7 @@ public void invalidFieldsIndicatedOnSave() {
200200
CrudElement crud = $(CrudElement.class).waitForFirst();
201201
crud.openRowForEditing(1);
202202

203-
TextFieldElement lastNameField = crud.getEditor()
203+
TextFieldElement lastNameField = crud.getForm()
204204
.$(TextFieldElement.class)
205205
.withAttribute("editor-role", "last-name").first();
206206

@@ -219,7 +219,7 @@ public void newItemDialogFields_ShouldPrefilledWithExpectedValues_SetInNewEventL
219219

220220
crud.getNewItemButton().get().click();
221221

222-
TestBenchElement editor = crud.getEditor();
222+
TestBenchElement editor = crud.getForm();
223223
TextFieldElement firstNameField = editor.$(TextFieldElement.class)
224224
.withAttribute("editor-role", "first-name").first();
225225
TextFieldElement lastNameField = editor.$(TextFieldElement.class)

vaadin-crud-flow-parent/vaadin-crud-flow-integration-tests/src/test/java/com/vaadin/flow/component/crud/tests/ProtectedBackendIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private void modify(CrudElement crud, String newValue,
8484
boolean isModifyAllowed) {
8585
Assert.assertTrue(crud.isEditorOpen());
8686

87-
TextFieldElement lastNameField = crud.getEditor()
87+
TextFieldElement lastNameField = crud.getForm()
8888
.$(TextFieldElement.class)
8989
.withAttribute("editor-role", "last-name").first();
9090

vaadin-crud-flow-parent/vaadin-crud-flow-integration-tests/src/test/java/com/vaadin/flow/component/crud/tests/TemplateSupportIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ public void editTest() {
7272
"Edit: Person{id=3, firstName='Guille', lastName='Guille'}",
7373
getLastEvent());
7474

75-
Assert.assertEquals("Guille", crud.getEditor().$(TextFieldElement.class)
75+
Assert.assertEquals("Guille", crud.getForm().$(TextFieldElement.class)
7676
.id("firstName").getValue());
7777

78-
Assert.assertEquals("Guille", crud.getEditor().$(TextFieldElement.class)
78+
Assert.assertEquals("Guille", crud.getForm().$(TextFieldElement.class)
7979
.id("lastName").getValue());
8080
}
8181

8282
@Test
8383
public void saveTest() {
8484
CrudElement crud = getCrud().waitForFirst();
8585
crud.openRowForEditing(0);
86-
TextFieldElement lastNameField = crud.getEditor()
86+
TextFieldElement lastNameField = crud.getForm()
8787
.$(TextFieldElement.class).id("lastName");
8888
lastNameField.setValue("Oladeji");
8989

vaadin-crud-flow-parent/vaadin-crud-testbench/src/main/java/com/vaadin/flow/component/crud/testbench/CrudElement.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.util.Optional;
1313
import java.util.stream.Collectors;
1414

15+
import org.openqa.selenium.By;
16+
1517
import com.vaadin.flow.component.button.testbench.ButtonElement;
1618
import com.vaadin.flow.component.confirmdialog.testbench.ConfirmDialogElement;
1719
import com.vaadin.flow.component.grid.testbench.GridElement;
@@ -150,14 +152,38 @@ public boolean isEditOnClick() {
150152
}
151153

152154
/**
153-
* Gets the open editor overlay
155+
* Since v25.0, returns the Crud element itself for backwards compatibility.
154156
*
155-
* @return the open editor overlay
157+
* @return the Crud element itself
158+
* @deprecated Pre v25.0, this method returned either the editor overlay,
159+
* when the editor was displayed as a dialog, or the Crud
160+
* itself, when the editor was displayed inline. Since v25.0,
161+
* the overlay is not accessible as a separate element anymore,
162+
* and, regardless whether the editor is displayed as a dialog
163+
* or inline, all editor-related controls can be queried through
164+
* the Crud element itself. To specifically access the editor
165+
* fields, use {@link #getForm()} instead. To access the editor
166+
* buttons, use {@link #getEditorSaveButton()},
167+
* {@link #getEditorCancelButton()}, and
168+
* {@link #getEditorDeleteButton()}.
156169
*/
170+
@Deprecated(since = "25.0", forRemoval = true)
157171
public TestBenchElement getEditor() {
158172
return this;
159173
}
160174

175+
/**
176+
* Gets the form element that contains form fields.
177+
*
178+
* @return the form element
179+
*/
180+
public TestBenchElement getForm() {
181+
// Not using TestBench query here, as it would return the slot element
182+
// within its shadow root
183+
return wrapElement(findElement(By.cssSelector("[slot='form']")),
184+
getCommandExecutor());
185+
}
186+
161187
/**
162188
* Gets the confirm cancel dialog
163189
*

0 commit comments

Comments
 (0)