Skip to content

Commit 64debe6

Browse files
vaadin-botugur-vaadinDiegoCardoso
authored
test: add tests for registering custom editor values while tabbing (#7753) (#7784)
* fix: use new custom editor if editors are updated * chore: fix formatting --------- Co-authored-by: Ugur Saglam <106508695+ugur-vaadin@users.noreply.github.com> Co-authored-by: Diego Cardoso <diego@vaadin.com>
1 parent f3b7e64 commit 64debe6

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright 2000-2025 Vaadin Ltd.
3+
*
4+
* This program is available under Vaadin Commercial License and Service Terms.
5+
*
6+
* See {@literal <https://vaadin.com/commercial-license-and-service-terms>} for the full
7+
* license.
8+
*/
9+
package com.vaadin.flow.component.spreadsheet.tests.fixtures;
10+
11+
import org.apache.poi.ss.usermodel.Cell;
12+
import org.apache.poi.ss.usermodel.Sheet;
13+
14+
import com.vaadin.flow.component.Component;
15+
import com.vaadin.flow.component.HasValue;
16+
import com.vaadin.flow.component.spreadsheet.Spreadsheet;
17+
import com.vaadin.flow.component.spreadsheet.SpreadsheetComponentFactory;
18+
import com.vaadin.flow.component.textfield.TextField;
19+
20+
public class AdjacentCustomEditorsFixture implements SpreadsheetFixture {
21+
22+
@Override
23+
public void loadFixture(final Spreadsheet spreadsheet) {
24+
spreadsheet.setShowCustomEditorOnFocus(true);
25+
spreadsheet.setSpreadsheetComponentFactory(new CustomEditorFactory());
26+
}
27+
28+
private static class CustomEditorFactory
29+
implements SpreadsheetComponentFactory {
30+
31+
@Override
32+
public Component getCustomComponentForCell(Cell cell, int rowIndex,
33+
int columnIndex, Spreadsheet spreadsheet, Sheet sheet) {
34+
return null;
35+
}
36+
37+
@Override
38+
public Component getCustomEditorForCell(Cell cell, final int rowIndex,
39+
final int columnIndex, final Spreadsheet spreadsheet,
40+
Sheet sheet) {
41+
if (rowIndex != 1 || columnIndex < 1 || columnIndex > 5) {
42+
return null;
43+
}
44+
var textField = new TextField();
45+
textField.addValueChangeListener(
46+
e -> spreadsheet.refreshCells(spreadsheet
47+
.createCell(rowIndex, columnIndex, e.getValue())));
48+
return textField;
49+
}
50+
51+
@Override
52+
public void onCustomEditorDisplayed(Cell cell, int rowIndex,
53+
int columnIndex, Spreadsheet spreadsheet, Sheet sheet,
54+
Component customEditor) {
55+
if (cell == null) {
56+
return;
57+
}
58+
String cellValue = cell.getStringCellValue();
59+
((HasValue) customEditor).setValue(cellValue);
60+
}
61+
}
62+
}

vaadin-spreadsheet-flow-parent/vaadin-spreadsheet-flow-integration-tests/src/main/java/com/vaadin/flow/component/spreadsheet/tests/fixtures/TestFixtures.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public enum TestFixtures {
3636
Rename(RenameFixture.class),
3737
CreateSheet(SheetsFixture.class),
3838
CustomEditor(SimpleCustomEditorFixture.class),
39+
AdjacentCustomEditors(AdjacentCustomEditorsFixture.class),
3940
CustomEditorShared(CustomEditorSharedFixture.class),
4041
CustomEditorRow(CustomEditorRowFixture.class),
4142
Styles(StylesFixture.class),

vaadin-spreadsheet-flow-parent/vaadin-spreadsheet-flow-integration-tests/src/test/java/com/vaadin/flow/component/spreadsheet/test/CustomEditorIT.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.time.LocalDate;
1212
import java.time.format.DateTimeFormatter;
13+
import java.util.List;
1314
import java.util.Optional;
1415

1516
import org.junit.Assert;
@@ -355,6 +356,20 @@ public void customEditorIsVisible_sheetIsChanged_editorsRemoved() {
355356
}
356357

357358
@Test
359+
public void adjacentCustomEditors_showOnFocus_navigateWithTabAndModify_valuesUpdated() {
360+
getSpreadsheet().addSheet();
361+
loadTestFixture(TestFixtures.AdjacentCustomEditors);
362+
var cellsToModify = List.of("B2", "C2", "D2", "E2", "F2");
363+
var valueToSet = "a";
364+
selectCell("A2");
365+
cellsToModify.forEach(
366+
address -> moveToNextCellAndAssertEditorInCellIsFocusedWithKeyPress(
367+
address, valueToSet));
368+
getActiveElement().sendKeys(Keys.TAB);
369+
cellsToModify.forEach(address -> Assert.assertEquals(valueToSet,
370+
getCellValue(address)));
371+
}
372+
358373
public void customEditorShared_persistsValuesCorrectly() {
359374
createNewSpreadsheet();
360375
loadTestFixture(TestFixtures.CustomEditorShared);

0 commit comments

Comments
 (0)