Skip to content

Commit

Permalink
chore: cleanup Cypress tests (#9877)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnaydenow authored Sep 16, 2024
1 parent 371c547 commit 85661f7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 48 deletions.
69 changes: 23 additions & 46 deletions packages/main/cypress/specs/base/AriaLabelHelper.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ describe("AriaLabelHelper", () => {
cy.get("#myInput")
.shadow()
.find("input")
.invoke("attr", "aria-label")
.should("eq", "Desc1 Desc2 Desc3 Desc4");
.should("have.attr", "aria-label", "Desc1 Desc2 Desc3 Desc4");

// act
cy.get("#lblDesc2")
Expand All @@ -30,8 +29,7 @@ describe("AriaLabelHelper", () => {
cy.get("#myInput")
.shadow()
.find("input")
.invoke("attr", "aria-label")
.should("eq", "Desc1 Desc4");
.should("have.attr", "aria-label", "Desc1 Desc4");
});

it("Input accessibleNameRef Tests", () => {
Expand All @@ -46,8 +44,7 @@ describe("AriaLabelHelper", () => {
cy.get("#inputEnterName")
.shadow()
.find("input")
.invoke("attr", "aria-label")
.should("eq", "FirstDesc ThirdDesc");
.should("have.attr", "aria-label", "FirstDesc ThirdDesc");

// act - update text of referenced label
cy.get("#lblEnterName1")
Expand All @@ -59,8 +56,7 @@ describe("AriaLabelHelper", () => {
cy.get("#inputEnterName")
.shadow()
.find("input")
.invoke("attr", "aria-label")
.should("eq", "First Label Desc ThirdDesc");
.should("have.attr", "aria-label", "First Label Desc ThirdDesc");

// act - update accessible-name-ref
cy.get("#inputEnterName")
Expand All @@ -70,8 +66,7 @@ describe("AriaLabelHelper", () => {
cy.get("#inputEnterName")
.shadow()
.find("input")
.invoke("attr", "aria-label")
.should("eq", "ThirdDesc First Label Desc");
.should("have.attr", "aria-label", "ThirdDesc First Label Desc");

// act - update accessible-name-ref
cy.get("#inputEnterName")
Expand All @@ -81,8 +76,7 @@ describe("AriaLabelHelper", () => {
cy.get("#inputEnterName")
.shadow()
.find("input")
.invoke("attr", "aria-label")
.should("eq", "SecondDesc");
.should("have.attr", "aria-label", "SecondDesc");
});

it("Input accessibleName and accessibleNameRef Tests", () => {
Expand All @@ -104,8 +98,7 @@ describe("AriaLabelHelper", () => {

// assert
cy.get("@input")
.invoke("attr", "aria-label")
.should("eq", INITIAL_ACCESSIBLE_NAME);
.should("have.attr", "aria-label", INITIAL_ACCESSIBLE_NAME);

cy.get("#inputEnterDesc")
.invoke("attr", "accessible-name", UPDATED_ACCESSIBLE_NAME);
Expand All @@ -130,44 +123,39 @@ describe("AriaLabelHelper", () => {

// assert - the text of the elment labelled with accessible-name-ref is used
cy.get("@input")
.invoke("attr", "aria-label")
.should("eq", ACCESSIBLE_NAME_REF_TEXT);
.should("have.attr", "aria-label", ACCESSIBLE_NAME_REF_TEXT);

// act - add acccessible-name once again
cy.get("#inputEnterDesc")
.invoke("attr", "accessible-name", INITIAL_ACCESSIBLE_NAME);

// assert - the text of the elment labelled with accessible-name-ref is still used
cy.get("@input")
.invoke("attr", "aria-label")
.should("eq", ACCESSIBLE_NAME_REF_TEXT);
.should("have.attr", "aria-label", ACCESSIBLE_NAME_REF_TEXT);

// act - remove acccessible-name-ref
cy.get("#inputEnterDesc")
.invoke("removeAttr", "accessible-name-ref");

// assert - after acccessible-name-ref is removed, fallbacks to use acccessible-name
cy.get("@input")
.invoke("attr", "aria-label")
.should("eq", INITIAL_ACCESSIBLE_NAME);
.should("have.attr", "aria-label", INITIAL_ACCESSIBLE_NAME);

// act - remove acccessible-name
cy.get("#inputEnterDesc")
.invoke("removeAttr", "accessible-name");

// assert - aria-label fallbacks to use the label's for, pointing to this input
cy.get("@input")
.invoke("attr", "aria-label")
.should("eq", "Label for inputEnterDesc");
.should("have.attr", "aria-label", "Label for inputEnterDesc");

// act - remove ui5-label's for
cy.get("#lblEnterDesc1")
.invoke("removeAttr", "for");

// assert - aria-label is undefined
cy.get("@input")
.invoke("attr", "aria-label")
.should("eq", undefined);
.should("not.have.attr", "aria-label");
});

it("Three inputs with same label accessibleNameRef Tests", () => {
Expand Down Expand Up @@ -198,16 +186,13 @@ describe("AriaLabelHelper", () => {

// assert
cy.get("@input1")
.invoke("attr", "aria-label")
.should("eq", LBL_TEXT_CONTENT);
.should("have.attr", "aria-label", LBL_TEXT_CONTENT);

cy.get("@input2")
.invoke("attr", "aria-label")
.should("eq", LBL_TEXT_CONTENT);
.should("have.attr", "aria-label", LBL_TEXT_CONTENT);

cy.get("@input3")
.invoke("attr", "aria-label")
.should("eq", LBL_TEXT_CONTENT);
.should("have.attr", "aria-label", LBL_TEXT_CONTENT);

// act

Expand All @@ -218,43 +203,37 @@ describe("AriaLabelHelper", () => {

// assert
cy.get("@input1")
.invoke("attr", "aria-label")
.should("eq", LBL_TEXT_CONTENT_UPDATED);
.should("have.attr", "aria-label", LBL_TEXT_CONTENT_UPDATED);

cy.get("@input2")
.invoke("attr", "aria-label")
.should("eq", LBL_TEXT_CONTENT_UPDATED);
.should("have.attr", "aria-label", LBL_TEXT_CONTENT_UPDATED);

cy.get("@input3")
.invoke("attr", "aria-label")
.should("eq", LBL_TEXT_CONTENT_UPDATED);
.should("have.attr", "aria-label", LBL_TEXT_CONTENT_UPDATED);

// act - remove "for" attribute
cy.get("#lblTestDesc")
.invoke("removeAttr", "for");

// assert - aria-label is undefined
cy.get("@input1")
.invoke("attr", "aria-label")
.should("eq", undefined);
.should("not.have.attr", "aria-label");

// act - remove accessible-name-ref
cy.get("#testInput2")
.invoke("removeAttr", "accessible-name-ref");

// assert - aria-label is the existing accessible-name
cy.get("@input2")
.invoke("attr", "aria-label")
.should("eq", "Hello");
.should("have.attr", "aria-label", "Hello");

// act - remove accessible-name-ref
cy.get("#testInput3")
.invoke("removeAttr", "accessible-name-ref");

// assert - shouldn't be any aria-label
cy.get("@input3")
.invoke("attr", "aria-label")
.should("eq", undefined);
.should("not.have.attr", "aria-label");
});

it("Tests generic html elements with for attribute", () => {
Expand All @@ -274,8 +253,7 @@ describe("AriaLabelHelper", () => {

// assert
cy.get("@input")
.invoke("attr", "aria-label")
.should("eq", "Desc1 Desc2 Desc3 Desc4 Desc5");
.should("have.attr", "aria-label", "Desc1 Desc2 Desc3 Desc4 Desc5");

// act
cy.get("#elId1")
Expand All @@ -299,7 +277,6 @@ describe("AriaLabelHelper", () => {

// assert
cy.get("@input")
.invoke("attr", "aria-label")
.should("eq", "Desc1X Desc4X");
.should("have.attr", "aria-label", "Desc1X Desc4X");
});
});
7 changes: 5 additions & 2 deletions packages/main/cypress/specs/base/IconCollection.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { html } from "lit";
import "../../../src/Assets.js";
import "../../../src/Icon.js";

setTheme("sap_fiori_3_dark");

describe("Icon collection", () => {
before(() => {
cy.wrap({ setTheme })
.invoke("setTheme", "sap_fiori_3_dark");
});

it("tests the icon collection in built-in themes", () => {
cy.mount(html`<ui5-icon name="home"></ui5-icon>`);

Expand Down

0 comments on commit 85661f7

Please sign in to comment.