diff options
| author | Julien Mougenot <jum@odoo.com> | 2020-07-28 09:27:13 +0000 |
|---|---|---|
| committer | Julien Mougenot <jum@odoo.com> | 2020-07-29 11:20:16 +0000 |
| commit | d3f0632f4977cd1f7d7099fb2688722bcd451d27 (patch) | |
| tree | ad934c91286cfaae3335dcf93540d7fa6ba4a508 /addons/web/static/tests/components/datepicker_tests.js | |
| parent | dbbf6a87318a4449a57585218d4d140a0406e272 (diff) | |
[FIX] web: datepicker get correct database format
Before this commit, the format used by both date and datetime picker
components depended on default props which are evaluated on module
loading. This was an issue because the "time" module did not have time
to load and fetch the correct database value, hence using the default
ones.
Now, the format is evaluated on component instantiation, giving enough
time to the "time" module to load.
Task 2307258
closes odoo/odoo#55113
X-original-commit: 792b565a65a8c9f65bf13e94f30b88913f2bfa7f
Signed-off-by: Paul Morelle <madprog@users.noreply.github.com>
Signed-off-by: Julien Mougenot (jum) <jum@odoo.com>
Diffstat (limited to 'addons/web/static/tests/components/datepicker_tests.js')
| -rw-r--r-- | addons/web/static/tests/components/datepicker_tests.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/addons/web/static/tests/components/datepicker_tests.js b/addons/web/static/tests/components/datepicker_tests.js index 995521259a1..7e59e9620d7 100644 --- a/addons/web/static/tests/components/datepicker_tests.js +++ b/addons/web/static/tests/components/datepicker_tests.js @@ -3,6 +3,7 @@ odoo.define('web.datepicker_tests', function (require) { const { DatePicker, DateTimePicker } = require('web.DatePickerOwl'); const testUtils = require('web.test_utils'); + const time = require('web.time'); const { createComponent } = testUtils; @@ -101,6 +102,26 @@ odoo.define('web.datepicker_tests', function (require) { picker.destroy(); }); + QUnit.test("Date format is correctly set", async function (assert) { + assert.expect(2); + + testUtils.patch(time, { getLangDateFormat: () => "YYYY/MM/DD" }); + const picker = await createComponent(DatePicker, { + props: { date: moment('01/09/1997') }, + }); + const input = picker.el.querySelector('.o_datepicker_input'); + + assert.strictEqual(input.value, '1997/01/09'); + + // Forces an update to assert that the registered format is the correct one + await testUtils.dom.click(input); + + assert.strictEqual(input.value, '1997/01/09'); + + picker.destroy(); + testUtils.unpatch(time); + }); + QUnit.module('DateTimePicker'); QUnit.test("basic rendering", async function (assert) { @@ -211,5 +232,25 @@ odoo.define('web.datepicker_tests', function (require) { picker.destroy(); }); + + QUnit.test("Date time format is correctly set", async function (assert) { + assert.expect(2); + + testUtils.patch(time, { getLangDatetimeFormat: () => "hh:mm:ss YYYY/MM/DD" }); + const picker = await createComponent(DateTimePicker, { + props: { date: moment('01/09/1997 12:30:01') }, + }); + const input = picker.el.querySelector('.o_datepicker_input'); + + assert.strictEqual(input.value, '12:30:01 1997/01/09'); + + // Forces an update to assert that the registered format is the correct one + await testUtils.dom.click(input); + + assert.strictEqual(input.value, '12:30:01 1997/01/09'); + + picker.destroy(); + testUtils.unpatch(time); + }); }); }); |
