Browse Source

Fix removing rows from the middle of Escalator (#8826)

* Fix removing rows from the middle of Escalator

Fixes #8825
tags/8.1.0.alpha1
Pekka Hyvönen 7 years ago
parent
commit
1e8ad07135

+ 2
- 8
client/src/main/java/com/vaadin/client/widgets/Escalator.java View File

@@ -3130,14 +3130,8 @@ public class Escalator extends Widget
y += spacerContainer.getSpacerHeight(i);
}

/*
* this is how many rows appeared into the viewport from
* below
*/
final int rowsToUpdateDataOn = numberOfRows
- escalatorRowsToRemove;
final int start = Math.max(0,
escalatorRowCount - rowsToUpdateDataOn);
// #8825 update data starting from the first moved row
final int start = dirtyRowsStart;
final int end = escalatorRowCount;
for (int i = start; i < end; i++) {
final TableRowElement tr = visualRowOrder.get(i);

+ 12
- 0
uitest/src/main/java/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java View File

@@ -540,6 +540,12 @@ public class EscalatorBasicClientFeaturesWidget
insertRows(escalator.getBody(), 0, 5);
}
}, menupath);
addMenuCommand("Add 22 rows to top", new ScheduledCommand() {
@Override
public void execute() {
insertRows(escalator.getBody(), 0, 22);
}
}, menupath);
addMenuCommand("Add 50 rows to top", new ScheduledCommand() {
@Override
public void execute() {
@@ -560,6 +566,12 @@ public class EscalatorBasicClientFeaturesWidget
escalator.getBody().getRowCount() - 50, 50);
}
}, menupath);
addMenuCommand("Remove 15 rows from middle", new ScheduledCommand() {
@Override
public void execute() {
removeRows(escalator.getBody(), 3, 15);
}
}, menupath);
addMenuCommand("Remove 50 rows from almost bottom",
new ScheduledCommand() {
@Override

+ 2
- 0
uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java View File

@@ -59,6 +59,8 @@ public abstract class EscalatorBasicClientFeaturesTest
protected static final String SCROLL_TO = "Scroll to...";

protected static final String REMOVE_ALL_INSERT_SCROLL = "Remove all, insert 30 and scroll 40px";
protected static final String ADD_22_ROWS_TO_TOP = "Add 22 rows to top";
protected static final String REMOVE_15_ROWS_FROM_MIDDLE = "Remove 15 rows from middle";

protected static final String GENERAL = "General";
protected static final String DETACH_ESCALATOR = "Detach Escalator";

+ 30
- 1
uitest/src/test/java/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorRemoveAndAddRowsTest.java View File

@@ -19,6 +19,7 @@ import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
@@ -38,7 +39,6 @@ public class EscalatorRemoveAndAddRowsTest

@Test
public void testRemoveAllRowsAndAddThirtyThenScroll() throws IOException {

selectMenuPath(GENERAL, POPULATE_COLUMN_ROW);

scrollVerticallyTo(99999);
@@ -51,4 +51,33 @@ public class EscalatorRemoveAndAddRowsTest
assertTrue("Escalator is not scrolled to bottom.",
isElementPresent(By.xpath("//td[text() = 'Row 29: 0,129']")));
}

@Test
public void testRemoveRowsFromMiddle() {
selectMenuPath(COLUMNS_AND_ROWS, COLUMNS, ADD_ONE_COLUMN_TO_BEGINNING);
selectMenuPath(COLUMNS_AND_ROWS, HEADER_ROWS, ADD_ONE_ROW_TO_BEGINNING);
selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, ADD_22_ROWS_TO_TOP);
// remove enough rows from middle, so that the total size of escalator
// rows drops to below the size of the rows shown, forcing the escalator
// to remove & move & update rows
selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, REMOVE_15_ROWS_FROM_MIDDLE);
// first there was rows 0-21, then removed 15 rows 3-18, thus the rows
// should be 0,1,2,18,19,20,21
verifyRow(0, 0);
verifyRow(1, 1);
verifyRow(2, 2);
verifyRow(3, 18);
verifyRow(4, 19);
verifyRow(5, 20);
verifyRow(6, 21);
}

private void verifyRow(int escalatorIndex, int rowIndexInText) {
// the format of text in cells is
// Row: <index_when_updated>: <cell_index>,<index_when_inserted>
Assert.assertEquals("Invalid row present in index " + escalatorIndex,
"Row " + escalatorIndex + ": 0," + rowIndexInText,
getBodyCell(escalatorIndex, 0).getText());
}

}

Loading…
Cancel
Save