-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: verify no errors after Grid detach and clear items (#570)
- Loading branch information
Showing
2 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
.../src/main/java/com/vaadin/flow/component/grid/it/GridClearAfterDetachAndReattachPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2000-2020 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.vaadin.flow.component.grid.it; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import com.vaadin.flow.component.grid.Grid; | ||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.component.html.NativeButton; | ||
import com.vaadin.flow.data.bean.PeopleGenerator; | ||
import com.vaadin.flow.data.bean.Person; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route("vaadin-grid/clean-grid-items-after-detach-and-reattach") | ||
public class GridClearAfterDetachAndReattachPage extends Div { | ||
|
||
public static final String GRID_ID = "person-grid-id"; | ||
public static final String CLEAR_BUTTON_ID = "clear-button-id"; | ||
|
||
public static final int GRID_ROW_COUNT = 150; | ||
|
||
public GridClearAfterDetachAndReattachPage() { | ||
Div gridContainer = new Div(); | ||
gridContainer.setWidthFull(); | ||
Grid<Person> grid = new Grid<>(); | ||
grid.addColumn(Person::getFirstName); | ||
grid.addColumn(Person::getLastName); | ||
grid.addColumn(Person::getAge); | ||
final List<Person> persons = new PeopleGenerator() | ||
.generatePeople(GRID_ROW_COUNT); | ||
grid.setItems(persons); | ||
grid.setId(GRID_ID); | ||
|
||
NativeButton clearGrid = new NativeButton("Clear Grid", click -> { | ||
// Remove grid from it's container and add it again | ||
gridContainer.removeAll(); | ||
gridContainer.add(grid); | ||
// Clear the underlying data | ||
grid.setItems(Collections.emptyList()); | ||
}); | ||
clearGrid.setId(CLEAR_BUTTON_ID); | ||
|
||
gridContainer.add(grid); | ||
add(gridContainer); | ||
add(clearGrid); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...ts/src/test/java/com/vaadin/flow/component/grid/it/GridClearAfterDetachAndReattachIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2000-2020 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package com.vaadin.flow.component.grid.it; | ||
|
||
import org.junit.Test; | ||
|
||
import com.vaadin.flow.component.grid.testbench.GridElement; | ||
import com.vaadin.flow.testutil.TestPath; | ||
import com.vaadin.tests.AbstractComponentIT; | ||
|
||
import static com.vaadin.flow.component.grid.it.GridClearAfterDetachAndReattachPage.CLEAR_BUTTON_ID; | ||
import static com.vaadin.flow.component.grid.it.GridClearAfterDetachAndReattachPage.GRID_ID; | ||
import static com.vaadin.flow.component.grid.it.GridClearAfterDetachAndReattachPage.GRID_ROW_COUNT; | ||
|
||
@TestPath("vaadin-grid/clean-grid-items-after-detach-and-reattach") | ||
public class GridClearAfterDetachAndReattachIT extends AbstractComponentIT { | ||
|
||
@Test // https://github.com/vaadin/vaadin-grid/issues/1837 | ||
public void clearGridItemsAfterDetachAndReattach_gridItemsClearedWithNoErrors() { | ||
open(); | ||
|
||
GridElement gridElement = $(GridElement.class).id(GRID_ID); | ||
waitUntil((driver) -> gridElement.getLastVisibleRowIndex() > 0); | ||
// Scroll to the end | ||
gridElement.scrollToRow(gridElement.getRowCount()); | ||
waitUntil((driver) -> gridElement.getLastVisibleRowIndex() == | ||
GRID_ROW_COUNT - 1); | ||
|
||
// Check that there are no exceptions/errors in the logs | ||
checkLogsForErrors(); | ||
|
||
$("button").id(CLEAR_BUTTON_ID).click(); | ||
waitUntil((driver) -> gridElement.getRowCount() == 0); | ||
|
||
// Check that there are no new exceptions/errors throws after | ||
// cleaning the grid | ||
checkLogsForErrors(); | ||
} | ||
} |