summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/basic_fields_tests.js
diff options
context:
space:
mode:
authorMartin Geubelle <mge@odoo.com>2019-03-05 15:44:31 +0000
committerMartin Geubelle <mge@odoo.com>2019-03-06 16:11:33 +0000
commitdcf8c67fe386cfe7005288c179e829bab9aefb31 (patch)
treeadbc8a760921dce28cae8f4ca64fa10673ffa911 /addons/web/static/tests/fields/basic_fields_tests.js
parenta3489be331f306db61fa80f21af51237bdf5e6bb (diff)
[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) <aab@odoo.com>
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/basic_fields_tests.js86
1 files changed, 60 insertions, 26 deletions
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: '<form string="Partners">' +
'<sheet>' +
'<div>' +
- '<field name="script_external" widget="CopyClipboardText"/>' +
- '<field name="web_page" widget="CopyClipboardChar"/>' +
+ '<field name="txt" widget="CopyClipboardText"/>' +
+ '<field name="foo" widget="CopyClipboardChar"/>' +
'</div>' +
'</sheet>' +
'</form>',
- }).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: '<form>' +
+ '<sheet>' +
+ '<group>' +
+ '<field name="foo" widget="CopyClipboardChar" />' +
+ '</group>' +
+ '</sheet>' +
+ '</form>',
+ 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: '<form>' +
+ '<sheet>' +
+ '<group>' +
+ '<field name="display_name" widget="CopyClipboardChar" />' +
+ '</group>' +
+ '</sheet>' +
+ '</form>',
});
+
+ 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');