|
| 1 | +import ShellBar from "../../src/ShellBar.js"; |
| 2 | +import ShellBarItem from "../../src/ShellBarItem.js"; |
| 3 | +import Button from "@ui5/webcomponents/dist/Button.js"; |
| 4 | +import Avatar from "@ui5/webcomponents/dist/Avatar.js"; |
| 5 | +import Input from "@ui5/webcomponents/dist/Input.js"; |
| 6 | + |
| 7 | +describe("ShellBarItem getFocusDomRef", () => { |
| 8 | + it("should return the correct DOM element when item is in the bar", () => { |
| 9 | + cy.mount( |
| 10 | + <ShellBar id="shellbar-test"> |
| 11 | + <ShellBarItem id="item1" icon="accept" text="Item 1" stable-dom-ref="item-1" /> |
| 12 | + </ShellBar> |
| 13 | + ); |
| 14 | + |
| 15 | + cy.get<ShellBarItem>("#item1") |
| 16 | + .then(($item) => { |
| 17 | + const focusRef = $item[0].getFocusDomRef(); |
| 18 | + expect(focusRef).to.be.instanceOf(HTMLElement); |
| 19 | + expect(focusRef).has.attr('ui5-button'); |
| 20 | + expect(focusRef?.getAttribute('data-ui5-stable')).to.equal('item-1'); |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + it("should return the correct DOM element when item is in overflow popover", () => { |
| 25 | + cy.mount( |
| 26 | + <ShellBar id="shellbar-overflow-test" showNotifications showProductSwitch> |
| 27 | + <Button icon="nav-back" slot="startButton" /> |
| 28 | + <ShellBarItem id="overflow-item1" icon="accept" text="Item 1" stable-dom-ref="overflow-1" /> |
| 29 | + <ShellBarItem id="overflow-item2" icon="alert" text="Item 2" stable-dom-ref="overflow-2" /> |
| 30 | + <ShellBarItem id="overflow-item3" icon="attachment" text="Item 3" stable-dom-ref="overflow-3" /> |
| 31 | + <Avatar slot="profile"> |
| 32 | + <img src="https://sdk.openui5.org/test-resources/sap/f/images/Woman_avatar_01.png" /> |
| 33 | + </Avatar> |
| 34 | + <Input placeholder="Search" slot="searchField" /> |
| 35 | + </ShellBar> |
| 36 | + ); |
| 37 | + |
| 38 | + // Force overflow by resizing viewport |
| 39 | + cy.viewport(320, 800); |
| 40 | + |
| 41 | + // Open overflow popover |
| 42 | + cy.get("#shellbar-overflow-test") |
| 43 | + .shadow() |
| 44 | + .find(".ui5-shellbar-overflow-button") |
| 45 | + .should("be.visible") |
| 46 | + .click(); |
| 47 | + |
| 48 | + cy.get("#shellbar-overflow-test") |
| 49 | + .shadow() |
| 50 | + .find(".ui5-shellbar-overflow-popover") |
| 51 | + .should("be.visible"); |
| 52 | + |
| 53 | + // Test when items are in overflow popover |
| 54 | + cy.get<ShellBarItem>("#overflow-item1") |
| 55 | + .then(($item) => { |
| 56 | + const focusRef = $item[0].getFocusDomRef(); |
| 57 | + // When overflowed, should return the list item in the popover |
| 58 | + expect(focusRef?.hasAttribute('ui5-li')); |
| 59 | + expect(focusRef?.getAttribute('data-ui5-stable')).to.equal('overflow-1'); |
| 60 | + }); |
| 61 | + }); |
| 62 | +}); |
0 commit comments