From 4f168c8d2f5413969db0536002dbffc36a55d50f Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Fri, 13 Feb 2015 18:58:40 +0000 Subject: [PATCH] MDL-47494 ddmarker: Update dd qtype tests to use js_pending not fixed waits #14895 --- question/type/ddmarker/tests/behat/preview.feature | 2 -- .../moodle-qtype_ddmarker-dd-debug.js | 4 ++++ .../moodle-qtype_ddmarker-dd/moodle-qtype_ddmarker-dd-min.js | 4 ++-- .../moodle-qtype_ddmarker-dd/moodle-qtype_ddmarker-dd.js | 4 ++++ .../moodle-qtype_ddmarker-form-debug.js | 5 ++++- .../moodle-qtype_ddmarker-form-min.js | 2 +- .../moodle-qtype_ddmarker-form/moodle-qtype_ddmarker-form.js | 5 ++++- question/type/ddmarker/yui/src/ddmarker/js/ddmarker.js | 4 ++++ question/type/ddmarker/yui/src/form/js/form.js | 5 ++++- 9 files changed, 27 insertions(+), 8 deletions(-) diff --git a/question/type/ddmarker/tests/behat/preview.feature b/question/type/ddmarker/tests/behat/preview.feature index 5d949b86217..a4f345a6c81 100644 --- a/question/type/ddmarker/tests/behat/preview.feature +++ b/question/type/ddmarker/tests/behat/preview.feature @@ -28,7 +28,6 @@ Feature: Preview a drag-drop onto image question Scenario: Preview a question using the mouse. When I click on "Preview" "link" in the "Drag markers" "table_row" And I switch to "questionpreview" window - And I wait "2" seconds # Odd, but the
s go to nothing, not a space. And I drag "OU" to "340,228" in the drag and drop markers question And I drag "Railway station" to "252,195" in the drag and drop markers question @@ -42,7 +41,6 @@ Feature: Preview a drag-drop onto image question Scenario: Preview a question using the keyboard. When I click on "Preview" "link" in the "Drag markers" "table_row" And I switch to "questionpreview" window - And I wait "1" seconds And I type "up" "89" times on marker "Railway station" in the drag and drop markers question And I type "right" "21" times on marker "Railway station" in the drag and drop markers question And I press "Submit and finish" diff --git a/question/type/ddmarker/yui/build/moodle-qtype_ddmarker-dd/moodle-qtype_ddmarker-dd-debug.js b/question/type/ddmarker/yui/build/moodle-qtype_ddmarker-dd/moodle-qtype_ddmarker-dd-debug.js index 204c67fa0c6..2487de29c41 100644 --- a/question/type/ddmarker/yui/build/moodle-qtype_ddmarker-dd/moodle-qtype_ddmarker-dd-debug.js +++ b/question/type/ddmarker/yui/build/moodle-qtype_ddmarker-dd/moodle-qtype_ddmarker-dd-debug.js @@ -308,7 +308,10 @@ var DDMARKER_QUESTION = function() { * This is the code for question rendering. */ Y.extend(DDMARKER_QUESTION, M.qtype_ddmarker.dd_base_class, { + pendingid: '', initializer : function() { + this.pendingid = 'qtype_ddmarker-' + Math.random().toString(36).slice(2); // Random string. + M.util.js_pending(this.pendingid); this.doc = this.doc_structure(this); this.poll_for_image_load(null, false, 0, this.after_image_load); this.doc.bg_img().after('load', this.poll_for_image_load, this, @@ -316,6 +319,7 @@ Y.extend(DDMARKER_QUESTION, M.qtype_ddmarker.dd_base_class, { }, after_image_load : function () { this.redraw_drags_and_drops(); + M.util.js_complete(this.pendingid); Y.later(2000, this, this.redraw_drags_and_drops, [], true); }, clone_new_drag_item : function (draghome, itemno) { diff --git a/question/type/ddmarker/yui/build/moodle-qtype_ddmarker-dd/moodle-qtype_ddmarker-dd-min.js b/question/type/ddmarker/yui/build/moodle-qtype_ddmarker-dd/moodle-qtype_ddmarker-dd-min.js index 40ef3f541c1..c719e3ce651 100644 --- a/question/type/ddmarker/yui/build/moodle-qtype_ddmarker-dd/moodle-qtype_ddmarker-dd-min.js +++ b/question/type/ddmarker/yui/build/moodle-qtype_ddmarker-dd/moodle-qtype_ddmarker-dd-min.js @@ -1,2 +1,2 @@ -YUI.add("moodle-qtype_ddmarker-dd",function(e,t){var n="moodle-qtype_ddmarker-dd",r=function(){r.superclass.constructor.apply(this,arguments)};e.extend(r,e.Base,{doc:null,polltimer:null,afterimageloaddone:!1,graphics:null,poll_for_image_load:function(t,n,r,i){if(this.afterimageloaddone)return;var s=this.doc.bg_img().get("complete");n&&(s=s&&this.doc.bg_img().hasClass("constrained"));if(s)this.polltimer!==null&&(this.polltimer.cancel(),this.polltimer=null),this.doc.bg_img().detach("load",this.poll_for_image_load),r!==0?e.later(r,this,i):i.call(this),this.afterimageloaddone=!0;else if(this.polltimer===null){var o=[null,n,r,i];this.polltimer=e.later(1e3,this,this.poll_for_image_load,o,!0)}},doc_structure:function(){var t=e.one(this.get("topnode")),n=t.one("div.dragitems"),r=t.one("div.droparea");return{top_node:function(){return t},bg_img:function(){return t.one(".dropbackground")},load_bg_img:function(e){r.setContent(''),this.bg_img().on("load",this.on_image_load,this,"bg_image")},drag_items:function(){return n.all(".dragitem")},drag_items_for_choice:function(e){return n.all("span.dragitem.choice"+e)},drag_item_for_choice:function(e,t){return n.one("span.dragitem.choice"+e+".item"+t)},drag_item_being_dragged:function(e){return n.one("span.dragitem.beingdragged.choice"+e)},drag_item_home:function(e){return n.one("span.draghome.choice"+e)},drag_item_homes:function(){return n.all("span.draghome")},get_classname_numeric_suffix:function(e,t){var n=e.getAttribute("class");if(n!==""){var r=n.split(" ");for(var i=0;i'+t+""):this.doc.marker_texts().append(''+t+"")}var a="draw_shape_"+n;if(this[a]instanceof Function){var f=this[a](e,r,i);if(f!==null){var l=this.doc.top_node().one("div.ddarea div.markertexts span.markertext"+e);if(l!==null){l.setStyle("opacity","0.6"),f[0]-=l.get("offsetWidth")/2,f[1]-=l.get("offsetHeight")/2,l.setXY(this.convert_to_window_xy(f));var c=l.one("a");c!==null&&(c.once("click",function(e,t){var n=this.shapes[t].get("fill");n.opacity=1,this.shapes[t].set("fill",n)},this,e),c.set("tabIndex",0))}}}},draw_shape_circle:function(e,t,n){var r=t.match(/(\d+),(\d+);(\d+)/);if(r&&r.length===4){var i=[Number(r[1])-r[3],Number(r[2])-r[3]];if(this.coords_in_img(i)){var s=[Number(r[3])*2,Number(r[3])*2],o=this.graphics.addShape({type:"circle",width:s[0],height:s[1],fill:{color:n,opacity:"0.5"},stroke:{weight:1,color:"black"}});return o.setXY(this.convert_to_window_xy(i)),this.shapes[e]=o,[Number(r[1]),Number(r[2])]}}return null},draw_shape_rectangle:function(e,t,n){var r=t.match(/(\d+),(\d+);(\d+),(\d+)/);if(r&&r.length===5){var i=[Number(r[1]),Number(r[2])],s=[Number(r[3]),Number(r[4])];if(this.coords_in_img([i[0]+s[0],i[1]+s[1]])){var o=this.graphics.addShape({type:"rect",width:s[0],height:s[1],fill:{color:n,opacity:"0.5"},stroke:{weight:1,color:"black"}});return o.setXY(this.convert_to_window_xy(i)),this.shapes[e]=o,[Number(i[0])+s[0]/2,Number(i[1])+s[1]/2]}}return null},draw_shape_polygon:function(e,t,n){var r=t.split(";"),i=[];for(var s in r){var o=r[s].match(/^(\d+),(\d+)$/);o!==null&&this.coords_in_img([o[1],o[2]])&&(i[i.length]=[o[1],o[2]])}if(i.length>2){var u=this.graphics.addShape({type:"path",stroke:{weight:1,color:"black"},fill:{color:n,opacity:"0.5"}}),a=[0,0],f=[this.doc.bg_img().get("width"),this.doc.bg_img().get("height")];for(s=0;sthis.doc.bg_img().get("width")||e[1]>this.doc.bg_img().get("height")?!1:!0},constrain_to_bgimg:function(e){var t=this.convert_to_bg_img_xy(e);return t[0]=Math.max(0,t[0]),t[1]=Math.max(0,t[1]),t[0]=Math.min(this.doc.bg_img().get("width"),t[0]),t[1]=Math.min(this.doc.bg_img().get("height"),t[1]),this.convert_to_window_xy(t)},convert_to_bg_img_xy:function(e){return[Number(e[0])-this.doc.bg_img().getX()-1,Number(e[1])-this.doc.bg_img().getY()-1]},redraw_drags_and_drops:function(){this.doc.drag_items().each(function(e){e.addClass("unneeded")},this),this.doc.inputs_for_choices().each(function(e){var t=this.get_choiceno_for_node(e),n=this.get_coords(e),r=this.doc.drag_item_home(t);for(var i=0;i'),this.bg_img().on("load",this.on_image_load,this,"bg_image")},drag_items:function(){return n.all(".dragitem")},drag_items_for_choice:function(e){return n.all("span.dragitem.choice"+e)},drag_item_for_choice:function(e,t){return n.one("span.dragitem.choice"+e+".item"+t)},drag_item_being_dragged:function(e){return n.one("span.dragitem.beingdragged.choice"+e)},drag_item_home:function(e){return n.one("span.draghome.choice"+e)},drag_item_homes:function(){return n.all("span.draghome")},get_classname_numeric_suffix:function(e,t){var n=e.getAttribute("class");if(n!==""){var r=n.split(" ");for(var i=0;i'+t+""):this.doc.marker_texts().append(''+t+"")}var a="draw_shape_"+n;if(this[a]instanceof Function){var f=this[a](e,r,i);if(f!==null){var l=this.doc.top_node().one("div.ddarea div.markertexts span.markertext"+e);if(l!==null){l.setStyle("opacity","0.6"),f[0]-=l.get("offsetWidth")/2,f[1]-=l.get("offsetHeight")/2,l.setXY(this.convert_to_window_xy(f));var c=l.one("a");c!==null&&(c.once("click",function(e,t){var n=this.shapes[t].get("fill");n.opacity=1,this.shapes[t].set("fill",n)},this,e),c.set("tabIndex",0))}}}},draw_shape_circle:function(e,t,n){var r=t.match(/(\d+),(\d+);(\d+)/);if(r&&r.length===4){var i=[Number(r[1])-r[3],Number(r[2])-r[3]];if(this.coords_in_img(i)){var s=[Number(r[3])*2,Number(r[3])*2],o=this.graphics.addShape({type:"circle",width:s[0],height:s[1],fill:{color:n,opacity:"0.5"},stroke:{weight:1,color:"black"}});return o.setXY(this.convert_to_window_xy(i)),this.shapes[e]=o,[Number(r[1]),Number(r[2])]}}return null},draw_shape_rectangle:function(e,t,n){var r=t.match(/(\d+),(\d+);(\d+),(\d+)/);if(r&&r.length===5){var i=[Number(r[1]),Number(r[2])],s=[Number(r[3]),Number(r[4])];if(this.coords_in_img([i[0]+s[0],i[1]+s[1]])){var o=this.graphics.addShape({type:"rect",width:s[0],height:s[1],fill:{color:n,opacity:"0.5"},stroke:{weight:1,color:"black"}});return o.setXY(this.convert_to_window_xy(i)),this.shapes[e]=o,[Number(i[0])+s[0]/2,Number(i[1])+s[1]/2]}}return null},draw_shape_polygon:function(e,t,n){var r=t.split(";"),i=[];for(var s in r){var o=r[s].match(/^(\d+),(\d+)$/);o!==null&&this.coords_in_img([o[1],o[2]])&&(i[i.length]=[o[1],o[2]])}if(i.length>2){var u=this.graphics.addShape({type:"path",stroke:{weight:1,color:"black"},fill:{color:n,opacity:"0.5"}}),a=[0,0],f=[this.doc.bg_img().get("width"),this.doc.bg_img().get("height")];for(s=0;sthis.doc.bg_img().get("width")||e[1]>this.doc.bg_img().get("height")?!1:!0},constrain_to_bgimg:function(e){var t=this.convert_to_bg_img_xy(e);return t[0]=Math.max(0,t[0]),t[1]=Math.max(0,t[1]),t[0]=Math.min(this.doc.bg_img().get("width"),t[0]),t[1]=Math.min(this.doc.bg_img().get("height"),t[1]),this.convert_to_window_xy(t)},convert_to_bg_img_xy:function(e){return[Number(e[0])-this.doc.bg_img().getX()-1,Number(e[1])-this.doc.bg_img().getY()-1]},redraw_drags_and_drops:function(){this.doc.drag_items().each(function(e){e.addClass("unneeded")},this),this.doc.inputs_for_choices().each(function(e){var t=this.get_choiceno_for_node(e),n=this.get_coords(e),r=this.doc.drag_item_home(t);for(var i=0;i
'),this.doc=this.doc_structure(this),this.stop_selector_events(),this.set_options_for_drag_item_selectors(),this.setup_form_events(),e.later(500,this,this.update_drop_zones,[],!0),e.after(this.load_bg_image,M.form_filepicker,"callback",this),this.load_bg_image()},load_bg_image:function(){var t=this.fp.file("bgimage").href;if(t!==null){this.doc.load_bg_img(t);var n=new e.DD.Drop({node:this.doc.bg_img()});n.on("drop:hit",function(e){e.drag.get("node").setData("gooddrop",!0)}),this.afterimageloaddone=!1,this.doc.bg_img().on("load",this.constrain_image_size,this)}},constrain_image_size:function(e){var t=this.get("maxsizes").bgimage,n=Math.max(e.target.get("width")/t.width,e.target.get("height")/t.height);n>1&&e.target.set("width",Math.floor(e.target.get("width")/n)),e.target.addClass("constrained"),e.target.detach("load",this.constrain_image_size)},update_drop_zones:function(){this.graphics!==null&&this.graphics.destroy(),this.restart_colours(),this.graphics=new e.Graphic({render:"div.ddarea div.dropzones"});var t=this.form.get_form_value("nodropzone",[]);for(var n=0;n'+t[o]+"";s.append(u);var a=s.one('option[value="'+o+'"]');if(o===i[n])a.set("selected",!0);else if(o!==0){var f=this.form.get_form_value("drags",[o-1,"noofdrags"]);if(Number(f)!==0)for(var l in i)if(Number(i[l])===o){if(Number(f)===1){a.set("disabled",!0);break}f--}}}}},stop_selector_events:function(){e.all("fieldset#id_dropzoneheader select").detachAll()},setup_form_events:function(){e.all("fieldset#id_draggableitemheader input").on("change",function(){this.set_options_for_drag_item_selectors()},this),e.all("fieldset#id_draggableitemheader select").on("change",function(){this.set_options_for_drag_item_selectors()},this),e.all("fieldset#id_dropzoneheader select").on("change",function(){this.set_options_for_drag_item_selectors()},this)},form:{to_name_with_index:function(e,t){var n=e;for(var r=0;r
'),this.doc=this.doc_structure(this),this.stop_selector_events(),this.set_options_for_drag_item_selectors(),this.setup_form_events(),e.later(500,this,this.update_drop_zones,[t],!0),e.after(this.load_bg_image,M.form_filepicker,"callback",this),this.load_bg_image()},load_bg_image:function(){var t=this.fp.file("bgimage").href;if(t!==null){this.doc.load_bg_img(t);var n=new e.DD.Drop({node:this.doc.bg_img()});n.on("drop:hit",function(e){e.drag.get("node").setData("gooddrop",!0)}),this.afterimageloaddone=!1,this.doc.bg_img().on("load",this.constrain_image_size,this)}},constrain_image_size:function(e){var t=this.get("maxsizes").bgimage,n=Math.max(e.target.get("width")/t.width,e.target.get("height")/t.height);n>1&&e.target.set("width",Math.floor(e.target.get("width")/n)),e.target.addClass("constrained"),e.target.detach("load",this.constrain_image_size)},update_drop_zones:function(){this.graphics!==null&&this.graphics.destroy(),this.restart_colours(),this.graphics=new e.Graphic({render:"div.ddarea div.dropzones"});var t=this.form.get_form_value("nodropzone",[]);for(var n=0;n'+t[o]+"";s.append(u);var a=s.one('option[value="'+o+'"]');if(o===i[n])a.set("selected",!0);else if(o!==0){var f=this.form.get_form_value("drags",[o-1,"noofdrags"]);if(Number(f)!==0)for(var l in i)if(Number(i[l])===o){if(Number(f)===1){a.set("disabled",!0);break}f--}}}}},stop_selector_events:function(){e.all("fieldset#id_dropzoneheader select").detachAll()},setup_form_events:function(){e.all("fieldset#id_draggableitemheader input").on("change",function(){this.set_options_for_drag_item_selectors()},this),e.all("fieldset#id_draggableitemheader select").on("change",function(){this.set_options_for_drag_item_selectors()},this),e.all("fieldset#id_dropzoneheader select").on("change",function(){this.set_options_for_drag_item_selectors()},this)},form:{to_name_with_index:function(e,t){var n=e;for(var r=0;r