diff options
| author | Dharmraj Jhala <dja@openerp.com> | 2017-05-11 17:15:15 +0530 |
|---|---|---|
| committer | Géry Debongnie <ged@odoo.com> | 2017-07-12 13:43:08 +0200 |
| commit | 4330ea02676a4afd88707bb463a007e7de3c8686 (patch) | |
| tree | f547124a18fd30e09433a65cd9aa7b5a6645131a /addons/web/static/tests | |
| parent | 578edf73b9f637b0d27708c511b542a27bd7a3b8 (diff) | |
[ADD] web, *: add rainbowification
This commit introduces the 'rainbowification' feature to the web client
(and to some affected addons). This feature is essentially a way to
display a nice friendly message when some business event happens. For
example, a encouraging message is displayed when the user clear her/his
inbox, or when a salesman closes a deal.
The mechanism currently only displays a 'rainbowman', but could be
extended later to add other kind of animation.
There are a few different ways to display a 'rainbowman':
- any JS code can simply trigger_up an event ('show_effect') with some
options: for example
this.trigger_up('show_effect', {
type: 'rainbow_man',
fadeout: 'no',
message: $done,
click_close: false,
});
- an action returned by the server can have an 'effect' key, with some
options
- the do_execute_action method accepts a 'effect' option. This is
useful when one wants to specify a rainbow on an action button in a
form view
Joint work with: dbh <dbh@odoo.com>, ged <ged@odoo.com>
Diffstat (limited to 'addons/web/static/tests')
| -rw-r--r-- | addons/web/static/tests/views/form_tests.js | 63 | ||||
| -rw-r--r-- | addons/web/static/tests/widgets/rainbow_man_tests.js | 37 |
2 files changed, 64 insertions, 36 deletions
diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index e4940f5fd2d..435da41ea55 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -4,6 +4,8 @@ odoo.define('web.form_tests', function (require) { var concurrency = require('web.concurrency'); var core = require('web.core'); var FormView = require('web.FormView'); +var pyeval = require('web.pyeval'); +var RainbowMan = require('web.rainbow_man'); var testUtils = require('web.test_utils'); var _t = core._t; @@ -5200,42 +5202,6 @@ QUnit.module('Views', { form.destroy(); }); - QUnit.test('wow effect', function (assert) { - assert.expect(3); - - this.data.partner.fields.model_name = { string: "Model name", type: "char" }; - - var clickCount = 0; - var form = createView({ - View: FormView, - model: 'partner', - data: this.data, - arch: '<form string="Partners">' + - '<button name="test" string="Mark Won" type="object" class="o_wow"/>' + - '</form>', - intercepts: { - execute_action: function (event) { - if (clickCount === 0) { - event.data.on_success(); - } else { - event.data.on_fail(); - } - clickCount++; - }, - show_wow: function () { - assert.step('wow'); - }, - }, - }); - - form.$('button.o_wow').click(); - assert.verifySteps(['wow']); - form.$('button.o_wow').click(); - assert.verifySteps(['wow']); - - form.destroy(); - }); - QUnit.test('readonly fields are not sent when saving', function (assert) { assert.expect(6); @@ -5377,5 +5343,30 @@ QUnit.module('Views', { form.destroy(); }); + + QUnit.test('rainbowman attributes correctly passed on button click', function (assert) { + assert.expect(1); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form string="Partners">' + + '<header>' + + '<button name="action_won" string="Won" type="object" effect="{\'message\': \'Congrats!\'}"/>' + + '</header>' + + '</form>', + intercepts: { + execute_action: function (event) { + var effectDescription = pyeval.py_eval(event.data.action_data.effect); + assert.deepEqual(effectDescription, {message: 'Congrats!'}, "should have correct effect description"); + } + } + }); + + form.$('.o_form_statusbar .btn-default').click(); + form.destroy(); + }); + }); }); diff --git a/addons/web/static/tests/widgets/rainbow_man_tests.js b/addons/web/static/tests/widgets/rainbow_man_tests.js new file mode 100644 index 00000000000..e9674ebc3fe --- /dev/null +++ b/addons/web/static/tests/widgets/rainbow_man_tests.js @@ -0,0 +1,37 @@ +odoo.define('web.rainbow_man_tests', function (require) { +"use strict"; + +var RainbowMan = require('web.rainbow_man'); + +QUnit.module('widgets', {}, function () { + +QUnit.module('RainbowMan', { + beforeEach: function () { + this.data = { + message: 'Congrats!', + click_close: false + }; + }, +}, function () { + + QUnit.test("rendering a rainbowman", function (assert) { + assert.expect(2); + + var $target = $("#qunit-fixture"); + + // Create and display rainbowman + var rainbowman = new RainbowMan(this.data); + rainbowman.appendTo($target); + + var $rainbow = rainbowman.$(".o_reward_rainbow"); + assert.strictEqual($rainbow.length, 1, + "Should have displayed rainbow effect"); + + assert.ok(rainbowman.$('.o_reward_msg_content').html() === 'Congrats!', + "Card on the rainbowman should display 'Congrats!' message"); + + rainbowman.destroy(); + }); +}); +}); +}); |
