-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added everything for Step 2: A First Unit Test
- Loading branch information
Showing
2 changed files
with
102 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,8 @@ sap.ui.define([], function () { | |
} | ||
return parseFloat(sValue).toFixed(2); | ||
}, | ||
priceState: function (){ | ||
|
||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,110 @@ | ||
/*global QUnit*/ | ||
|
||
sap.ui.define([ | ||
"com/mrb/UI5-Testing/model/formatter" | ||
], function (formatter) { | ||
"use strict"; | ||
sap.ui.define(["com/mrb/UI5-Testing/model/formatter"], function (formatter) { | ||
"use strict"; | ||
|
||
QUnit.module("Number unit"); | ||
QUnit.module("Number unit"); | ||
|
||
function numberUnitValueTestCase(assert, sValue, fExpectedNumber) { | ||
// Act | ||
var fNumber = formatter.numberUnit(sValue); | ||
function numberUnitValueTestCase(assert, sValue, fExpectedNumber) { | ||
// Act | ||
var fNumber = formatter.numberUnit(sValue); | ||
|
||
// Assert | ||
assert.strictEqual(fNumber, fExpectedNumber, "The rounding was correct"); | ||
} | ||
// Assert | ||
assert.strictEqual(fNumber, fExpectedNumber, "The rounding was correct"); | ||
} | ||
|
||
QUnit.test("Should round down a 3 digit number", function (assert) { | ||
numberUnitValueTestCase.call(this, assert, "3.123", "3.12"); | ||
}); | ||
QUnit.test("Should round down a 3 digit number", function (assert) { | ||
numberUnitValueTestCase.call(this, assert, "3.123", "3.12"); | ||
}); | ||
|
||
QUnit.test("Should round up a 3 digit number", function (assert) { | ||
numberUnitValueTestCase.call(this, assert, "3.128", "3.13"); | ||
}); | ||
QUnit.test("Should round up a 3 digit number", function (assert) { | ||
numberUnitValueTestCase.call(this, assert, "3.128", "3.13"); | ||
}); | ||
|
||
QUnit.test("Should round a negative number", function (assert) { | ||
numberUnitValueTestCase.call(this, assert, "-3", "-3.00"); | ||
}); | ||
QUnit.test("Should round a negative number", function (assert) { | ||
numberUnitValueTestCase.call(this, assert, "-3", "-3.00"); | ||
}); | ||
|
||
QUnit.test("Should round an empty string", function (assert) { | ||
numberUnitValueTestCase.call(this, assert, "", ""); | ||
}); | ||
QUnit.test("Should round an empty string", function (assert) { | ||
numberUnitValueTestCase.call(this, assert, "", ""); | ||
}); | ||
|
||
QUnit.test("Should round a zero", function (assert) { | ||
numberUnitValueTestCase.call(this, assert, "0", "0.00"); | ||
}); | ||
QUnit.test("Should round a zero", function (assert) { | ||
numberUnitValueTestCase.call(this, assert, "0", "0.00"); | ||
}); | ||
|
||
QUnit.module("Price State"); | ||
|
||
// Requirements: | ||
// price < 50: Status is green (Success) | ||
// price >= 50 and price < 250: Status is normal (None) | ||
// price >= 250 and price < 2000: Status is orange (Warning) | ||
// price >= 2000: Status is red (Error) | ||
|
||
function priceStateTestCase(oOptions) { | ||
//Act | ||
var sState = formatter.priceState(oOptions.price); | ||
|
||
//Assert | ||
oOptions.assert.strictEqual( | ||
sState, | ||
oOptions.expected, | ||
"The price state was correct" | ||
); | ||
} | ||
|
||
QUnit.test( | ||
"Should format the products with a price lower than 50 to Success", | ||
function (assert) { | ||
priceStateTestCase.call(this, { | ||
assert: assert, | ||
price: 42, | ||
expected: "Success", | ||
}); | ||
} | ||
); | ||
|
||
QUnit.test( | ||
"Should format the products with a price of 50 to Normal", | ||
function (assert) { | ||
priceStateTestCase.call(this, { | ||
assert: assert, | ||
price: 50, | ||
expected: "None", | ||
}); | ||
} | ||
); | ||
|
||
QUnit.test( | ||
"Should format the products with a price between 50 and 250 to Normal", | ||
function (assert) { | ||
priceStateTestCase.call(this, { | ||
assert: assert, | ||
price: 112, | ||
expected: "None", | ||
}); | ||
} | ||
); | ||
|
||
QUnit.test( | ||
"Should format the products with a price between 250 and 2000 to Warning", | ||
function (assert) { | ||
priceStateTestCase.call(this, { | ||
assert: assert, | ||
price: 798, | ||
expected: "Warning", | ||
}); | ||
} | ||
); | ||
|
||
QUnit.test( | ||
"Should format the products with a price higher than 2000 to Error", | ||
function (assert) { | ||
priceStateTestCase.call(this, { | ||
assert: assert, | ||
price: 2001, | ||
expected: "Error", | ||
}); | ||
} | ||
); | ||
}); |