Files
odoo_source/addons/lunch/static/tests/lunch_tests.js
T
qsm-odoo 250e716c3a [REF] web, *: restore views design
Since the new views merge, a lot of design elements were broken. This
was particularly impacting the fields in the editable list view; indeed
the editable list view is not using an inline form view anymore so the
fields in the list were not properly styled as the LESS was still
defined assuming the form view environment (for example the invalid
fields were red for o2m fields in form view but not in editable list
view even though they got the right CSS class).

This commit refactor the LESS following these rules:
- No more division of non-layout and layout rules. Dividing LESS rules
  in x_layout.less and x.less was a mistake. Many rules can be
  considered to be layout and not layout at the same time, developers
  always have to switch from one file part to the other, many CSS
  selectors (and rules!) are duplicated for nothing, ...
- Field style is extracted from x_view.less and put in the new
  fields.less file. As before, the fields_extra.less will contain the
  rules specific to community so that the enterprise repo can override
  those by replacing the whole file.
- Many classes have been renamed so that o_form_x_y becomes o_x_y as
  many classes can now be applied outside of form view. These classes
  should not be used in templates anyway.

The commit also changes the DOM of fields so that it is more minimalist
(no useless parent div, etc).

Input elements are not automatically styled anymore, they have to get
the o_input class explicitely. This allows to fix lots of small style
bugs of previous versions (required monetary field had not the proper
style, readonly m2m tags appeared as editable, ...). This also improves
the LESS code.

The editable list view should also completely stop flickering on chrome
and firefox.

The commit also removes the orange outline on list view dirty cells.

The commit also removes deprecated static xml, LESS and other code.

Notice there are still styles to restore/fix and LESS to improve.
2017-05-04 12:07:30 +02:00

146 lines
4.9 KiB
JavaScript

odoo.define('lunch.tests', function (require) {
"use strict";
var FormView = require('web.FormView');
var testUtils = require('web.test_utils');
var createView = testUtils.createView;
QUnit.module('lunch', {
beforeEach: function () {
this.data = {
order: {
fields: {
previous_order_widget: {type: 'text'},
order_line_ids: {type: 'many2many', relation: 'order_line'}
},
records: [{
id: 1,
name: 'coucou',
}, {
id: 2,
name: 'coucou',
}, {
id: 11,
}],
},
order_line: {
fields: {
product_id: {type: 'many2one', relation: 'product'},
note: {type: 'text'},
price: {type: 'float'},
},
},
supplier: {
fields: {},
records: [{
id: 1,
display_name: "Coin Gourmant",
}, {
id: 2,
display_name: "Pizza Inn",
}]
},
product: {
fields: {},
records: [{
id: 1,
name: 'Pizza Margherita',
}],
}
};
},
}, function () {
QUnit.test("empty previous_order widget", function (assert) {
assert.expect(2);
var form = createView({
View: FormView,
arch: '<form>' +
'<sheet>' +
'<field name="previous_order_widget" widget="previous_order"/>' +
'<field name="order_line_ids"/>' +
'</sheet>' +
'</form>',
data: this.data,
model: 'order',
archs: {
"order_line,false,list": '<tree string="Orders">' +
'<field name="product_id"/>' +
'<field name="note"/>' +
'<field name="price"/>' +
'</tree>',
},
});
var widgetText = form.$('.o_field_widget[name="previous_order_widget"]').text();
assert.ok(widgetText.indexOf('This is the first time you order a meal') !== -1,
"the widget should display its no content text");
assert.strictEqual(form.$('.o_lunch_vignette').length, 0,
"there should be no vignette");
form.destroy();
});
QUnit.test("add an order line with previous_order widget", function (assert) {
assert.expect(4);
var form = createView({
View: FormView,
arch: '<form>' +
'<sheet>' +
'<field name="previous_order_widget" widget="previous_order"/>' +
'<field name="order_line_ids"/>' +
'</sheet>' +
'</form>',
data: this.data,
model: 'order',
mockRPC: function (route, args) {
if (args.method === 'default_get') {
return $.when({
previous_order_widget: '{' +
'"8": {' +
'"note": "coucou",' +
'"line_id": 8,' +
'"digits": [69, 2],' +
'"product_id": 1,' +
'"currency": "$",' +
'"supplier": "Pizza Inn",' +
'"position": "before",' +
'"price": 6.9,' +
'"product_name": "Pizza Margherita"' +
'}' +
'}'
});
}
return this._super.apply(this, arguments);
},
archs: {
"order_line,false,list": '<tree string="Orders">' +
'<field name="product_id"/>' +
'<field name="note"/>' +
'<field name="price"/>' +
'</tree>',
},
});
assert.strictEqual(form.$('.o_list_view tr.o_data_row').length, 0,
"there should be no row in the one2many list");
assert.strictEqual(form.$('.o_lunch_vignette').length, 1,
"there should be a vignette");
// add an order
form.$('.o_lunch_vignette .o_add_button').click();
assert.strictEqual(form.$('.o_list_view tr.o_data_row').length, 1,
"there should be one new row in the one2many list");
assert.strictEqual(form.$('.o_list_view tr.o_data_row').text(), "Pizza Margheritacoucou6.90",
"the line should contain the correct data");
form.destroy();
});
});
});