Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API to detect if GridMultiSelect select-all checkbox is checked #12086

Merged
merged 2 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ public void setUserSelectionAllowed(boolean allowed) {
model.setUserSelectionAllowed(allowed);
}

/**
* Returns whether all items are selected or not.
* <p>
* This is only {@code true} if user has selected all rows with the select
* all checkbox on client side, or if {@link #selectAll()} has been used
* from server side.
*
* @return {@code true} if all selected, {@code false} if not
* @since 8.12.0
*/
public boolean isAllSelected() {
return model.isAllSelected();
}

/**
* Checks if the user is allowed to change the selection.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,16 @@ public void setSelectAllCheckBoxVisibility(
* @see #setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility)
*/
public boolean isSelectAllCheckBoxVisible();

/**
* Returns whether all items are selected or not.
* <p>
* This is only {@code true} if user has selected all rows with the select
* all checkbox on client side, or if {@link #selectAll()} has been used
* from server side.
*
* @return {@code true} if all selected, {@code false} if not
* @since 8.12.0
*/
boolean isAllSelected();
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,7 @@ public boolean isSelectAllCheckBoxVisible() {
return getState(false).selectAllCheckBoxVisible;
}

/**
* Returns whether all items are selected or not.
* <p>
* This is only {@code true} if user has selected all rows with the select
* all checkbox on client side, or if {@link #selectAll()} has been used
* from server side.
*
* @return {@code true} if all selected, {@code false} if not
*/
@Override
public boolean isAllSelected() {
return getState(false).allSelected;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.vaadin.tests.components.grid;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.Label;

public class GridSelectAllStatus extends AbstractTestUI {

public Grid<String> grid;

@Override
protected void setup(VaadinRequest request) {
grid = new Grid<>();
grid.setSelectionMode(SelectionMode.MULTI);
grid.setItems("Item 1", "Item 2");
grid.addColumn(item -> item);

Label label = new Label("Select-all checkbox is checked?");
Label selectAllStatus = new Label(
String.valueOf(grid.asMultiSelect().isAllSelected()));
selectAllStatus.setId("status");

grid.asMultiSelect()
.addMultiSelectionListener(e -> selectAllStatus.setValue(
String.valueOf(grid.asMultiSelect().isAllSelected())));

addComponents(grid, label, selectAllStatus);
}

@Override
protected Integer getTicketNumber() {
return 12081;
}

@Override
protected String getTestDescription() {
return "The status of the Grid's select-all checkbox should be "
+ "accessible through the Java API.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.vaadin.tests.components.grid;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.openqa.selenium.WebElement;

import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class GridSelectAllStatusTest extends MultiBrowserTest {

@Test
public void checkSelectAllStatus() {
openTestURL();

GridElement grid = $(GridElement.class).first();
LabelElement selectAllStatusLabel = $(LabelElement.class).id("status");
WebElement selectAllCheckbox = grid
.findElement(By.className("v-grid-select-all-checkbox"));

// select all
selectAllCheckbox.click();
assertTrue(
"The status of the select-all checkbox is expected to be True.",
Boolean.parseBoolean(selectAllStatusLabel.getText()));

// De-select all selections
selectAllCheckbox.click();
assertFalse(
"The status of the select-all checkbox is expected to be False.",
Boolean.parseBoolean(selectAllStatusLabel.getText()));
}
}