Part of task 1896658 Co-authored-by: Aaron Bohy <aab@odoo.com> Co-authored-by: Christophe Matthieu <chm@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com> Co-authored-by: David Monjoie <dmo@odoo.com> Co-authored-by: Martin Geubelle <mge@odoo.com> Co-authored-by: svs-odoo <svs@odoo.com> Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
88 lines
2.8 KiB
JavaScript
88 lines
2.8 KiB
JavaScript
odoo.define('mrp.tests', function (require) {
|
|
"use strict";
|
|
|
|
var FormView = require('web.FormView');
|
|
var testUtils = require("web.test_utils");
|
|
|
|
var createView = testUtils.createView;
|
|
|
|
QUnit.module('mrp', {
|
|
beforeEach: function () {
|
|
this.data = {
|
|
partner: {
|
|
fields: {
|
|
state: {
|
|
string: "State",
|
|
type: "selection",
|
|
selection: [['waiting', 'Waiting'], ['chilling', 'Chilling']],
|
|
},
|
|
duration: {string: "Duration", type: "float"},
|
|
},
|
|
records: [{
|
|
id: 1,
|
|
state: 'waiting',
|
|
duration: 6000,
|
|
}],
|
|
onchanges: {},
|
|
},
|
|
};
|
|
},
|
|
}, function () {
|
|
|
|
QUnit.test("bullet_state: basic rendering", async function (assert) {
|
|
assert.expect(2);
|
|
|
|
var form = await createView({
|
|
View: FormView,
|
|
model: 'partner',
|
|
data: this.data,
|
|
res_id: 1,
|
|
arch:
|
|
'<form>' +
|
|
'<field name="state" widget="bullet_state" options="{\'classes\': {\'waiting\': \'danger\'}}"/>' +
|
|
'</form>',
|
|
});
|
|
|
|
assert.strictEqual(form.$('.o_field_widget').text(), "Waiting Materials",
|
|
"the widget should be correctly named");
|
|
assert.containsOnce(form, '.o_field_widget .badge-danger',
|
|
"the badge should be danger");
|
|
|
|
form.destroy();
|
|
});
|
|
|
|
QUnit.test("mrp_time_counter: basic rendering", async function (assert) {
|
|
assert.expect(2);
|
|
|
|
var form = await createView({
|
|
View: FormView,
|
|
model: 'partner',
|
|
data: this.data,
|
|
res_id: 1,
|
|
arch:
|
|
'<form>' +
|
|
'<field name="duration" widget="mrp_time_counter"/>' +
|
|
'</form>',
|
|
mockRPC: function (route, args) {
|
|
if (args.method === 'search_read' && args.model === 'mrp.workcenter.productivity') {
|
|
assert.ok(true, "the widget should fetch the mrp.workcenter.productivity");
|
|
return Promise.resolve([{
|
|
date_start: '2017-01-01 08:00:00',
|
|
date_end: '2017-01-01 10:00:00',
|
|
}, {
|
|
date_start: '2017-01-01 12:00:00',
|
|
date_end: '2017-01-01 12:30:00',
|
|
}]);
|
|
}
|
|
return this._super.apply(this, arguments);
|
|
},
|
|
});
|
|
|
|
assert.strictEqual(form.$('.o_field_widget[name="duration"]').text(), "02:30:00",
|
|
"the timer should be correctly set");
|
|
|
|
form.destroy();
|
|
});
|
|
});
|
|
});
|