From 2d61d9f0a3497fe1695b108abd9af11749a5371d Mon Sep 17 00:00:00 2001 From: Peder Hveem Alsvik Date: Wed, 23 Mar 2022 21:16:51 +0100 Subject: [PATCH 1/3] test: control method returns String[] or empty array --- .../webapp/controller/Main.controller.js | 3 ++ .../ui5-js-app/webapp/mockdata/countries.json | 36 +++++++++++++++++++ .../webapp/test/e2e/prop-array.test.js | 30 ++++++++++++++++ examples/ui5-js-app/webapp/view/Main.view.xml | 3 ++ 4 files changed, 72 insertions(+) create mode 100644 examples/ui5-js-app/webapp/mockdata/countries.json create mode 100644 examples/ui5-js-app/webapp/test/e2e/prop-array.test.js diff --git a/examples/ui5-js-app/webapp/controller/Main.controller.js b/examples/ui5-js-app/webapp/controller/Main.controller.js index 4c074ead..a9b1396a 100644 --- a/examples/ui5-js-app/webapp/controller/Main.controller.js +++ b/examples/ui5-js-app/webapp/controller/Main.controller.js @@ -19,6 +19,9 @@ sap.ui.define( let testModel = new JSONModel(jData) this.getView().setModel(testModel, "testModel") + + let multComboBoxModel = new JSONModel(sap.ui.require.toUrl("test/Sample/mockdata/countries.json")) + this.getView().setModel(multComboBoxModel, "countries") }, navFwd() { diff --git a/examples/ui5-js-app/webapp/mockdata/countries.json b/examples/ui5-js-app/webapp/mockdata/countries.json new file mode 100644 index 00000000..654d5fa9 --- /dev/null +++ b/examples/ui5-js-app/webapp/mockdata/countries.json @@ -0,0 +1,36 @@ +{ + "Countries": [ + { + "key": "CH", + "text": "China" + }, + { + "key": "IN", + "text": "India" + }, + { + "key": "US", + "text": "United States" + }, + { + "key": "ID", + "text": "Indonesia" + }, + { + "key": "PA", + "text": "Pakistan" + }, + { + "key": "BR", + "text": "Brazil" + }, + { + "key": "NG", + "text": "Nigeria" + }, + { + "key": "BA", + "text": "Bangladesh" + } + ] +} diff --git a/examples/ui5-js-app/webapp/test/e2e/prop-array.test.js b/examples/ui5-js-app/webapp/test/e2e/prop-array.test.js new file mode 100644 index 00000000..0f759ca8 --- /dev/null +++ b/examples/ui5-js-app/webapp/test/e2e/prop-array.test.js @@ -0,0 +1,30 @@ +const Main = require("./pageObjects/Main") +const viewName = "test.Sample.view.Main" + +const multiComboBoxSelector = { + forceSelect: true, + selector: { + interaction: "root", + id: "multiComboBox", + viewName: viewName + } +} + +describe("ui5 property array test", () => { + before(async () => { + await Main.open() + }) + + it("should get empty array", async () => { + const oMultiComboBox = await browser.asControl(multiComboBoxSelector) + const aSelectedKeys = await oMultiComboBox.getSelectedKeys() + expect(aSelectedKeys.length).toEqual(0) + }) + + it("select two countries from list", async () => { + const oMultiComboBox = await browser.asControl(multiComboBoxSelector) + await oMultiComboBox.setSelectedKeys(["IN", "BR"]) + const aSelectedKeys = await oMultiComboBox.getSelectedKeys() + expect(aSelectedKeys.length).toEqual(2) + }) +}) diff --git a/examples/ui5-js-app/webapp/view/Main.view.xml b/examples/ui5-js-app/webapp/view/Main.view.xml index f12b9022..5670d620 100644 --- a/examples/ui5-js-app/webapp/view/Main.view.xml +++ b/examples/ui5-js-app/webapp/view/Main.view.xml @@ -62,6 +62,9 @@