From 76ccfeda5625d060a0359bd7fd0a083214a09f90 Mon Sep 17 00:00:00 2001 From: Marco Beier Date: Sat, 23 May 2020 15:07:32 +0200 Subject: [PATCH] Added everything for Step 4: Testing a New Module --- webapp/model/FlaggedType.js | 13 +++++++ webapp/test/unit/AllTests.js | 2 +- webapp/test/unit/model/flaggedtype.js | 56 +++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 webapp/model/FlaggedType.js create mode 100644 webapp/test/unit/model/flaggedtype.js diff --git a/webapp/model/FlaggedType.js b/webapp/model/FlaggedType.js new file mode 100644 index 0000000..78f93e3 --- /dev/null +++ b/webapp/model/FlaggedType.js @@ -0,0 +1,13 @@ +sap.ui.define([ + "sap/ui/model/SimpleType" +], function (SimpleType) { + "use strict"; + return SimpleType.extend("com.mrb.UI5-Testing.model.FlaggedType", { + formatValue: function () { + }, + parseValue: function () { + }, + validateValue: function () { + } + }); +}); \ No newline at end of file diff --git a/webapp/test/unit/AllTests.js b/webapp/test/unit/AllTests.js index cdf579c..8cd8764 100644 --- a/webapp/test/unit/AllTests.js +++ b/webapp/test/unit/AllTests.js @@ -1,3 +1,3 @@ -sap.ui.define(["./model/models", "./model/formatter"], function () { +sap.ui.define(["./model/models", "./model/formatter", "./model/FlaggedType"], function () { "use strict"; }); diff --git a/webapp/test/unit/model/flaggedtype.js b/webapp/test/unit/model/flaggedtype.js new file mode 100644 index 0000000..8c20d8b --- /dev/null +++ b/webapp/test/unit/model/flaggedtype.js @@ -0,0 +1,56 @@ +/*global QUnit*/ +sap.ui.require(["com/mrb/UI5-Testing/model/FlaggedType"], function ( + FlaggedType +) { + "use strict"; + QUnit.module("FlaggedType - formatting"); + + QUnit.test("Should convert 1 to true", function (assert) { + //Act + var bFormattedValue = new FlaggedType().formatValue(1); + //Assert + assert.strictEqual( + bFormattedValue, + true, + "The formatting conversion was correct" + ); + }); + QUnit.test("Should convert other values to false", function (assert) { + var oFlaggedType = new FlaggedType(); + // Act + var bFormattedZero = oFlaggedType.formatValue(0); + var bFormattedNegativeNumber = oFlaggedType.formatValue(-666); + // Assert + assert.strictEqual( + bFormattedZero, + false, + "The formatting conversion was correct" + ); + assert.strictEqual( + bFormattedNegativeNumber, + false, + "The formatting conversion was correct" + ); + }); + QUnit.module("FlaggedType - parsing"); + QUnit.test("Should parse false to 0", function (assert) { + // Act + var iParsedValue = new FlaggedType().parseValue(false); + // Assert + assert.strictEqual( + iParsedValue, + 0, + "The parsing conversion matched the input" + ); + }); + QUnit.test("Should parse true to 1", function (assert) { + // Act + var iParsedValue = new FlaggedType().parseValue(true); + // Assert + assert.strictEqual( + iParsedValue, + 1, + "The parsing conversion matched the input" + ); + }); +});