diff options
| author | Debauche Stéphane <std@odoo.com> | 2020-01-20 14:28:35 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-01-28 09:14:43 +0000 |
| commit | 75f7ab0608bfb9770e99fe2ce1ad55e76c70ac72 (patch) | |
| tree | 16654596a1fc75b24e71c56f56d27a65b96f5739 /addons/sms/static | |
| parent | 1ec887b773581b6316902997fec94176bbae1ac0 (diff) | |
[FIX] web: fix email and phone widgets with empty value
When the value is empty in a related field, string of the element was
displaying "false" instead of an empty string which is not what we expect.
This commit fixes that issue.
Task ID 2119333
PR #40949
Diffstat (limited to 'addons/sms/static')
| -rw-r--r-- | addons/sms/static/src/js/fields_phone_widget.js | 2 | ||||
| -rw-r--r-- | addons/sms/static/tests/sms_widget_test.js | 44 |
2 files changed, 45 insertions, 1 deletions
diff --git a/addons/sms/static/src/js/fields_phone_widget.js b/addons/sms/static/src/js/fields_phone_widget.js index 4dd9a033e23..84809f2b044 100644 --- a/addons/sms/static/src/js/fields_phone_widget.js +++ b/addons/sms/static/src/js/fields_phone_widget.js @@ -79,7 +79,7 @@ Phone.include({ */ _renderReadonly: function () { var def = this._super.apply(this, arguments); - if (this.enableSMS) { + if (this.enableSMS && this.value) { var $composerButton = $('<a>', { title: _t('Send SMS Text Message'), href: '', diff --git a/addons/sms/static/tests/sms_widget_test.js b/addons/sms/static/tests/sms_widget_test.js index 36ae6de5c1b..9a0f31e42c1 100644 --- a/addons/sms/static/tests/sms_widget_test.js +++ b/addons/sms/static/tests/sms_widget_test.js @@ -18,6 +18,15 @@ QUnit.module('fields', { message: "", }] }, + visitor: { + fields: { + mobile: {string: "mobile", type: "text"}, + }, + records: [{ + id: 1, + mobile: "+32494444444", + }] + }, }; } }, function () { @@ -32,6 +41,7 @@ QUnit.module('fields', { data: this.data, arch: '<form><sheet><field name="message" widget="sms_widget"/></sheet></form>', }); + assert.containsOnce(form, '.o_sms_count', "Should have a sms counter"); assert.strictEqual(form.$('.o_sms_count').text(), '0 characters, fits in 0 SMS (GSM7) ', 'Should be "0 characters, fits in 0 SMS (GSM7) " by default'); @@ -70,5 +80,39 @@ QUnit.module('fields', { form.destroy(); }); + + QUnit.test('Sms widgets with non-empty initial value', async function (assert) { + assert.expect(1); + var form = await createView({ + View: FormView, + model: 'visitor', + data: this.data, + arch: `<form><sheet><field name="mobile" widget="sms_widget"/></sheet></form>`, + res_id: 1, + res_ids: [1], + }); + + assert.strictEqual(form.$('.o_field_text').text(), '+32494444444', + 'Should have the initial value'); + + form.destroy(); + }); + + QUnit.test('Sms widgets with empty initial value', async function (assert) { + assert.expect(1); + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: `<form><sheet><field name="message" widget="sms_widget"/></sheet></form>`, + res_id: 1, + res_ids: [1], + }); + + assert.strictEqual(form.$('.o_field_text').text(), '', + 'Should have the empty initial value'); + + form.destroy(); + }); }); }); |
