Skip to content

Commit

Permalink
Update multiselect cypress tests to match new multiselect checkbox DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamik10 committed Oct 9, 2023
1 parent 3190b7d commit 4b0f857
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions src/components/multiselect/Multiselect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,61 +20,64 @@ describe("Multiselect", () => {
});

it("Has the all option selected by default", () => {
cy.get("button:visible").should("contain", "All").click();
cy.get("button:visible")
.should("contain", "advancedSearchFilterAllText")
.click();
cy.get("[role=option]")
.contains("All")
.find("[type=checkbox]")
.should("be.checked");
.eq(0)
.should("contain", "advancedSearchFilterAllText")
.and("have.attr", "aria-selected", "true");
});

it("Allows selection of single value", () => {
cy.get("button:visible").click();
cy.get("[role=option]").contains("First item").click();
cy.get("[role=option]")
.contains("First item")
.click()
.find("input[type=checkbox]")
.should("be.checked");
.eq(1)
.should("contain", "First item")
.and("have.attr", "aria-selected", "true");
cy.get("[role=option]")
.contains("All")
.find("[type=checkbox]")
.should("not.be.checked");
.eq(0)
.should("contain", "advancedSearchFilterAllText")
.and("have.attr", "aria-selected", "false");
});

it("Allows selection of multiple values", () => {
cy.get("button:visible").click();
cy.get("[role=option]")
.contains("First item")
.eq(1)
.click()
.find("[type=checkbox]")
.should("be.checked");
.should("contain", "First item")
.and("have.attr", "aria-selected", "true");
cy.get("[role=option]")
.contains("2. item")
.eq(2)
.click()
.find("[type=checkbox]")
.should("be.checked");
.should("contain", "2. item")
.and("have.attr", "aria-selected", "true");
cy.get("[role=option]")
.contains("All")
.find("[type=checkbox]")
.should("not.be.checked");
.eq(0)
.should("contain", "advancedSearchFilterAllText")
.and("have.attr", "aria-selected", "false");
});

it("Selects the all option if all values are selected", () => {
cy.get("button:visible").click();
cy.get("[role=option]").click({ multiple: true });
cy.get("[role=option]")
.contains("All")
.find("[type=checkbox]")
.should("be.checked");
.eq(0)
.should("contain", "advancedSearchFilterAllText")
.and("have.attr", "aria-selected", "true");
});

it("Supports single default value preselected", () => {
cy.visit("/iframe.html?args=&id=components-multiselect--single-selected");
cy.contains("First item");
cy.get("button:visible").click();
cy.get("[role=option]")
.contains("First item")
.find("[type=checkbox]")
.should("be.checked");
.eq(1)
.click()
.should("contain", "First item")
.and("have.attr", "aria-selected", "true");
});

it("Supports multiple default values preselected", () => {
Expand All @@ -83,13 +86,13 @@ describe("Multiselect", () => {
cy.contains("2. item");
cy.get("button:visible").click();
cy.get("[role=option]")
.contains("First item")
.find("[type=checkbox]")
.should("be.checked");
.eq(1)
.should("contain", "First item")
.and("have.attr", "aria-selected", "true");
cy.get("[role=option]")
.contains("2. item")
.find("[type=checkbox]")
.should("be.checked");
.eq(2)
.should("contain", "2. item")
.and("have.attr", "aria-selected", "true");
});
});

Expand Down

0 comments on commit 4b0f857

Please sign in to comment.