Skip to content

Commit

Permalink
test: verify no errors after Grid detach and clear items (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshabarov authored Jan 20, 2021
1 parent 13bab04 commit a4d3070
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
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);
}
}
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();
}
}

0 comments on commit a4d3070

Please sign in to comment.