diff --git a/packages/fiori/cypress/specs/ShellBar.cy.tsx b/packages/fiori/cypress/specs/ShellBar.cy.tsx index eb762a0cd612..1fc68d9c9353 100644 --- a/packages/fiori/cypress/specs/ShellBar.cy.tsx +++ b/packages/fiori/cypress/specs/ShellBar.cy.tsx @@ -504,9 +504,9 @@ describe("Slots", () => { cy.mount( ); - + cy.get("#shellbar").as("shellbar"); - + // Add search field after a timeout (simulating real-world scenario) cy.get("@shellbar").then(shellbar => { setTimeout(() => { @@ -516,15 +516,15 @@ describe("Slots", () => { shellbar.get(0).appendChild(searchField); }, 100); }); - + // Wait for the search field to be added cy.get("#delayed-search", { timeout: 1000 }).should("exist"); - + // Search should now be visible and collapsed cy.get("#shellbar [slot='searchField']") .should("exist") .should("have.prop", "collapsed", true); - + // click the searchField to expand it cy.get("#shellbar [slot='searchField']") .click() @@ -611,6 +611,385 @@ describe("Events", () => { cy.get("@logoClickSmall") .should("have.been.calledOnce"); }); + + describe("Big screen", () => { + beforeEach(() => { + cy.viewport(1920, 1680); + }); + + it("tests opening of menu", () => { + cy.mount( + + Menu Item 1 + Menu Item 2 + + + ); + + cy.get("[ui5-shellbar]") + .shadow() + .find(".ui5-shellbar-menu-button") + .click(); + + cy.get("[ui5-shellbar]") + .shadow() + .find(".ui5-shellbar-menu-popover") + .should("have.prop", "open", true); + }); + + it("tests notificationsClick event", () => { + cy.mount( +
+ + + + +
+ ); + + cy.get("[ui5-shellbar]").then($shellbar => { + const shellbar = $shellbar[0]; + shellbar.addEventListener("ui5-notifications-click", () => { + (document.getElementById("press-input") as HTMLInputElement).value = "Notifications"; + }); + }); + + cy.get("[ui5-shellbar]") + .shadow() + .find(".ui5-shellbar-bell-button") + .click(); + + cy.get("#press-input").should("have.value", "Notifications"); + }); + + it("tests profileClick event", () => { + cy.mount( +
+ + + + + + + +
+ ); + + cy.get("[ui5-shellbar]").then($shellbar => { + const shellbar = $shellbar[0]; + shellbar.addEventListener("ui5-profile-click", () => { + (document.getElementById("press-input") as HTMLInputElement).value = "Profile"; + }); + }); + + cy.get("[ui5-shellbar]") + .shadow() + .find("[data-profile-btn]") + .click(); + + cy.get("#press-input").should("have.value", "Profile"); + }); + + it("tests productSwitchClick event", () => { + cy.mount( +
+ + + + +
+ ); + + cy.get("[ui5-shellbar]").then($shellbar => { + const shellbar = $shellbar[0]; + shellbar.addEventListener("ui5-product-switch-click", () => { + (document.getElementById("press-input") as HTMLInputElement).value = "Product Switch"; + }); + }); + + cy.get("[ui5-shellbar]") + .shadow() + .find(".ui5-shellbar-button-product-switch") + .click(); + + cy.get("#press-input").should("have.value", "Product Switch"); + }); + + it("tests logoClick event", () => { + cy.mount( +
+ + + + +
+ ); + + cy.get("[ui5-shellbar]").then($shellbar => { + const shellbar = $shellbar[0]; + shellbar.addEventListener("ui5-logo-click", () => { + (document.getElementById("press-input") as HTMLInputElement).value = "Logo"; + }); + }); + + cy.get("[ui5-shellbar]") + .shadow() + .find(".ui5-shellbar-logo") + .click(); + + cy.get("#press-input").should("have.value", "Logo"); + }); + + it("tests search-button-click event", () => { + cy.viewport(870, 1680); + + cy.mount( +
+ + + + + +
+ ); + + cy.get("[ui5-shellbar]").then($shellbar => { + const shellbar = $shellbar[0]; + shellbar.addEventListener("ui5-search-button-click", (e) => { + e.preventDefault(); + (document.getElementById("press-input") as HTMLInputElement).value = "Search clicked"; + }); + }); + + cy.get("[ui5-shellbar]").should("have.prop", "showSearchField", false); + + cy.get("[ui5-shellbar]") + .shadow() + .find(".ui5-shellbar-search-button") + .click(); + + cy.get("[ui5-shellbar]").should("have.prop", "showSearchField", false); + + cy.get("#press-input").should("have.value", "Search clicked"); + }); + + it("tests menuItemClick event", () => { + cy.mount( +
+ + + + Application 1 + Application 2 + + +
+ ); + + cy.get("[ui5-li][slot='menuItems']").each(($item) => { + const item = $item[0]; + item.addEventListener("click", () => { + (document.getElementById("press-input") as HTMLInputElement).value = item.textContent.trim(); + (document.getElementById("press-data") as HTMLInputElement).value = item.getAttribute("data-key") || ""; + }); + }); + + cy.get("[ui5-shellbar]") + .shadow() + .find(".ui5-shellbar-menu-button") + .click(); + + cy.get("[ui5-li][slot='menuItems']").first().click(); + + cy.get("#press-input").should("have.value", "Application 1"); + cy.get("#press-data").should("have.value", "key1"); + + cy.get("#press-input").invoke("prop", "value", ""); + cy.get("#press-data").invoke("prop", "value", ""); + + cy.get("[ui5-shellbar]") + .shadow() + .find(".ui5-shellbar-menu-button") + .click(); + + cy.get("[ui5-li][slot='menuItems']").eq(1).click(); + + cy.get("#press-input").should("have.value", "Application 2"); + cy.get("#press-data").should("have.value", "key2"); + }); + + it("tests if searchfield toggles when altering the showSearchField property", () => { + cy.mount( + + + + + ); + + cy.get("[ui5-shellbar]").should("have.prop", "showSearchField", true); + + cy.get("[ui5-shellbar]").invoke("prop", "showSearchField", false); + + cy.get("[ui5-shellbar]").should("have.prop", "showSearchField", false); + + cy.get("[ui5-shellbar]").invoke("prop", "showSearchField", true); + cy.get("[ui5-shellbar]").should("have.prop", "showSearchField", true); + }); + }); + + describe("Small screen", () => { + beforeEach(() => { + cy.viewport(510, 1680); + }); + + it("tests logoClick event", () => { + cy.mount( +
+ + + + +
+ ); + + const title = "SAPLabsBulgaria"; + + cy.get("[ui5-shellbar]").then($shellbar => { + const shellbar = $shellbar[0]; + shellbar.addEventListener("ui5-logo-click", () => { + (document.getElementById("press-input2") as HTMLInputElement).value = title; + }); + }); + + cy.get("[ui5-shellbar]") + .shadow() + .find(".ui5-shellbar-logo") + .click(); + + cy.get("#press-input2").should("have.value", title); + }); + + it("tests opening of menu", () => { + cy.mount( + + Menu Item 1 + Menu Item 2 + + + ); + + cy.get("[ui5-shellbar]") + .shadow() + .find(".ui5-shellbar-menu-button") + .click(); + + cy.get("[ui5-shellbar]") + .shadow() + .find(".ui5-shellbar-menu-popover") + .should("have.prop", "open", true); + }); + + it("tests profileClick event", () => { + cy.mount( +
+ + + + + + + +
+ ); + + cy.get("[ui5-shellbar]").then($shellbar => { + const shellbar = $shellbar[0]; + shellbar.addEventListener("ui5-profile-click", () => { + (document.getElementById("press-input") as HTMLInputElement).value = "Profile"; + }); + }); + + cy.get("[ui5-shellbar]") + .shadow() + .find("[data-profile-btn]") + .click(); + + cy.get("#press-input").should("have.value", "Profile"); + }); + + it("tests productSwitchClick event", () => { + cy.mount( +
+ + + + +
+ ); + + cy.get("[ui5-shellbar]").then($shellbar => { + const shellbar = $shellbar[0]; + shellbar.addEventListener("ui5-product-switch-click", () => { + (document.getElementById("press-input") as HTMLInputElement).value = "Product Switch"; + }); + }); + + cy.get("[ui5-shellbar]") + .shadow() + .find(".ui5-shellbar-button-product-switch") + .click(); + + cy.get("#press-input").should("have.value", "Product Switch"); + }); + + it("tests preventDefault of click on a button with default behavior prevented", () => { + cy.mount( + + + + + +