Skip to content

Commit 0d937da

Browse files
committed
test: Add tests for the new destinations parameter
1 parent 03d9093 commit 0d937da

19 files changed

Lines changed: 684 additions & 10 deletions

File tree

resources/template-card/test/App.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ sap.ui.define(["sap/ui/integration/Host"], async (Host) => {
88
const applyChangesBtn = document.getElementById("applyChangesBtn");
99
const resetBtn = document.getElementById("resetBtn");
1010
const destinations = {
11-
Northwind: "https://services.odata.org/V4/Northwind/Northwind.svc/"
11+
<%_ if (destinations && destinations.length > 0) { -%>
12+
<%_ destinations.forEach(function(destination, index) { -%>
13+
"<%= destination.name %>": "<%= destination.defaultUrl %>"<%= index < destinations.length - 1 ? ',' : '' %>
14+
<%_ }); -%>
15+
<%_ } -%>
1216
};
1317
const host = new Host({
14-
resolveDestination: function(sDestinationName) {
15-
if (destinations[sDestinationName]) {
16-
return destinations[sDestinationName];
18+
resolveDestination: function(destinationName) {
19+
if (destinations[destinationName]) {
20+
return destinations[destinationName];
1721
}
1822

19-
return Promise.reject("Destination " + sDestinationName + " not found!");
23+
return Promise.reject("Destination " + destinationName + " not found!");
2024
},
2125
actions: [
2226
{

test/expected/create_integration_card/common/test/App.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ sap.ui.define(["sap/ui/integration/Host"], async (Host) => {
88
const applyChangesBtn = document.getElementById("applyChangesBtn");
99
const resetBtn = document.getElementById("resetBtn");
1010
const destinations = {
11-
Northwind: "https://services.odata.org/V4/Northwind/Northwind.svc/"
1211
};
1312
const host = new Host({
14-
resolveDestination: function(sDestinationName) {
15-
if (destinations[sDestinationName]) {
16-
return destinations[sDestinationName];
13+
resolveDestination: function(destinationName) {
14+
if (destinations[destinationName]) {
15+
return destinations[destinationName];
1716
}
1817

19-
return Promise.reject("Destination " + sDestinationName + " not found!");
18+
return Promise.reject("Destination " + destinationName + " not found!");
2019
},
2120
actions: [
2221
{
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
sap.ui.define([
2+
"sap/ui/integration/Designtime",
3+
],
4+
function (
5+
Designtime
6+
) {
7+
"use strict";
8+
9+
return function () {
10+
return new Designtime({
11+
form: {
12+
items: {
13+
groupheader1: {
14+
label: "General Settings",
15+
type: "group",
16+
},
17+
separator1: {
18+
type: "separator",
19+
},
20+
title: {
21+
manifestpath: "/sap.card/header/title",
22+
type: "string",
23+
translatable: true,
24+
label: "Card Title",
25+
cols: 1,
26+
allowDynamicValues: true,
27+
},
28+
subtitle: {
29+
manifestpath: "/sap.card/header/subtitle",
30+
type: "string",
31+
translatable: true,
32+
label: "Card Subtitle",
33+
cols: 1,
34+
allowDynamicValues: true,
35+
},
36+
},
37+
},
38+
preview: {
39+
modes: "None",
40+
},
41+
});
42+
};
43+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
title=Sample Integration Card
2+
subtitle=Subtitle
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"_version": "1.78.0",
3+
"sap.app": {
4+
"id": "sample.integration.card",
5+
"type": "card",
6+
"title": "Sample Integration Card",
7+
"applicationVersion": {
8+
"version": "1.0.0"
9+
}
10+
},
11+
"sap.ui": {
12+
"technology": "UI5",
13+
"deviceTypes": {
14+
"desktop": true,
15+
"tablet": true,
16+
"phone": true
17+
}
18+
},
19+
"sap.card": {
20+
"type": "List",
21+
"configuration": {
22+
"destinations": {
23+
"northwind": {
24+
"name": "northwind",
25+
"defaultUrl": "https://services.odata.org/V4/Northwind/Northwind.svc/"
26+
},
27+
"myapi": {
28+
"name": "myapi",
29+
"defaultUrl": "https://api.example.com/v1/"
30+
}
31+
},
32+
"editor": "./dt/Configuration"
33+
},
34+
"data": {
35+
"json": {
36+
"items": [
37+
{
38+
"title": "Item 1",
39+
"description": "Description for Item 1"
40+
},
41+
{
42+
"title": "Item 2",
43+
"description": "Description for Item 2"
44+
}
45+
]
46+
}
47+
},
48+
"header": {
49+
"title": "{i18n>title}",
50+
"subtitle": "{i18n>subtitle}"
51+
},
52+
"content": {
53+
"data": {
54+
"path": "/items"
55+
},
56+
"item": {
57+
"title": "{title}",
58+
"description": "{description}"
59+
}
60+
}
61+
}
62+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "template-card",
3+
"version": "1.0.0",
4+
"description": "A basic template card project",
5+
"scripts": {
6+
"start": "http-server ./ -c-1 -o test/index.html",
7+
"test": "echo \"No tests specified\" && exit 0"
8+
},
9+
"devDependencies": {
10+
"http-server": "^14.1.1"
11+
}
12+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
sap.ui.define(["sap/ui/integration/Host"], async (Host) => {
2+
"use strict";
3+
await customElements.whenDefined("ui-integration-card");
4+
await customElements.whenDefined("ui-integration-card-editor");
5+
6+
const editor = document.getElementById("editor");
7+
const card = document.getElementById("card");
8+
const applyChangesBtn = document.getElementById("applyChangesBtn");
9+
const resetBtn = document.getElementById("resetBtn");
10+
const destinations = {
11+
"northwind": "https://services.odata.org/V4/Northwind/Northwind.svc/",
12+
"myapi": "https://api.example.com/v1/"
13+
};
14+
const host = new Host({
15+
resolveDestination: function(destinationName) {
16+
if (destinations[destinationName]) {
17+
return destinations[destinationName];
18+
}
19+
20+
return Promise.reject("Destination " + destinationName + " not found!");
21+
},
22+
actions: [
23+
{
24+
type: "Custom",
25+
text: "Configure",
26+
icon: "sap-icon://action-settings",
27+
action: () => {
28+
document.getElementById("editorSection").classList.remove("hidden");
29+
}
30+
}
31+
]
32+
});
33+
34+
// Called by the Configuration Editor to show a list of available destinations
35+
host.getDestinations = function() {
36+
return Promise.resolve(Object.entries(destinations).map(([name, url]) => {
37+
return {
38+
name,
39+
};
40+
}));
41+
};
42+
43+
card.host = host.getId();
44+
card.manifest = "../card/manifest.json";
45+
46+
editor.host = host.getId();
47+
editor.card = "card";
48+
49+
let initialSettings;
50+
51+
// UI5 CustomElementBase doesn't expose the "ready" event, so use timeout
52+
setTimeout(() => {
53+
initialSettings = editor.getCurrentSettings();
54+
}, 3000);
55+
56+
applyChangesBtn.addEventListener("click", () => {
57+
card.manifestChanges = [editor.getCurrentSettings()];
58+
});
59+
60+
resetBtn.addEventListener("click", () => {
61+
card.manifestChanges = [initialSettings];
62+
});
63+
});
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
body {
2+
margin: 2rem;
3+
}
4+
5+
.container {
6+
display: flex;
7+
gap: 2rem;
8+
align-items: flex-start;
9+
flex-wrap: wrap;
10+
}
11+
12+
.card-section {
13+
flex: 1;
14+
min-width: 300px;
15+
max-width: 600px;
16+
display: block;
17+
flex-direction: column;
18+
}
19+
20+
.editor-section {
21+
--sapUiIntegrationEditorFormHeight: auto;
22+
}
23+
24+
.button-container {
25+
display: flex;
26+
justify-content: flex-end;
27+
gap: 0.5rem;
28+
margin-top: 1rem;
29+
}
30+
31+
.config-button {
32+
padding: 0.25rem 0.5rem;
33+
border: none;
34+
border-radius: 0.25rem;
35+
cursor: pointer;
36+
font-size: 14px;
37+
transition: background-color 0.2s ease;
38+
}
39+
40+
.config-button.primary {
41+
background-color: #0070f3;
42+
color: white;
43+
}
44+
45+
.config-button.primary:hover {
46+
background-color: #0051cc;
47+
}
48+
49+
.config-button.secondary {
50+
background-color: #f5f5f5;
51+
color: #333;
52+
border: 1px solid #ddd;
53+
}
54+
55+
.config-button.secondary:hover {
56+
background-color: #e5e5e5;
57+
}
58+
59+
.hidden {
60+
display: none;
61+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Integration Card Preview</title>
8+
<link rel="stylesheet" href="./index.css">
9+
<script
10+
src="https://ui5.sap.com/resources/sap-ui-integration.js"
11+
id="sap-ui-bootstrap"
12+
data-sap-ui-compat-version="edge"
13+
data-sap-ui-resource-roots='{"preview": "./"}'
14+
data-sap-ui-on-init="module:preview/App"
15+
data-sap-ui-theme="sap_horizon">
16+
</script>
17+
<script src="https://ui5.sap.com/resources/sap-ui-integration-card-editor.js"></script>
18+
</head>
19+
20+
<body>
21+
<h1>Preview</h1>
22+
<div class="container">
23+
<div class="card-section">
24+
<h2>Integration Card</h2>
25+
<ui-integration-card
26+
id="card"
27+
width="300px"
28+
height="400px">
29+
</ui-integration-card>
30+
</div>
31+
<div id="editorSection"
32+
class="card-section hidden">
33+
<h2>Configuration Editor</h2>
34+
<ui-integration-card-editor
35+
id="editor">
36+
</ui-integration-card-editor>
37+
<div class="button-container">
38+
<button id="applyChangesBtn" class="config-button primary">Apply Changes</button>
39+
<button id="resetBtn" class="config-button secondary">Reset</button>
40+
</div>
41+
</div>
42+
</div>
43+
</body>
44+
45+
</html>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
sap.ui.define([
2+
"sap/ui/integration/Designtime",
3+
],
4+
function (
5+
Designtime
6+
) {
7+
"use strict";
8+
9+
return function () {
10+
return new Designtime({
11+
form: {
12+
items: {
13+
groupheader1: {
14+
label: "General Settings",
15+
type: "group",
16+
},
17+
separator1: {
18+
type: "separator",
19+
},
20+
title: {
21+
manifestpath: "/sap.card/header/title",
22+
type: "string",
23+
translatable: true,
24+
label: "Card Title",
25+
cols: 1,
26+
allowDynamicValues: true,
27+
},
28+
subtitle: {
29+
manifestpath: "/sap.card/header/subtitle",
30+
type: "string",
31+
translatable: true,
32+
label: "Card Subtitle",
33+
cols: 1,
34+
allowDynamicValues: true,
35+
},
36+
},
37+
},
38+
preview: {
39+
modes: "None",
40+
},
41+
});
42+
};
43+
});

0 commit comments

Comments
 (0)