diff --git a/addons/sms/static/tests/sms_widget_test.js b/addons/sms/static/tests/sms_widget_test.js index 9a0f31e42c1..467cd0770de 100644 --- a/addons/sms/static/tests/sms_widget_test.js +++ b/addons/sms/static/tests/sms_widget_test.js @@ -1,7 +1,9 @@ odoo.define('sms.sms_widget_tests', function (require) { "use strict"; +var config = require('web.config'); var FormView = require('web.FormView'); +var ListView = require('web.ListView'); var testUtils = require('web.test_utils'); var createView = testUtils.createView; @@ -12,10 +14,16 @@ QUnit.module('fields', { partner: { fields: { message: {string: "message", type: "text"}, + foo: {string: "Foo", type: "char", default: "My little Foo Value"}, }, records: [{ id: 1, message: "", + foo: 'yop', + }, { + id: 2, + message: "", + foo: 'bayou', }] }, visitor: { @@ -114,5 +122,58 @@ QUnit.module('fields', { form.destroy(); }); + + 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: '', + intercepts: { + do_action(ev) { + assert.equal(ev.data.action.res_model, 'sms.composer', + 'The action to send an SMS should have been executed'); + doActionCount += 1; + } + } + }); + + assert.containsN(list, 'tbody td:not(.o_list_record_selector)', 4); + assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yopSMS', + "value should be displayed properly with a link to send SMS"); + + assert.containsN(list, 'a.o_field_widget.o_form_uri', 2, + "should have the correct classnames"); + + // Edit a line and check the result + var $cell = list.$('tbody td:not(.o_list_record_selector)').first(); + await testUtils.dom.click($cell); + assert.hasClass($cell.parent(),'o_selected_row', 'should be set as edit mode'); + assert.strictEqual($cell.find('input').val(), 'yop', + 'should have the corect value in internal input'); + await testUtils.fields.editInput($cell.find('input'), 'new'); + + // save + await testUtils.dom.click(list.$buttons.find('.o_list_button_save')); + $cell = list.$('tbody td:not(.o_list_record_selector)').first(); + assert.doesNotHaveClass($cell.parent(), 'o_selected_row', 'should not be in edit mode anymore'); + assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'newSMS', + "value should be properly updated"); + assert.containsN(list, 'a.o_field_widget.o_form_uri', 2, + "should still have links with correct classes"); + + await testUtils.dom.click(list.$('tbody td:not(.o_list_record_selector) .o_field_phone_sms').first()); + assert.equal(doActionCount, 1, 'Only one action should have been executed'); + assert.containsNone(list, '.o_selected_row', + 'None of the list element should have been activated'); + + list.destroy(); + }); }); }); diff --git a/addons/web/static/tests/fields/basic_fields_mobile_tests.js b/addons/web/static/tests/fields/basic_fields_mobile_tests.js index bdd78c21df9..d4657a65856 100644 --- a/addons/web/static/tests/fields/basic_fields_mobile_tests.js +++ b/addons/web/static/tests/fields/basic_fields_mobile_tests.js @@ -111,7 +111,7 @@ QUnit.module('basic_fields', { assert.containsN(list, '.o_data_row', 3, "should have 3 record"); - assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yopSMS', + assert.strictEqual(list.$('tbody td:not(.o_list_record_selector) a').first().text(), 'yop', "value should be displayed properly"); var $phoneLink = list.$('a.o_form_uri.o_field_widget'); @@ -132,7 +132,7 @@ QUnit.module('basic_fields', { await testUtils.dom.click(list.$buttons.find('.o_list_button_save')); $cell = list.$('tbody td:not(.o_list_record_selector)').first(); assert.doesNotHaveClass($cell.parent(), 'o_selected_row', 'should not be in edit mode anymore'); - assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'newSMS', + assert.strictEqual(list.$('tbody td:not(.o_list_record_selector) a').first().text(), 'new', "value should be properly updated"); $phoneLink = list.$('a.o_form_uri.o_field_widget'); assert.strictEqual($phoneLink.length, 3, diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index cb19958ef94..ada71b91429 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -4907,7 +4907,7 @@ QUnit.module('basic_fields', { }); QUnit.test('phone field in editable list view on normal screens', async function (assert) { - assert.expect(11); + assert.expect(8); var doActionCount = 0; var list = await createView({ @@ -4920,17 +4920,10 @@ QUnit.module('basic_fields', { size_class: config.device.SIZES.LG, }, }, - intercepts: { - do_action(ev) { - assert.equal(ev.data.action.res_model, 'sms.composer', - 'The action to send an SMS should have been executed'); - doActionCount += 1; - } - } }); assert.containsN(list, 'tbody td:not(.o_list_record_selector)', 5); - assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'yopSMS', + assert.strictEqual(list.$('tbody td:not(.o_list_record_selector) a').first().text(), 'yop', "value should be displayed properly with a link to send SMS"); assert.containsN(list, 'a.o_field_widget.o_form_uri', 5, @@ -4948,16 +4941,11 @@ QUnit.module('basic_fields', { await testUtils.dom.click(list.$buttons.find('.o_list_button_save')); $cell = list.$('tbody td:not(.o_list_record_selector)').first(); assert.doesNotHaveClass($cell.parent(), 'o_selected_row', 'should not be in edit mode anymore'); - assert.strictEqual(list.$('tbody td:not(.o_list_record_selector)').first().text(), 'newSMS', + assert.strictEqual(list.$('tbody td:not(.o_list_record_selector) a').first().text(), 'new', "value should be properly updated"); assert.containsN(list, 'a.o_field_widget.o_form_uri', 5, "should still have links with correct classes"); - await testUtils.dom.click(list.$('tbody td:not(.o_list_record_selector) .o_field_phone_sms').first()); - assert.equal(doActionCount, 1, 'Only one action should have been executed'); - assert.containsNone(list, '.o_selected_row', - 'None of the list element should have been activated'); - list.destroy(); });