From 8fe49cf3caee9cbd2a13a033a8b81850db0ab4e7 Mon Sep 17 00:00:00 2001 From: ddm Date: Thu, 12 Dec 2013 10:43:06 +0100 Subject: [PATCH] [IMP] Improve resume for automated tests bzr revid: ddm@openerp.com-20131212094306-marvfv7zewlghiii --- addons/website/static/src/js/website.tour.js | 50 +++++++++++++++++++------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/addons/website/static/src/js/website.tour.js b/addons/website/static/src/js/website.tour.js index e09366d..2abeec9 100644 --- a/addons/website/static/src/js/website.tour.js +++ b/addons/website/static/src/js/website.tour.js @@ -217,28 +217,54 @@ }, }); - var TestConsole = website.TestConsole = { + var TestConsole = openerp.Class.extend({ tests: [], + editor: null, + init: function (editor) { + if (!editor) { + throw new Error("Editor cannot be null or undefined"); + } + this.editor = editor; + }, test: function (id) { return _.find(this.tests, function (tour) { return tour.id === id; }); }, + snippetSelector: function (snippetId) { + return '#oe_snippets div.oe_snippet[data-snippet-id="'+snippetId+'"] .oe_snippet_thumbnail'; + }, + snippetThumbnail: function (snippetId) { + return $(this.snippetSelector(snippetId)).first(); + }, dragAndDropSnippet: function (snippetId) { - var selector = '#oe_snippets div.oe_snippet[data-snippet-id="'+snippetId+'"] .oe_snippet_thumbnail'; - var $thumbnail = $(selector).first(); - var thumbnailPosition = $thumbnail.position(); - $thumbnail.trigger($.Event("mousedown", { which: 1, pageX: thumbnailPosition.left, pageY: thumbnailPosition.top })); - $thumbnail.trigger($.Event("mousemove", { which: 1, pageX: thumbnailPosition.left, pageY: thumbnailPosition.top+500 })); - var $dropZone = $(".oe_drop_zone").first(); - var dropPosition = $dropZone.position(); - $dropZone.trigger($.Event("mouseup", { which: 1, pageX: dropPosition.left, pageY: dropPosition.top })); + function actualDragAndDrop ($thumbnail) { + var thumbnailPosition = $thumbnail.position(); + $thumbnail.trigger($.Event("mousedown", { which: 1, pageX: thumbnailPosition.left, pageY: thumbnailPosition.top })); + $thumbnail.trigger($.Event("mousemove", { which: 1, pageX: thumbnailPosition.left, pageY: thumbnailPosition.top+500 })); + var $dropZone = $(".oe_drop_zone").first(); + var dropPosition = $dropZone.position(); + $dropZone.trigger($.Event("mouseup", { which: 1, pageX: dropPosition.left, pageY: dropPosition.top })); + } + if (this.snippetThumbnail(snippetId).length === 0) { + this.editor.on('rte:ready', this, function () { + actualDragAndDrop(this.snippetThumbnail(snippetId)); + }); + } else { + actualDragAndDrop(this.snippetThumbnail(snippetId)); + } }, - }; + }); website.EditorBar.include({ tours: [], + init: function () { + var result = this._super(); + website.TestConsole = new TestConsole(this); + return result; + }, start: function () { + $('.tour-backdrop').click(function (e) { e.stopImmediatePropagation(); e.preventDefault(); @@ -288,7 +314,7 @@ }); var $element = $(step.element); if (step.snippet && step.trigger === 'drag') { - TestConsole.dragAndDropSnippet(step.snippet); + website.TestConsole.dragAndDropSnippet(step.snippet); } else if (step.trigger.id === 'change') { var currentValue = $element.val(); var options = $element[0].options; @@ -322,7 +348,7 @@ window.localStorage.removeItem(testId); }, }; - TestConsole.tests.push(test); + website.TestConsole.tests.push(test); if (window.localStorage.getItem(testId)) { test.run(); } -- 1.7.10.4