Skip to content

Commit

Permalink
fix: update setChecked to dispatch change event (#7000)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Jan 6, 2025
1 parent 6da1b8f commit cb16438
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component.checkbox.testbench;

import java.util.Collections;

import com.vaadin.testbench.HasHelper;
import com.vaadin.testbench.HasLabel;
import com.vaadin.testbench.TestBenchElement;
Expand Down Expand Up @@ -46,6 +48,7 @@ public boolean isChecked() {
*/
public void setChecked(boolean checked) {
setProperty("checked", checked);
dispatchEvent("change", Collections.singletonMap("bubbles", true));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.vaadin.flow.component.checkbox.testbench.CheckboxElement;
import com.vaadin.flow.component.grid.testbench.GridElement;
import com.vaadin.flow.testutil.TestPath;
import com.vaadin.testbench.TestBenchElement;
Expand Down Expand Up @@ -131,6 +132,26 @@ public void selectAllCheckbox_state() {
selectAllCheckbox.getAttribute("indeterminate"));
}

@Test
public void selectAllCheckbox_setChecked_selectsAndDeselectsItems() {
open();

GridElement grid = $(GridElement.class)
.id(GridMultiSelectionColumnPage.IN_MEMORY_GRID_ID);
CheckboxElement selectAllCheckbox = grid.$(CheckboxElement.class)
.id(SELECT_ALL_CHECKBOX_ID);
WebElement message = findElement(By.id("selected-item-count"));

selectAllCheckbox.setChecked(true);
Assert.assertEquals(
"Selected item count: "
+ GridMultiSelectionColumnPage.ITEM_COUNT,
message.getText());

selectAllCheckbox.setChecked(false);
Assert.assertEquals("Selected item count: 0", message.getText());
}

@Test
public void selectCheckboxMultiSelectionMode() {
open();
Expand Down

0 comments on commit cb16438

Please sign in to comment.