summaryrefslogtreecommitdiff
path: root/addons/web
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2021-01-04 10:29:27 +0000
committerAaron Bohy <aab@odoo.com>2021-01-04 12:47:18 +0000
commit6e928ef24d70e69d8063bd3aab884d4bbbb94150 (patch)
tree36b4f98b0d6d3a5c830c5fb829cac897980b79c9 /addons/web
parentabff1ca94bcc829250b63fd9677890988b796819 (diff)
[FIX] web: SampleServer: fix randomly failing test
Commit [1] recently tweaked the way floats are generated in the SampleServer, as they are now rounded to 2 decimals. As a consequence it sometimes generates integers for float fields (e.g. 5 for 5.00). This is also what the real server does, so it's fine. However, a test was asserting that float fields were floats, so this test sometimes failed and thus needed to be adapted. [1] https://github.com/odoo/odoo/commit/81f2bc7 closes odoo/odoo#64008 Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
Diffstat (limited to 'addons/web')
-rw-r--r--addons/web/static/tests/views/sample_server_tests.js12
1 files changed, 5 insertions, 7 deletions
diff --git a/addons/web/static/tests/views/sample_server_tests.js b/addons/web/static/tests/views/sample_server_tests.js
index 9eedd16c7f5..0f1dd45f795 100644
--- a/addons/web/static/tests/views/sample_server_tests.js
+++ b/addons/web/static/tests/views/sample_server_tests.js
@@ -105,13 +105,11 @@ odoo.define('web.sample_server_tests', function (require) {
);
}
}
- function assertBetween(fieldName, min, max, decimal = 1) {
+ function assertBetween(fieldName, min, max, isFloat = false) {
+ const val = rec[fieldName];
assert.ok(
- min <= rec[fieldName] && rec[fieldName] < max &&
- rec[fieldName].toString().split(".").length === decimal,
- `Field "${fieldName}" is between ${min} and ${max} and is ${
- decimal === 1 ? "an integer" : "a float number"
- }`
+ min <= val && val < max && (isFloat || parseInt(val, 10) === val),
+ `Field "${fieldName}" is between ${min} and ${max} ${!isFloat ? 'and is an integer ' : ''}: ${val}`
);
}
@@ -129,7 +127,7 @@ odoo.define('web.sample_server_tests', function (require) {
assert.ok(SAMPLE_TEXTS.includes(rec.description));
assertFormat('birthday', /\d{4}-\d{2}-\d{2}/);
assertFormat('arrival_date', /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/);
- assertBetween('height', 0, MAX_FLOAT, 2);
+ assertBetween('height', 0, MAX_FLOAT, true);
assertBetween('color', 0, MAX_COLOR_INT);
assertBetween('age', 0, MAX_INTEGER);
assertBetween('salary', 0, MAX_MONETARY);