Skip to content

Commit

Permalink
[FIX] web: wrong tests
Browse files Browse the repository at this point in the history
This commit fixes two tests that became meaningless after tweaks
in production code:

 - form_tests: use two char fields, as integer fields can't be
   unset since rev. c62a4ed
 - pivot_tests: the button is disabled since rev. 4f4f111, but
   simulating a click with jQuery bypasses the disabled attribute

This commit also removes unecessary overrides of mockRPC. Those
overrides existed  because the attachments part of the sidebar
used to make a search_read RPC, but this has been removed at rev.
1dbb555.
  • Loading branch information
aab-odoo committed Nov 13, 2018
1 parent 8efa9e5 commit b9837f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 63 deletions.
59 changes: 8 additions & 51 deletions addons/web/static/tests/views/form_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ QUnit.module('Views', {

this.data.partner.fields.foo.default = false; // no default value for this test
this.data.partner.records[1].foo = false; // 1 is record with id=2
this.data.partner.records[1].int_field = false; // 1 is record with id=2
this.data.partner.records[1].display_name = false; // 1 is record with id=2

var form = createView({
View: FormView,
Expand All @@ -807,16 +807,16 @@ QUnit.module('Views', {
'<sheet>' +
'<group>' +
'<field name="foo"/>' +
'<field name="int_field" attrs="{\'readonly\': [[\'foo\', \'=\', \'readonly\']]}"/>' +
'<field name="display_name" attrs="{\'readonly\': [[\'foo\', \'=\', \'readonly\']]}"/>' +
'</group>' +
'</sheet>' +
'</form>',
res_id: 2,
});

assert.strictEqual(form.$('.o_field_widget.o_field_empty').length, 1,
assert.strictEqual(form.$('.o_field_widget.o_field_empty').length, 2,
"should have 1 empty field with correct class");
assert.strictEqual(form.$('.o_form_label_empty').length, 1,
assert.strictEqual(form.$('.o_form_label_empty').length, 2,
"should have 1 muted label (for the empty fied) in readonly");

form.$buttons.find('.o_form_button_edit').click();
Expand All @@ -826,10 +826,10 @@ QUnit.module('Views', {
assert.strictEqual(form.$('.o_form_label_empty').length, 0,
"in edit mode, only labels associated to empty readonly fields should have the o_form_label_empty class");

form.$('input[name="foo"]').val("readonly").trigger("input"); // int_field is now rerendered as readonly
form.$('input[name="foo"]').val("edit").trigger("input"); // int_field is now rerendered as editable
form.$('input[name="int_field"]').val('1').trigger("input"); // int_field is now set
form.$('input[name="foo"]').val("readonly").trigger("input"); // int_field is now rerendered as readonly
form.$('input[name="foo"]').val("readonly").trigger("input"); // display_name is now rerendered as readonly
form.$('input[name="foo"]').val("edit").trigger("input"); // display_name is now rerendered as editable
form.$('input[name="display_name"]').val('1').trigger("input"); // display_name is now set
form.$('input[name="foo"]').val("readonly").trigger("input"); // display_name is now rerendered as readonly

assert.strictEqual(form.$('.o_field_empty').length, 0,
"there still should not be any empty class on fields as the readonly one is now set");
Expand Down Expand Up @@ -1646,12 +1646,6 @@ QUnit.module('Views', {
'</form>',
viewOptions: {hasSidebar: true},
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'search_read' && args.model === 'ir.attachment') {
return $.when([]);
}
return this._super.apply(this, arguments);
},
});

assert.ok(!form.sidebar.$el.hasClass('o_hidden'), 'sidebar should be visible');
Expand Down Expand Up @@ -1791,12 +1785,6 @@ QUnit.module('Views', {
'</form>',
res_id: 1,
viewOptions: {hasSidebar: true},
mockRPC: function (route, args) {
if (args.method === 'search_read' && args.model === 'ir.attachment') {
return $.when([]);
}
return this._super.apply(this, arguments);
},
});

assert.strictEqual(form.get('title'), 'first record',
Expand Down Expand Up @@ -1829,9 +1817,6 @@ QUnit.module('Views', {
assert.strictEqual(args.kwargs.context.hey, 'hoy',
"should have send the correct context");
}
if (args.method === 'search_read' && args.model === 'ir.attachment') {
return $.when([]);
}
return this._super.apply(this, arguments);
},
});
Expand All @@ -1853,12 +1838,6 @@ QUnit.module('Views', {
'</form>',
res_id: 1,
viewOptions: {hasSidebar: true},
mockRPC: function (route, args) {
if (args.method === 'search_read' && args.model === 'ir.attachment') {
return $.when([]);
}
return this._super.apply(this, arguments);
},
});

assert.strictEqual(form.get('title'), 'first record',
Expand Down Expand Up @@ -2426,12 +2405,6 @@ QUnit.module('Views', {
arch: '<form string="Partners"><field name="foo"></field></form>',
res_id: 1,
viewOptions: {hasSidebar: true},
mockRPC: function (route, args) {
if (args.method === 'search_read' && args.model === 'ir.attachment') {
return $.when([]);
}
return this._super.apply(this, arguments);
},
});

form.$buttons.find('.o_form_button_edit').click();
Expand Down Expand Up @@ -2773,12 +2746,6 @@ QUnit.module('Views', {
hasSidebar: true,
},
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'search_read' && args.model === 'ir.attachment') {
return $.when([]);
}
return this._super.apply(this, arguments);
},
});

assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should be 1');
Expand Down Expand Up @@ -2818,9 +2785,6 @@ QUnit.module('Views', {
},
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'search_read' && args.model === 'ir.attachment') {
return $.when([]);
}
assert.step(args.method);
return this._super.apply(this, arguments);
}
Expand Down Expand Up @@ -4990,9 +4954,6 @@ QUnit.module('Views', {
"the active_ids should be an array with 1 inside.");
return $.when({});
}
if (args.method === 'search_read' && args.model === 'ir.attachment') {
return $.when([]);
}
return this._super.apply(this, arguments);
},
});
Expand Down Expand Up @@ -6273,10 +6234,6 @@ QUnit.module('Views', {
res_id: 1,
viewOptions: {hasSidebar: true},
mockRPC: function (route, args) {
if (args.method === 'search_read' && args.model === 'ir.attachment') {
// rpcs done by the sidebar
return $.when([]);
}
var result = this._super.apply(this, arguments);
if (args.method === 'copy') {
return result.then(function (id) {
Expand Down
3 changes: 0 additions & 3 deletions addons/web/static/tests/views/list_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1054,9 +1054,6 @@ QUnit.module('Views', {
viewOptions: {hasSidebar: true},
arch: '<tree><field name="foo"/></tree>',
mockRPC: function (route) {
if (route === '/web/dataset/call_kw/ir.attachment/search_read') {
return $.when([]);
}
assert.step(route);
return this._super.apply(this, arguments);
},
Expand Down
12 changes: 3 additions & 9 deletions addons/web/static/tests/views/pivot_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ QUnit.module('Views', {
pivot.destroy();
});

QUnit.test('can download a file without data', function (assert) {
QUnit.test('download button is disabled when there is no data', function (assert) {
assert.expect(1);

this.data.partner.records = [];
Expand All @@ -803,16 +803,10 @@ QUnit.module('Views', {
'<field name="date" interval="month" type="col"/>' +
'<field name="foo" type="measure"/>' +
'</pivot>',
session: {
get_file: function (args) {
assert.strictEqual(args.url, '/web/pivot/export_xls',
"should call get_file with correct parameters");
args.complete();
},
},
});

pivot.$buttons.find('.o_pivot_download').click();
assert.strictEqual(pivot.$buttons.find('.o_pivot_download').attr('disabled'), 'disabled',
"download button should be disabled");
pivot.destroy();
});

Expand Down

0 comments on commit b9837f1

Please sign in to comment.