summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-03-13 08:33:37 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commite7e60331cfb94e9400bc85873ac4753fe0e523cc (patch)
tree2c2f8428ecbb63c0cfde97015509536de925f362
parent29cd7154e66a30fb656b88e16b4301d17fa7d958 (diff)
[REF] web: test_utils: export removeSrcAttribute()
So that it can be used in every tests, not only those using createView. Note: it would be nice to automatically call this function in addMockEnvironment().
-rw-r--r--addons/web/static/test/helpers/test_utils.js35
1 files changed, 23 insertions, 12 deletions
diff --git a/addons/web/static/test/helpers/test_utils.js b/addons/web/static/test/helpers/test_utils.js
index 28fce6140c3..17c50cd7cf4 100644
--- a/addons/web/static/test/helpers/test_utils.js
+++ b/addons/web/static/test/helpers/test_utils.js
@@ -132,17 +132,9 @@ function createAsyncView(params) {
var view = new params.View(fields_view.arch, fields_view.fields, viewOptions);
- // remove src attribute on images and iframes to remove not found error in tests
- function removeSrcAttribute () {
- $('img, iframe[src]', this).each(function () {
- var src = $(this).attr('src');
- if (src[0] !== '#') {
- $(this).attr('src', '#test:' + $(this).attr('src'));
- widget._rpc(src).exec();
- }
- });
- }
- $('#qunit-fixture').on('DOMNodeInserted', removeSrcAttribute);
+ $('#qunit-fixture').on('DOMNodeInserted.removeSRC', function () {
+ removeSrcAttribute($(this), widget);
+ });
if (params.with_modifiers) {
_.each(params.with_modifiers, function (modifier, name) {
@@ -170,7 +162,7 @@ function createAsyncView(params) {
// when it will be called the second time (by its parent)
delete view.destroy;
widget.destroy();
- $('#qunit-fixture').off('DOMNodeInserted', removeSrcAttribute);
+ $('#qunit-fixture').off('DOMNodeInserted.removeSRC');
};
return view.appendTo($view_manager).then(function () {
view.$el.on('click', 'a', function (ev) {
@@ -388,6 +380,24 @@ function triggerMouseEvent($el, type) {
$el.trigger(e);
}
+/**
+ * Removes the src attribute on images and iframes to prevent not found errors,
+ * and optionally triggers an rpc with the src url as route on a widget.
+ *
+ * @param {JQueryElement} $el
+ * @param {[Widget]} widget the widget on which the rpc should be performed
+ */
+function removeSrcAttribute($el, widget) {
+ $el.find('img, iframe[src]').each(function () {
+ var src = $(this).attr('src');
+ if (src[0] !== '#') {
+ $(this).attr('src', '#test:' + $(this).attr('src'));
+ if (widget) {
+ widget._rpc(src).exec();
+ }
+ }
+ });
+}
return session.is_bound.then(function () {
setTimeout(function () {
@@ -404,6 +414,7 @@ return session.is_bound.then(function () {
addMockEnvironment: addMockEnvironment,
dragAndDrop: dragAndDrop,
triggerMouseEvent: triggerMouseEvent,
+ removeSrcAttribute: removeSrcAttribute,
};
});