-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix picture selector behavior (#2964)
Fixes a few issues: 1. Checkbox becomes invisible after selecting/unselecting an image 2. Selection toolbar is not visible when one or multiple images are selected Updates pictures select all behavior: - when no pictures selected then all pictures selected - when one/many pictures selected then all pictures selected instead of toggling of picture selection state Closes #2960
- Loading branch information
Showing
3 changed files
with
101 additions
and
20 deletions.
There are no files selected for viewing
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
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
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,63 @@ | ||
import PictureSelector from "alchemy_admin/picture_selector" | ||
|
||
describe("PictureSelector", () => { | ||
beforeEach(() => { | ||
document.body.innerHTML = ` | ||
<div class="toolbar_buttons"> | ||
<a id="select_all_pictures"></a> | ||
</div> | ||
<div class="selected_item_tools hidden"></div> | ||
<div id="picture_archive"> | ||
<div class="picture_thumbnail"> | ||
<span class="picture_tool select"> | ||
<input type="checkbox" name="picture_ids[]" id="checkbox_1" value="1"> | ||
</span> | ||
</div> | ||
<div class="picture_thumbnail"> | ||
<span class="picture_tool select"> | ||
<input type="checkbox" name="picture_ids[]" id="checkbox_2" value="1"> | ||
</span> | ||
</div> | ||
</div> | ||
` | ||
|
||
PictureSelector() | ||
}) | ||
|
||
it("selects/unselects all images and toggles selection toolbar visibility", () => { | ||
const selectAllButton = document.querySelector("#select_all_pictures") | ||
const checkboxOne = document.querySelector("#checkbox_1") | ||
const checkboxTwo = document.querySelector("#checkbox_2") | ||
const selectionToolbar = document.querySelector(".selected_item_tools") | ||
|
||
selectAllButton.click() | ||
|
||
expect(selectAllButton.classList.contains("active")).toBeTruthy() | ||
expect(selectionToolbar.classList.contains("hidden")).toBeFalsy() | ||
expect(checkboxOne.checked).toBeTruthy() | ||
expect(checkboxTwo.checked).toBeTruthy() | ||
|
||
selectAllButton.click() | ||
|
||
expect(selectAllButton.classList.contains("active")).toBeFalsy() | ||
expect(selectionToolbar.classList.contains("hidden")).toBeTruthy() | ||
expect(checkboxOne.checked).toBeFalsy() | ||
expect(checkboxTwo.checked).toBeFalsy() | ||
}) | ||
|
||
it("toggles selection toolbar visibility when one image is selected/unselected", () => { | ||
const selectionToolbar = document.querySelector(".selected_item_tools") | ||
const checkboxParent = document.querySelector(".picture_tool") | ||
const checkbox = document.querySelector("#checkbox_1") | ||
|
||
checkbox.click() | ||
|
||
expect(selectionToolbar.classList.contains("hidden")).toBeFalsy() | ||
expect(checkboxParent.classList.contains("visible")).toBeTruthy() | ||
|
||
checkbox.click() | ||
|
||
expect(selectionToolbar.classList.contains("hidden")).toBeTruthy() | ||
expect(checkboxParent.classList.contains("visible")).toBeFalsy() | ||
}) | ||
}) |