IMP] sms: improve readability of the widget

This commit is contained in:
Rémi Rahir
2018-07-06 14:15:56 +02:00
parent 8a1dad3da4
commit f9a68d5e77
3 changed files with 11 additions and 10 deletions
+2 -1
View File
@@ -9,6 +9,7 @@ var framework = require('web.framework');
var FieldText = basicFields.FieldText;
var QWeb = core.qweb;
var _t = core._t
/**
* SmsWidget is a widget to display a textarea (the body) and a text representing
* the number of SMS and the number of characters. This text is computed every
@@ -89,7 +90,7 @@ var SmsWidget = FieldText.extend({
* @private
*/
_renderSMS: function () {
this.$('.o_sms_count').text(this.nbrChar + ' / ' + this.nbrSMS + ' SMS (' + this.encoding + ') ');
this.$('.o_sms_count').text(this.nbrChar + _t(' chars, fits in ') + this.nbrSMS + ' SMS (' + this.encoding + ') ');
},
//--------------------------------------------------------------------------
@@ -34,32 +34,32 @@ QUnit.module('fields', {
});
form.$buttons.find('.o_form_button_edit').click();
assert.ok(form.$('.o_sms_count').length, "Should have a sms counter");
assert.strictEqual(form.$('.o_sms_count').text(), '0 / 0 SMS (GSM7) ', 'Should be "0 / 0 SMS (GSM7) " by default');
assert.strictEqual(form.$('.o_sms_count').text(), '0 chars, fits in 0 SMS (GSM7) ', 'Should be "0 chars, fits in 0 SMS (GSM7) " by default');
// GSM-7
form.$('.o_input').val("Hello from Odoo").trigger('input');
assert.strictEqual(form.$('.o_sms_count').text(), '15 / 1 SMS (GSM7) ', 'Should be "15 / 1 SMS (GSM7) " for "Hello from Odoo"');
assert.strictEqual(form.$('.o_sms_count').text(), '15 chars, fits in 1 SMS (GSM7) ', 'Should be "15 chars, fits in 1 SMS (GSM7) " for "Hello from Odoo"');
// GSM-7 with \n => this one count as 2 characters
form.$('.o_input').val("Hello from Odoo\n").trigger('input');
assert.strictEqual(form.$('.o_sms_count').text(), '17 / 1 SMS (GSM7) ', 'Should be "17 / 1 SMS (GSM7) " for "Hello from Odoo\\n"');
assert.strictEqual(form.$('.o_sms_count').text(), '17 chars, fits in 1 SMS (GSM7) ', 'Should be "17 chars, fits in 1 SMS (GSM7) " for "Hello from Odoo\\n"');
// Unicode => ê
form.$('.o_input').val("Hêllo from Odoo").trigger('input');
assert.strictEqual(form.$('.o_sms_count').text(), '15 / 1 SMS (UNICODE) ', 'Should be "15 / 1 SMS (UNICODE) " for "Hêllo from Odoo"');
assert.strictEqual(form.$('.o_sms_count').text(), '15 chars, fits in 1 SMS (UNICODE) ', 'Should be "15 chars, fits in 1 SMS (UNICODE) " for "Hêllo from Odoo"');
// GSM-7 with 160c
var text = Array(161).join('a');
form.$('.o_input').val(text).trigger('input');
assert.strictEqual(form.$('.o_sms_count').text(), '160 / 1 SMS (GSM7) ', 'Should be "160 / 1 SMS (GSM7) " for 160 x "a"');
assert.strictEqual(form.$('.o_sms_count').text(), '160 chars, fits in 1 SMS (GSM7) ', 'Should be "160 chars, fits in 1 SMS (GSM7) " for 160 x "a"');
// GSM-7 with 161c
text = Array(162).join('a');
form.$('.o_input').val(text).trigger('input');
assert.strictEqual(form.$('.o_sms_count').text(), '161 / 2 SMS (GSM7) ', 'Should be "161 / 2 SMS (GSM7) " for 161 x "a"');
assert.strictEqual(form.$('.o_sms_count').text(), '161 chars, fits in 2 SMS (GSM7) ', 'Should be "161 chars, fits in 2 SMS (GSM7) " for 161 x "a"');
// Unicode with 70c
text = Array(71).join('ê');
form.$('.o_input').val(text).trigger('input');
assert.strictEqual(form.$('.o_sms_count').text(), '70 / 1 SMS (UNICODE) ', 'Should be "70 / 1 SMS (UNICODE) " for 70 x "ê"');
assert.strictEqual(form.$('.o_sms_count').text(), '70 chars, fits in 1 SMS (UNICODE) ', 'Should be "70 chars, fits in 1 SMS (UNICODE) " for 70 x "ê"');
// Unicode with 71c
text = Array(72).join('ê');
form.$('.o_input').val(text).trigger('input');
assert.strictEqual(form.$('.o_sms_count').text(), '71 / 2 SMS (UNICODE) ', 'Should be "71 / 2 SMS (UNICODE) " for 71 x "ê"');
assert.strictEqual(form.$('.o_sms_count').text(), '71 chars, fits in 2 SMS (UNICODE) ', 'Should be "71 chars, fits in 2 SMS (UNICODE) " for 71 x "ê"');
form.destroy();
});
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<templates>
<t t-name="sms.sms_count">
<span class="pull-right"><span class="text-muted o_sms_count"></span> <a href="https://iap-services.odoo.com/iap/sms/pricing" target="_blank" class="fa fa-lg fa-info" aria-label="SMS Pricing" title="SMS Pricing"/></span>
<span class="pull-right"><span class="text-muted o_sms_count"></span> <a href="https://iap-services.odoo.com/iap/sms/pricing" target="_blank" class="fa fa-lg fa-info-circle" aria-label="SMS Pricing" title="SMS Pricing"/></span>
</t>
</templates>