Skip to content

Commit 4e0d8fe

Browse files
authored
test: add cypress test of ui5 and ui5webc integration case (#12257)
Adds a new Cypress test, loading SAPUI5 and UI5 Web Components, mixing sap.m.Dialog and ui5-dialog Fixes: #12249
1 parent 798113e commit 4e0d8fe

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import "../../src/features/OpenUI5Support.js";
2+
import Button from "@ui5/webcomponents/dist/Button.js";
3+
import Dialog from "@ui5/webcomponents/dist/Dialog.js";
4+
5+
describe("ui5 and web components integration", () => {
6+
it("should open sap.m.Dialog, then web components dialog from within", () => {
7+
// mount the components
8+
cy.mount(
9+
<div>
10+
<Button id="webc-button">web components button</Button>
11+
<Dialog id="webc-dialog" headerText="web components dialog">
12+
<Button>button inside web components dialog</Button>
13+
</Dialog>
14+
<div id="content"></div>
15+
</div>
16+
);
17+
18+
// inject ui5 configuration
19+
cy.document().then((doc) => {
20+
const configScript = doc.createElement('script');
21+
configScript.setAttribute('data-ui5-config', '');
22+
configScript.type = 'application/json';
23+
configScript.textContent = JSON.stringify({
24+
language: 'EN'
25+
});
26+
doc.head.appendChild(configScript);
27+
});
28+
29+
// define initialization function before loading ui5
30+
cy.window().then((win) => {
31+
(win as any).onOpenUI5Init = function() {
32+
(win as any).sap.ui.require(["sap/m/Button", "sap/m/Dialog"], (Button: any, Dialog: any) => {
33+
// create sap.m.Button that opens sap.m.Dialog
34+
new Button("ui5-button", {
35+
text: "Open sap.m.Dialog",
36+
press: function () {
37+
// create sap.m.Dialog with button to open web components dialog
38+
const dialog = new Dialog({
39+
title: "sap.m.Dialog",
40+
content: [
41+
new Button({
42+
id: "ui5-open-webc-button",
43+
text: "open web components dialog from ui5",
44+
press: function() {
45+
// open the web components dialog
46+
const webcDialog = win.document.getElementById('webc-dialog') as any;
47+
if (webcDialog) {
48+
webcDialog.open = true;
49+
(win as any).webcDialogOpened = true;
50+
}
51+
}
52+
})
53+
],
54+
afterClose: function () {
55+
this.destroy();
56+
}
57+
});
58+
59+
dialog.open();
60+
}
61+
}).placeAt("content");
62+
63+
(win as any).ui5InitComplete = true;
64+
});
65+
};
66+
});
67+
68+
// add ui5 bootstrap
69+
cy.document().then((doc) => {
70+
const ui5Script = doc.createElement('script');
71+
ui5Script.src = 'https://openui5.hana.ondemand.com/resources/sap-ui-core.js';
72+
ui5Script.id = 'sap-ui-bootstrap';
73+
ui5Script.setAttribute('data-sap-ui-libs', 'sap.m');
74+
ui5Script.setAttribute('data-sap-ui-oninit', 'onOpenUI5Init');
75+
doc.head.appendChild(ui5Script);
76+
});
77+
78+
// act: open sap.m.Dialog
79+
cy.get('#ui5-button')
80+
.should('be.visible')
81+
.realClick();
82+
83+
// assert: sap.m.Dialog is open
84+
cy.get('.sapMDialog').should('exist');
85+
cy.get('.sapMDialog.sapMDialogOpen').should('be.visible');
86+
87+
// act: open ui5-dialog
88+
cy.get('#ui5-open-webc-button')
89+
.should('be.visible')
90+
.realClick();
91+
92+
// assert: ui5-dialog is open
93+
cy.get("#webc-dialog").should(($dialog) => {
94+
expect($dialog).to.have.attr("open");
95+
expect($dialog.is(":popover-open")).to.be.true;
96+
expect($dialog.width()).to.not.equal(0);
97+
expect($dialog.height()).to.not.equal(0);
98+
});
99+
});
100+
101+
});

0 commit comments

Comments
 (0)