summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorAlexandre Kühn <aku@odoo.com>2018-02-20 14:17:57 +0100
committerAlexandre Kühn <aku@odoo.com>2018-02-20 14:17:57 +0100
commita0a6811ff9efef9e4fc46a5e84ddc71db2a68b1c (patch)
treebb37d4f7f7f91ae80ea52f7be8432ba6add7f240 /addons/web/static
parentae2fa4d0d67ea7b7e7452fe70405ad23cec0cd55 (diff)
parent2b17b7e83d997658392d310ad176c0367c8a7949 (diff)
[MERGE] mail,web: fix various bugs from recent JS mail refactoring
Revision on a recent JS refactoring: https://github.com/odoo/odoo/commit/02ec09cb1c3e2d7bc7968f40c18f2208d7f3f498 This merge contains several fixes from the above refactoring commit. It also adds tests on discuss, as one of the purpose of the refactoring was to test this widget.
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/tests/helpers/test_utils.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/addons/web/static/tests/helpers/test_utils.js b/addons/web/static/tests/helpers/test_utils.js
index a4f6531d075..6f3b3ef4549 100644
--- a/addons/web/static/tests/helpers/test_utils.js
+++ b/addons/web/static/tests/helpers/test_utils.js
@@ -23,6 +23,8 @@ var Widget = require('web.Widget');
var DebouncedField = basic_fields.DebouncedField;
+var originalWindowGetSelection; // cached replaced originalGetSelection
+
/**
* intercepts an event bubbling up the widget hierarchy. The event intercepted
* must be a "custom event", i.e. an event generated by the method 'trigger_up'.
@@ -726,6 +728,50 @@ function patch (target, props) {
}
}
/**
+ * In Phantomjs, there is a crash when calling window.getSelection
+ * in order for the tests to work, for the specific test that uses it, replace
+ * the default window.getSelection by a mock
+ *
+ * usage:
+ * QUnit.test('...',function(done){
+ * testUtils.patchWindowGetSelection();
+ *
+ * // do something that needs to use window.getSelection()
+ * assert.strictEqual(....);
+ *
+ * // restore the original function
+ * testUtils.unpatchWindowGetSelection();
+ *
+ * // finish the test
+ * done();
+ * })
+ */
+
+function patchWindowGetSelection() {
+ originalWindowGetSelection = window.getSelection;
+ window.getSelection = function () {
+ return {
+ removeAllRanges: function () {},
+ addRange: function (range) {},
+ getRangeAt: function (index) {
+ return {
+ startOffset : 0
+ };
+ },
+ anchorNode: {
+ parentNode: {
+ childNodes: [{
+ outerHTML: "@",
+ nodeType: 3,
+ textContent: '@',
+ }],
+ },
+ },
+ };
+ };
+}
+
+/**
* Unpatches a given Class or Object.
*
* @param {Class|Object} target
@@ -749,6 +795,14 @@ function unpatch(target) {
delete target.__patchID;
}
+/**
+ * after using patchWindowGetSelection, at the end of your test
+ * you must restore the default function so there is no impact to the other tests
+ */
+function unpatchWindowGetSelection() {
+ window.getSelection = originalWindowGetSelection;
+}
+
// Loading static files cannot be properly simulated when their real content is
// really needed. This is the case for static XML files so we load them here,
// before starting the qunit test suite.
@@ -775,11 +829,13 @@ return $.when(
intercept: intercept,
observe: observe,
patch: patch,
+ patchWindowGetSelection: patchWindowGetSelection,
removeSrcAttribute: removeSrcAttribute,
triggerKeypressEvent: triggerKeypressEvent,
triggerMouseEvent: triggerMouseEvent,
triggerPositionalMouseEvent: triggerPositionalMouseEvent,
unpatch: unpatch,
+ unpatchWindowGetSelection: unpatchWindowGetSelection,
};
});