diff options
Diffstat (limited to 'addons/web/static/tests/core/widget_tests.js')
| -rw-r--r-- | addons/web/static/tests/core/widget_tests.js | 99 |
1 files changed, 53 insertions, 46 deletions
diff --git a/addons/web/static/tests/core/widget_tests.js b/addons/web/static/tests/core/widget_tests.js index 0eb4192c4a1..440cc97b524 100644 --- a/addons/web/static/tests/core/widget_tests.js +++ b/addons/web/static/tests/core/widget_tests.js @@ -2,7 +2,6 @@ odoo.define('web.widget_tests', function (require) { "use strict"; var AjaxService = require('web.AjaxService'); -var concurrency = require('web.concurrency'); var core = require('web.core'); var QWeb = require('web.QWeb'); var Widget = require('web.Widget'); @@ -86,8 +85,6 @@ QUnit.module('core', {}, function () { w.destroy(); }); - - QUnit.test('renderElement, no template, default', function (assert) { assert.expect(7); @@ -206,7 +203,7 @@ QUnit.module('core', {}, function () { widget.destroy(); }); - QUnit.test('repeated', function (assert) { + QUnit.test('repeated', async function (assert) { assert.expect(4); var $fix = $( "#qunit-fixture"); @@ -222,17 +219,16 @@ QUnit.module('core', {}, function () { }))(); widget.value = 42; - return widget.appendTo($fix) - .done(function () { + await widget.appendTo($fix) + .then(function () { assert.strictEqual($fix.find('p').text(), '42', "DOM fixture should contain initial value"); assert.strictEqual(widget.$el.text(), '42', "should set initial value"); widget.value = 36; widget.renderElement(); assert.strictEqual($fix.find('p').text(), '36', "DOM fixture should use new value"); assert.strictEqual(widget.$el.text(), '36', "should set new value"); - }).always(function () { - widget.destroy(); }); + widget.destroy(); }); @@ -274,7 +270,7 @@ QUnit.module('core', {}, function () { }); - QUnit.test('delegate', function (assert) { + QUnit.test('delegate', async function (assert) { assert.expect(5); var a = []; @@ -292,9 +288,9 @@ QUnit.module('core', {}, function () { }))(); widget.renderElement(); - widget.$el.click(); - widget.$('li:eq(3)').click(); - widget.$('input:last').val('foo').change(); + await testUtils.dom.click(widget.$el, {allowInvisible: true}); + await testUtils.dom.click(widget.$('li:eq(3)'), {allowInvisible: true}); + await testUtils.fields.editAndTrigger(widget.$('input:last'), 'foo', 'change'); for(var i=0; i<3; ++i) { assert.ok(a[i], "should pass test " + i); @@ -302,7 +298,7 @@ QUnit.module('core', {}, function () { widget.destroy(); }); - QUnit.test('undelegate', function (assert) { + QUnit.test('undelegate', async function (assert) { assert.expect(4); var clicked = false; @@ -316,13 +312,13 @@ QUnit.module('core', {}, function () { widget.renderElement(); widget.$el.on('click', 'li', function () { newclicked = true; }); - widget.$('li').click(); + await testUtils.dom.clickFirst(widget.$('li'), {allowInvisible: true}); assert.ok(clicked, "should trigger bound events"); assert.ok(newclicked, "should trigger bound events"); clicked = newclicked = false; widget._undelegateEvents(); - widget.$('li').click(); + await testUtils.dom.clickFirst(widget.$('li'), {allowInvisible: true}); assert.ok(!clicked, "undelegate should unbind events delegated"); assert.ok(newclicked, "undelegate should only unbind events it created"); widget.destroy(); @@ -330,50 +326,54 @@ QUnit.module('core', {}, function () { QUnit.module('Widget, and async stuff'); - QUnit.test("alive(alive)", function (assert) { + QUnit.test("alive(alive)", async function (assert) { assert.expect(1); var widget = new (Widget.extend({})); - return concurrency.asyncWhen(widget.start()) - .then(function () { return widget.alive(concurrency.asyncWhen()); }) - .then(function () { assert.ok(true); }) - .always(function () { widget.destroy(); }); + await widget.start() + .then(function () {return widget.alive(Promise.resolve()) ;}) + .then(function () { assert.ok(true); }); + + widget.destroy(); }); QUnit.test("alive(dead)", function (assert) { assert.expect(1); var widget = new (Widget.extend({})); - return $.Deferred(function (d) { - concurrency.asyncWhen(widget.start()) + return new Promise(function (resolve, reject) { + widget.start() .then(function () { // destroy widget widget.destroy(); - var promise = concurrency.asyncWhen(); + var promise = Promise.resolve(); // leave time for alive() to do its stuff promise.then(function () { - return concurrency.asyncWhen(); + return Promise.resolve(); }).then(function () { assert.ok(true); - d.resolve(); + resolve(); }); // ensure that widget.alive() refuses to resolve or reject return widget.alive(promise); - }).always(function () { - d.reject(); + }).then(function () { + reject(); + assert.ok(false, "alive() should not terminate by default"); + }).catch(function() { + reject(); assert.ok(false, "alive() should not terminate by default"); }); }); }); - QUnit.test("alive(alive, true)", function (assert) { + QUnit.test("alive(alive, true)", async function (assert) { assert.expect(1); var widget = new (Widget.extend({})); - return concurrency.asyncWhen(widget.start()) - .then(function () { return widget.alive(concurrency.asyncWhen(), true) }) - .then(function () { assert.ok(true); }) - .always(function () { widget.destroy(); }); + await widget.start() + .then(function () { return widget.alive(Promise.resolve(), true); }) + .then(function () { assert.ok(true); }); + widget.destroy(); }); QUnit.test("alive(dead, true)", function (assert) { @@ -382,11 +382,11 @@ QUnit.module('core', {}, function () { var widget = new (Widget.extend({})); - concurrency.asyncWhen(widget.start()) + widget.start() .then(function () { // destroy widget widget.destroy(); - return widget.alive(concurrency.asyncWhen(), true); + return widget.alive(Promise.resolve(), true); }).then(function () { assert.ok(false, "alive(p, true) should fail its promise"); done(); @@ -396,7 +396,7 @@ QUnit.module('core', {}, function () { }); }); - QUnit.test("calling _rpc on destroyed widgets", function (assert) { + QUnit.test("calling _rpc on destroyed widgets", async function (assert) { assert.expect(3); var def; @@ -404,7 +404,7 @@ QUnit.module('core', {}, function () { testUtils.mock.addMockEnvironment(parent, { session: { rpc: function () { - def = $.Deferred(); + def = testUtils.makeTestPromise(); def.abort = def.reject; return def; }, @@ -419,23 +419,30 @@ QUnit.module('core', {}, function () { assert.ok(true, "The ajax call should be resolve"); }); def.resolve(); + await testUtils.nextMicrotaskTick(); def = null; - widget._rpc({route: '/a/route'}).always(function () { + widget._rpc({route: '/a/route'}).then(function () { throw Error("Calling _rpc on a destroyed widget should return a " + - "deferred that is never resolved nor rejected"); + "promise that remains pending forever"); + }).catch(function () { + throw Error("Calling _rpc on a destroyed widget should return a " + + "promise that remains pending forever"); }); widget.destroy(); def.resolve(); + await testUtils.nextMicrotaskTick(); def = null; - widget._rpc({route: '/a/route'}).always(function () { + widget._rpc({route: '/a/route'}).then(function () { + throw Error("Calling _rpc on a destroyed widget should return a " + + "promise that remains pending forever"); + }).catch(function () { throw Error("Calling _rpc on a destroyed widget should return a " + - "deferred that is never resolved nor rejected"); + "promise that remains pending forever"); }); - assert.ok(!def, - "The trigger_up is not performed and the call returns a deferred "+ - "never resolved nor rejected"); + assert.ok(!def, "trigger_up is not performed and the call returns a " + + "promise that remains pending forever"); assert.ok(true, "there should be no crash when calling _rpc on a destroyed widget"); @@ -444,12 +451,12 @@ QUnit.module('core', {}, function () { QUnit.test('start is not called when widget is destroyed', function (assert) { assert.expect(0); - var slowWillStartDef = $.Deferred(); + var slowWillStartPromise = testUtils.makeTestPromise(); var $fix = $( "#qunit-fixture"); var widget = new (Widget.extend({ willStart: function () { - return slowWillStartDef; + return slowWillStartPromise; }, start: function () { throw new Error('Should not call start method'); @@ -458,7 +465,7 @@ QUnit.module('core', {}, function () { widget.appendTo($fix); widget.destroy(); - slowWillStartDef.resolve(); + slowWillStartPromise.resolve(); }); }); |
