Skip to content

Commit

Permalink
Added everything for Step 4: Testing a New Module
Browse files Browse the repository at this point in the history
  • Loading branch information
wridgeu committed May 23, 2020
1 parent 92fd474 commit 76ccfed
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
13 changes: 13 additions & 0 deletions webapp/model/FlaggedType.js
Original file line number Diff line number Diff line change
@@ -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 () {
}
});
});
2 changes: 1 addition & 1 deletion webapp/test/unit/AllTests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sap.ui.define(["./model/models", "./model/formatter"], function () {
sap.ui.define(["./model/models", "./model/formatter", "./model/FlaggedType"], function () {
"use strict";
});
56 changes: 56 additions & 0 deletions webapp/test/unit/model/flaggedtype.js
Original file line number Diff line number Diff line change
@@ -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"
);
});
});

0 comments on commit 76ccfed

Please sign in to comment.