Skip to content

Commit

Permalink
say "deselect all" in menu when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
macfarlandian committed Nov 10, 2020
1 parent 7f0851c commit 1df087e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion public-dashboard-client/src/controls/CohortSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ function CustomSelect({
selected,
setSelected,
}) {
const selectAllLabel =
selected.length === optionsFromData.length ? "Deselect all" : "Select all";
const visibleOptions = [
{ id: SELECT_ALL_ID, label: "Select all" },
{ id: SELECT_ALL_ID, label: selectAllLabel },
...optionsFromData,
];

Expand Down
6 changes: 6 additions & 0 deletions public-dashboard-client/src/controls/CohortSelect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ test("supports select-all", () => {
const { getByRole } = openMenu();
const selectAll = getByRole("option", { name: /select all/i });

expect(selectAll).toHaveTextContent(/deselect all/i);
act(() => userEvent.click(selectAll));

// de-selects all
Expand All @@ -225,6 +226,7 @@ test("supports select-all", () => {
"false"
);
});
expect(selectAll).toHaveTextContent(/(?<!de)select all/i);

// click again to select all
act(() => userEvent.click(selectAll));
Expand All @@ -234,6 +236,7 @@ test("supports select-all", () => {
"true"
);
});
expect(selectAll).toHaveTextContent(/deselect all/i);

// now de-select some manually and try again
testOptions.slice(2, 6).forEach((opt) => {
Expand All @@ -244,6 +247,8 @@ test("supports select-all", () => {
);
});

expect(selectAll).toHaveTextContent(/(?<!de)select all/i);

act(() => userEvent.click(selectAll));
// everything is selected again
testOptions.forEach((opt) => {
Expand All @@ -252,4 +257,5 @@ test("supports select-all", () => {
"true"
);
});
expect(selectAll).toHaveTextContent(/deselect all/i);
});

0 comments on commit 1df087e

Please sign in to comment.