Check 'Select all' checkboxes on page load if all its checkboxes are checked

This means the code to set the initial value in the view template isn't needed.
This commit is contained in:
Cillian O'Ruanaidh
2022-07-29 10:24:09 +01:00
committed by Filipe
parent 512394862b
commit 8e47949260
3 changed files with 36 additions and 1 deletions

View File

@@ -79,4 +79,35 @@ describe("SelectAllController", () => {
expect(checkboxB.checked).toBe(false);
});
});
describe("#connect", () => {
beforeEach(() => {
document.body.innerHTML = `
<div data-controller="select-all">
<input
id="selectAllCheckbox"
type="checkbox"
data-action="change->select-all#toggleAll"
data-select-all-target="all">
<input
id="checkboxA"
type="checkbox"
data-action="change->select-all#toggleCheckbox"
data-select-all-target="checkbox"
checked="checked">
<input
id="checkboxB"
type="checkbox"
data-action="change->select-all#toggleCheckbox"
data-select-all-target="checkbox"
checked="checked">
</div>
`;
});
it("checks the select all checkbox on page load if all checkboxes are checked", () => {
const selectAllCheckbox = document.getElementById("selectAllCheckbox");
expect(selectAllCheckbox.checked).toBe(true);
});
});
});