summaryrefslogtreecommitdiff
path: root/addons/mrp/static/tests
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/mrp/static/tests
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/mrp/static/tests')
-rw-r--r--addons/mrp/static/tests/mrp_document_kanban_tests.js172
-rw-r--r--addons/mrp/static/tests/mrp_tests.js133
2 files changed, 305 insertions, 0 deletions
diff --git a/addons/mrp/static/tests/mrp_document_kanban_tests.js b/addons/mrp/static/tests/mrp_document_kanban_tests.js
new file mode 100644
index 00000000..366bb1bd
--- /dev/null
+++ b/addons/mrp/static/tests/mrp_document_kanban_tests.js
@@ -0,0 +1,172 @@
+odoo.define('mrp.document_kanban_tests', function (require) {
+"use strict";
+
+const MrpDocumentsKanbanView = require('mrp.MrpDocumentsKanbanView');
+const MrpDocumentsKanbanController = require('mrp.MrpDocumentsKanbanController');
+const testUtils = require('web.test_utils');
+
+const createView = testUtils.createView;
+
+QUnit.module('Views', {}, function () {
+
+QUnit.module('MrpDocumentsKanbanView', {
+ beforeEach: function () {
+ this.ORIGINAL_CREATE_XHR = MrpDocumentsKanbanController.prototype._createXHR;
+ this.patchDocumentXHR = (mockedXHRs, customSend) => {
+ MrpDocumentsKanbanController.prototype._createXhr = () => {
+ const xhr = {
+ upload: new window.EventTarget(),
+ open() { },
+ send(data) { customSend && customSend(data); },
+ };
+ mockedXHRs.push(xhr);
+ return xhr;
+ };
+ };
+ this.data = {
+ 'mrp.document': {
+ fields: {
+ name: {string: "Name", type: 'char', default: ' '},
+ priority: {string: 'priority', type: 'selection',
+ selection: [['0', 'Normal'], ['1', 'Low'], ['2', 'High'], ['3', 'Very High']]},
+ },
+ records: [
+ {id: 1, name: 'test1', priority: 2},
+ {id: 4, name: 'test2', priority: 1},
+ {id: 3, name: 'test3', priority: 3},
+ ],
+ },
+ };
+ },
+ afterEach() {
+ MrpDocumentsKanbanController.prototype._createXHR = this.ORIGINAL_CREATE_XHR;
+ },
+}, function () {
+ QUnit.test('MRP documents kanban basic rendering', async function (assert) {
+ assert.expect(6);
+
+ const kanban = await createView({
+ View: MrpDocumentsKanbanView,
+ model: 'mrp.document',
+ data: this.data,
+ arch: '<kanban><templates><t t-name="kanban-box">' +
+ '<div>' +
+ '<field name="name"/>' +
+ '</div>' +
+ '</t></templates></kanban>',
+ });
+
+ assert.ok(kanban, "kanban is created");
+ assert.ok(kanban.$buttons.find('.o_mrp_documents_kanban_upload'),
+ "should have upload button in kanban buttons");
+ assert.containsN(kanban, '.o_kanban_view .o_kanban_record:not(.o_kanban_ghost)', 3,
+ "should have 3 records in the renderer");
+ // check view layout
+ assert.hasClass(kanban.$('.o_kanban_view'), 'o_mrp_documents_kanban_view',
+ "should have classname 'o_mrp_documents_kanban_view'");
+ // check control panel buttons
+ assert.containsN(kanban, '.o_cp_buttons .btn-primary', 1,
+ "should have only 1 primary button i.e. Upload button");
+ assert.strictEqual(kanban.$('.o_cp_buttons .btn-primary:first').text().trim(), 'Upload',
+ "should have a primary 'Upload' button");
+
+ kanban.destroy();
+ });
+
+ QUnit.test('mrp: upload multiple files', async function (assert) {
+ assert.expect(4);
+
+ const file1 = await testUtils.file.createFile({
+ name: 'text1.txt',
+ content: 'hello, world',
+ contentType: 'text/plain',
+ });
+ const file2 = await testUtils.file.createFile({
+ name: 'text2.txt',
+ content: 'hello, world',
+ contentType: 'text/plain',
+ });
+ const file3 = await testUtils.file.createFile({
+ name: 'text3.txt',
+ content: 'hello, world',
+ contentType: 'text/plain',
+ });
+
+ const mockedXHRs = [];
+ this.patchDocumentXHR(mockedXHRs, data => assert.step('xhrSend'));
+
+ const kanban = await createView({
+ View: MrpDocumentsKanbanView,
+ model: 'mrp.document',
+ data: this.data,
+ arch: '<kanban><templates><t t-name="kanban-box">' +
+ '<div>' +
+ '<field name="name"/>' +
+ '</div>' +
+ '</t></templates></kanban>',
+ });
+
+ kanban.trigger_up('upload_file', {files: [file1]});
+ await testUtils.nextTick();
+ assert.verifySteps(['xhrSend']);
+
+ kanban.trigger_up('upload_file', {files: [file2, file3]});
+ await testUtils.nextTick();
+ assert.verifySteps(['xhrSend']);
+
+ kanban.destroy();
+ });
+
+ QUnit.test('mrp: upload progress bars', async function (assert) {
+ assert.expect(4);
+
+ const file1 = await testUtils.file.createFile({
+ name: 'text1.txt',
+ content: 'hello, world',
+ contentType: 'text/plain',
+ });
+
+ const mockedXHRs = [];
+ this.patchDocumentXHR(mockedXHRs, data => assert.step('xhrSend'));
+
+ const kanban = await createView({
+ View: MrpDocumentsKanbanView,
+ model: 'mrp.document',
+ data: this.data,
+ arch: '<kanban><templates><t t-name="kanban-box">' +
+ '<div>' +
+ '<field name="name"/>' +
+ '</div>' +
+ '</t></templates></kanban>',
+ });
+
+ kanban.trigger_up('upload_file', {files: [file1]});
+ await testUtils.nextTick();
+ assert.verifySteps(['xhrSend']);
+
+ const progressEvent = new Event('progress', { bubbles: true });
+ progressEvent.loaded = 250000000;
+ progressEvent.total = 500000000;
+ progressEvent.lengthComputable = true;
+ mockedXHRs[0].upload.dispatchEvent(progressEvent);
+ assert.strictEqual(
+ kanban.$('.o_file_upload_progress_text_left').text(),
+ "Uploading... (50%)",
+ "the current upload progress should be at 50%"
+ );
+
+ progressEvent.loaded = 350000000;
+ mockedXHRs[0].upload.dispatchEvent(progressEvent);
+ assert.strictEqual(
+ kanban.$('.o_file_upload_progress_text_right').text(),
+ "(350/500Mb)",
+ "the current upload progress should be at (350/500Mb)"
+ );
+
+ kanban.destroy();
+ });
+});
+
+});
+
+});
diff --git a/addons/mrp/static/tests/mrp_tests.js b/addons/mrp/static/tests/mrp_tests.js
new file mode 100644
index 00000000..f05a5b42
--- /dev/null
+++ b/addons/mrp/static/tests/mrp_tests.js
@@ -0,0 +1,133 @@
+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 data = {
+ foo: {
+ fields: { duration: { string: "Duration", type: "float" } },
+ records: [{id: 1, duration:150.5}]
+ },
+ };
+ var form = await createView({
+ View: FormView,
+ model: 'foo',
+ data: 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([]);
+ }
+ return this._super.apply(this, arguments);
+ },
+ });
+
+ assert.strictEqual(form.$('.o_field_widget[name="duration"]').text(), "150:30",
+ "the timer should be correctly set");
+
+ form.destroy();
+ });
+
+ QUnit.test("embed_viewer rendering in form view", async function (assert) {
+ assert.expect(8);
+ var data = {
+ foo: {
+ fields: { char_url: { string: "URL", type: "char" } },
+ records: [{ id: 1 }]
+ },
+ };
+
+ var form = await createView({
+ View: FormView,
+ model: 'foo',
+ data: data,
+ arch:
+ '<form>' +
+ '<field name="char_url" widget="embed_viewer"/>' +
+ '</form>',
+ res_id: 1,
+ mockRPC: function (route) {
+ if (route === ('http://example.com')) {
+ return Promise.resolve();
+ }
+ return this._super.apply(this, arguments);
+ }
+ });
+
+ assert.isNotVisible(form.$('iframe.o_embed_iframe'), "there should be an invisible iframe readonly mode");
+ assert.strictEqual(_.has(form.$('iframe.o_embed_iframe')[0].attributes, "src"), false,
+ "src attribute is not set if there are no values");
+ await testUtils.form.clickEdit(form);
+ assert.isNotVisible(form.$('iframe.o_embed_iframe'), "there should be an invisible iframe in edit mode");
+ await testUtils.fields.editAndTrigger(form.$('.o_field_char'), 'http://example.com', ['input', 'change', 'focusout']);
+ assert.strictEqual(form.$('iframe.o_embed_iframe').attr('src'), 'http://example.com',
+ "src should updated on the iframe");
+ assert.isVisible(form.$('iframe.o_embed_iframe'), "there should be a visible iframe in edit mode");
+ await testUtils.form.clickSave(form);
+ assert.isVisible(form.$('iframe.o_embed_iframe'), "there should be a visible iframe in readonly mode");
+ assert.strictEqual(form.$('iframe.o_embed_iframe').attr('data-src'), 'http://example.com',
+ "should have updated src in readonly mode");
+
+ // In readonly mode, we are not displaying the URL, only iframe will be there.
+ assert.strictEqual(form.$('.iframe.o_embed_iframe').siblings().length, 0,
+ "there shouldn't be any siblings of iframe in readonly mode");
+
+ form.destroy();
+ });
+});
+});