Skip to content

Commit 18f7fa7

Browse files
authored
chore: wait for focus DOM refs of UI5 elements before interaction (#11834)
1 parent 951aa44 commit 18f7fa7

File tree

3 files changed

+38
-31
lines changed

3 files changed

+38
-31
lines changed

packages/cypress-internal/src/commands.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ import "./helpers.js"
77
const realEventCmdCallback = (originalFn: any, element: any, ...args: any) => {
88
cy.get(element)
99
.should($el => {
10-
if ($el[0].tagName.includes("-") && $el[0].shadowRoot) {
11-
expect($el[0].shadowRoot.hasChildNodes(), "Custom elements with shadow DOM have content in their shadow DOM").to.be.true;
10+
const el = $el[0];
11+
12+
const isCustom = el.tagName.includes("-");
13+
const isUI5Element = el.isUI5Element;
14+
const isVisible = !Cypress.dom.isHidden(el);
15+
const domRef = typeof el.getDomRef === "function" && el.getDomRef();
16+
17+
if (isCustom && isUI5Element) {
18+
expect(domRef, "DOM Reference exists").to.exist;
19+
expect(isVisible, "Be visible").to.be.true;
1220
}
1321
})
14-
.and("be.visible")
1522
.then(() => {
1623
return originalFn(element, ...args)
1724
});

packages/fiori/cypress/specs/SideNavigationWithGroups.cy.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("Component Behavior", () => {
2929
.should("not.exist");
3030
});
3131

32-
it("Tests that visualization is correct when two groups are next to each other", async () => {
32+
it("Tests that visualization is correct when two groups are next to each other", () => {
3333
cy.mount(
3434
<SideNavigation id="sn1" collapsed={false}>
3535
<SideNavigationGroup id="group1" text="Group 1">
@@ -42,9 +42,9 @@ describe("Component Behavior", () => {
4242
<SideNavigationGroup id="group3" text="Group 3">
4343
<SideNavigationItem text="Item 3.1" icon="locate-me"></SideNavigationItem>
4444
</SideNavigationGroup>
45-
</SideNavigation>
45+
</SideNavigation>
4646
);
47-
47+
4848
cy.get("#group2")
4949
.should("have.prop", "belowGroup", true);
5050

@@ -55,7 +55,7 @@ describe("Component Behavior", () => {
5555

5656
cy.get("#group3")
5757
.should("have.prop", "belowGroup", false);
58-
58+
5959
cy.get("#group3")
6060
.shadow()
6161
.find(".ui5-sn-item-separator").eq(0)
@@ -95,7 +95,7 @@ describe("Component Behavior", () => {
9595
.realClick();
9696
cy.get("#group1").should("have.prop", "expanded", true);
9797
});
98-
98+
9999
it("Tests expanding of groups with ArrowRight", () => {
100100
cy.mount(
101101
<SideNavigation id="sn">
@@ -186,11 +186,11 @@ describe("Component Behavior", () => {
186186
<SideNavigation id="sn">
187187
<SideNavigationItem id="focusStart" text="focus start"></SideNavigationItem>
188188
<SideNavigationGroup id="group1" text="Group">
189-
<SideNavigationItem text="Home 1"
190-
icon="home"
191-
href="#home"
192-
title="Home tooltip" />
193-
</SideNavigationGroup>
189+
<SideNavigationItem text="Home 1"
190+
icon="home"
191+
href="#home"
192+
title="Home tooltip" />
193+
</SideNavigationGroup>
194194
</SideNavigation>
195195
);
196196

@@ -206,11 +206,11 @@ describe("Component Behavior", () => {
206206
<SideNavigation id="sn">
207207
<SideNavigationItem id="focusStart" text="focus start"></SideNavigationItem>
208208
<SideNavigationGroup id="group1" expanded text="Group">
209-
<SideNavigationItem text="Home 1"
210-
icon="home"
211-
href="#home"
212-
title="Home tooltip" />
213-
</SideNavigationGroup>
209+
<SideNavigationItem text="Home 1"
210+
icon="home"
211+
href="#home"
212+
title="Home tooltip" />
213+
</SideNavigationGroup>
214214
</SideNavigation>
215215
);
216216

packages/main/cypress/specs/Toast.cy.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ describe("Toast general interaction", () => {
3838
.invoke("prop", "open", true);
3939

4040
cy.get("[ui5-toast]")
41-
.should("be.visible")
42-
.and("have.attr", "placement", "MiddleEnd")
43-
.should(($el) => {
44-
const rect = $el[0].getBoundingClientRect();
41+
.should("be.visible")
42+
.and("have.attr", "placement", "MiddleEnd")
43+
.should(($el) => {
44+
const rect = $el[0].getBoundingClientRect();
4545

46-
expect(rect.top + rect.height / 2).to.be.closeTo(window.innerHeight / 2, 20);
47-
expect(window.innerWidth - (rect.left + rect.width)).to.be.lessThan(50);
48-
});
46+
expect(rect.top + rect.height / 2).to.be.closeTo(window.innerHeight / 2, 20);
47+
expect(window.innerWidth - (rect.left + rect.width)).to.be.lessThan(50);
48+
});
4949
});
5050

5151
it("tests shadow content div role", () => {
@@ -102,7 +102,7 @@ describe("Toast general interaction", () => {
102102
.should("have.attr", "open");
103103

104104
//waiting the duration of the toast
105-
cy.get("[ui5-toast]", {timeout: 3000});
105+
cy.get("[ui5-toast]", { timeout: 3000 });
106106

107107
cy.get("[ui5-toast]")
108108
.should("not.be.visible");
@@ -128,7 +128,7 @@ describe("Keyboard handling", () => {
128128
);
129129
});
130130

131-
it("toast should be closed on pressing esc key", async () => {
131+
it("toast should be closed on pressing esc key", () => {
132132
cy.get("[ui5-button]")
133133
.realClick();
134134

@@ -150,13 +150,13 @@ describe("Keyboard handling", () => {
150150
.realPress("Escape");
151151

152152
// //waiting the duration of the toast
153-
cy.get("[ui5-toast]", {timeout: 3000});
153+
cy.get("[ui5-toast]", { timeout: 3000 });
154154

155155
cy.get("[ui5-toast]")
156156
.should("not.have.attr", "open");
157157
});
158158

159-
it("Opens two toasts in a row and focuses the last open", async () => {
159+
it("Opens two toasts in a row and focuses the last open", () => {
160160
cy.mount(
161161
<>
162162
<Button id="wcBtnShowToastTS">Show Toast TS</Button>
@@ -176,7 +176,7 @@ describe("Keyboard handling", () => {
176176
cy.realPress(["Control", "Shift", "m"]);
177177

178178
//waiting the duration of the toast
179-
cy.get("[ui5-toast]", {timeout: 3000});
179+
cy.get("[ui5-toast]", { timeout: 3000 });
180180

181181
cy.get("#wcToastTC")
182182
.should("be.visible");
@@ -287,7 +287,7 @@ describe("Toast - test popover API", () => {
287287
cy.get("#toast")
288288
.invoke("prop", "open", true);
289289

290-
cy.get("#toast", {timeout: 500});
290+
cy.get("#toast", { timeout: 500 });
291291

292292
cy.get("@toastClose")
293293
.should("be.calledOnce");

0 commit comments

Comments
 (0)