From dcf8c67fe386cfe7005288c179e829bab9aefb31 Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Tue, 5 Mar 2019 15:44:31 +0000 Subject: [FIX] web: hide CopyClipboard widget button when pointless The widget has been moved in rev. odoo/odoo@15f3bbe but was not very generic. In particular, there was a traceback when clicking on the button if the field had no value (the button was displayed for readonly fields in create mode). The button is now only appended in readonly mode (a `button` inside an `input` or a `textarea` is not very DOM friendly) if the field has a value. Task 1941996 closes odoo/odoo#31635 Signed-off-by: Aaron Bohy (aab) --- .../web/static/tests/fields/basic_fields_tests.js | 86 +++++++++++++++------- 1 file changed, 60 insertions(+), 26 deletions(-) (limited to 'addons/web/static/tests/fields/basic_fields_tests.js') diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 978e6de226f..40593480099 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1412,45 +1412,79 @@ QUnit.module('basic_fields', { list.destroy(); }); - QUnit.module('copy_clipboard', { - beforeEach: function () { - this.data = { - partner: { - fields: { - script_external: {string: "Script External", type: "text"}, - web_page: {string: "Web page link", type: "char"} - }, - records: [{ - id: 1, - script_external:'Random Text', - web_page: 'web page links' - },], - }, - }; - } - }); + QUnit.module('CopyClipboard'); QUnit.test('Char & Text Fields: Copy to clipboard button', function (assert) { assert.expect(2); - var done = assert.async(); - testUtils.createAsyncView({ + + var form = createView({ View: FormView, model: 'partner', data: this.data, arch: '
' + '' + '
' + - '' + - '' + + '' + + '' + '
' + '
' + '
', - }).then(function (form) { - assert.strictEqual(form.$('.o_clipboard_button.o_btn_text_copy').length, 1,"Should have copy button on text type field"); - assert.strictEqual(form.$('.o_clipboard_button.o_btn_char_copy').length, 1,"Should have copy button on char type field"); - form.destroy(); - done(); + res_id: 1, + }); + + assert.strictEqual(form.$('.o_clipboard_button.o_btn_text_copy').length, 1,"Should have copy button on text type field"); + assert.strictEqual(form.$('.o_clipboard_button.o_btn_char_copy').length, 1,"Should have copy button on char type field"); + + form.destroy(); + }); + + QUnit.test('CopyClipboard widget on unset field', function (assert) { + assert.expect(1); + + this.data.partner.records[0].foo = false; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '
', + res_id: 1, + }); + + assert.containsNone(form, '.o_field_copy[name="foo"] .o_clipboard_button', + "foo (unset) should not contain a button"); + + form.destroy(); + }); + + QUnit.test('CopyClipboard widget on readonly unset fields in create mode', function (assert) { + assert.expect(1); + + this.data.partner.fields.display_name.readonly = true; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '
', }); + + assert.containsNone(form, '.o_field_copy[name="display_name"] .o_clipboard_button', + "the readonly unset field should not contain a button"); + + form.destroy(); }); QUnit.module('FieldText'); -- cgit v1.2.3