/** @odoo-module **/ import FormView from 'web.FormView'; import ListView from 'web.ListView'; import testUtils from 'web.test_utils'; import { makeView, setupViewRegistries } from "@web/../tests/views/helpers"; import { getFixture } from "@web/../tests/helpers/utils"; const createView = testUtils.createView; QUnit.module('fields', { beforeEach: function () { this.data = { partner: { fields: { message: {string: "message", type: "text"}, foo: {string: "Foo", type: "char", default: "My little Foo Value"}, mobile: {string: "mobile", type: "text"}, }, records: [{ id: 1, message: "", foo: 'yop', mobile: "+32494444444", }, { id: 2, message: "", foo: 'bayou', }] }, visitor: { fields: { mobile: {string: "mobile", type: "text"}, }, records: [{ id: 1, mobile: "+32494444444", }] }, }; setupViewRegistries(); this.target = getFixture(); } }, function () { QUnit.module('SmsWidget'); QUnit.test('Sms widgets are correctly rendered', async function (assert) { assert.expect(9); await makeView({ type: "form", resModel: "partner", serverData: { models: this.data }, arch: /* xml */ `
`, }); assert.containsOnce(this.target, '.o_sms_count', "Should have a sms counter"); assert.strictEqual(this.target.querySelector('.o_sms_count').textContent, '0 characters, fits in 0 SMS (GSM7) ', 'Should be "0 characters, fits in 0 SMS (GSM7) " by default'); // GSM-7 await testUtils.fields.editAndTrigger(this.target.querySelector('.o_input'), "Hello from Odoo", 'input'); assert.strictEqual(this.target.querySelector('.o_sms_count').textContent, '15 characters, fits in 1 SMS (GSM7) ', 'Should be "15 characters, fits in 1 SMS (GSM7) " for "Hello from Odoo"'); // GSM-7 with \n => this one count as 2 characters await testUtils.fields.editAndTrigger(this.target.querySelector('.o_input'), "Hello from Odoo\n", 'input'); assert.strictEqual(this.target.querySelector('.o_sms_count').textContent, '17 characters, fits in 1 SMS (GSM7) ', 'Should be "17 characters, fits in 1 SMS (GSM7) " for "Hello from Odoo\\n"'); // Unicode => ê await testUtils.fields.editAndTrigger(this.target.querySelector('.o_input'), "Hêllo from Odoo", 'input'); assert.strictEqual(this.target.querySelector('.o_sms_count').textContent, '15 characters, fits in 1 SMS (UNICODE) ', 'Should be "15 characters, fits in 1 SMS (UNICODE) " for "Hêllo from Odoo"'); // GSM-7 with 160c var text = Array(161).join('a'); await testUtils.fields.editAndTrigger(this.target.querySelector('.o_input'), text, 'input'); assert.strictEqual(this.target.querySelector('.o_sms_count').textContent, '160 characters, fits in 1 SMS (GSM7) ', 'Should be "160 characters, fits in 1 SMS (GSM7) " for 160 x "a"'); // GSM-7 with 161c text = Array(162).join('a'); await testUtils.fields.editAndTrigger(this.target.querySelector('.o_input'), text, 'input'); assert.strictEqual(this.target.querySelector('.o_sms_count').textContent, '161 characters, fits in 2 SMS (GSM7) ', 'Should be "161 characters, fits in 2 SMS (GSM7) " for 161 x "a"'); // Unicode with 70c text = Array(71).join('ê'); await testUtils.fields.editAndTrigger(this.target.querySelector('.o_input'), text, 'input'); assert.strictEqual(this.target.querySelector('.o_sms_count').textContent, '70 characters, fits in 1 SMS (UNICODE) ', 'Should be "70 characters, fits in 1 SMS (UNICODE) " for 70 x "ê"'); // Unicode with 71c text = Array(72).join('ê'); await testUtils.fields.editAndTrigger(this.target.querySelector('.o_input'), text, 'input'); assert.strictEqual(this.target.querySelector('.o_sms_count').textContent, '71 characters, fits in 2 SMS (UNICODE) ', 'Should be "71 characters, fits in 2 SMS (UNICODE) " for 71 x "ê"'); }); QUnit.test('Sms widgets with non-empty initial value', async function (assert) { assert.expect(1); await makeView({ type: "form", resModel: "visitor", resId: 1, serverData: { models: this.data }, arch: /* xml */ ``, }); assert.strictEqual(this.target.querySelector('.o_field_text span').textContent, '+32494444444', 'Should have the initial value'); }); QUnit.test('Sms widgets with empty initial value', async function (assert) { assert.expect(1); await makeView({ type: "form", resModel: "partner", resId: 1, serverData: { models: this.data }, arch: /* xml */ ``, }); assert.strictEqual(this.target.querySelector('.o_field_text span').textContent, '', 'Should have the empty initial value'); }); QUnit.module('PhoneWidget'); QUnit.test('phone field in editable list view on normal screens', async function (assert) { assert.expect(11); var doActionCount = 0; var list = await createView({ View: ListView, model: 'partner', data: this.data, debug:true, arch: '