UNPKG

dijit

Version:

Dijit provides a complete collection of user interface controls based on Dojo, giving you the power to create web applications that are highly optimized for usability, performance, internationalization, accessibility, but above all deliver an incredible u

539 lines (488 loc) 18.4 kB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>doh.robot Editor FontChoice Plugin Test</title> <style> @import "../../../../util/doh/robot/robot.css"; </style> <script type="text/javascript" src="../../../../dojo/dojo.js"></script> <script type="text/javascript"> require([ "doh/runner", "dojo/robotx", "dojo/_base/array", "dojo/dom", "dojo/sniff", "dojo/window", "dijit/tests/helpers", "dojo/domReady!" ], function(doh, robot, array, dom, has, winUtils, helpers){ robot.initRobot('../test_FontChoice.html'); var editor; // points to one of the editors (editor0, editor1, etc.) var fcPlugin; // formatBlock, fontSize, or fontName plugin var value; // HTML value of editor function getPlugin(/*String*/ command){ var editor = registry.byId("editor0"); var edPlugins = editor._plugins, i; for(i = 0; i < edPlugins.length; i++){ var p = edPlugins[i]; if(p.declaredClass === "dijit._editor.plugins.FontChoice" && p.command == command){ return p; } } throw new Error("didn't find plugin " + command); } var registry; doh.register("setup", [ { name: "wait for editors to load", timeout: 5000, runTest: helpers.waitForLoad }, function setVars(){ registry = robot.window.require("dijit/registry"); } ]); // Verify that the formatBlock, fontSize, and fontName // plugins correctly display the format / font-size / font-name of the selected text. doh.register("FontChoice: verify current format/font-size/font-name", array.map( [ {id: "para0", format: "p"}, {id: "pre0", format: "pre"}, {id: "h10", format: "h1"}, {id: "h20", format: "h2"}, {id: "h30", format: "h3"}, {id: "sizedText1", size: "1"}, {id: "sizedText4", size: "4"}, {id: "sizedText7", size: "7"}, {id: "comicText", name: "Comic Sans MS"} ], function(params){ return { name: [ "Verify", params.format ? "format " + params.format.toUpperCase() : "", params.size ? "font size " + params.size : "", params.name ? "font name " + params.name : "", "Identified" ].join(" ").replace(/ +/g, " "), timeout: 20000, setUp: function(){ editor = registry.byId("editor0"); value = editor.get("value"); }, runTest: function(){ var d = new doh.Deferred(); // Focus on the editor window winUtils.scrollIntoView(editor.domNode); editor.focus(); robot.mouseMoveAt(editor.iframe, 1000); robot.mouseClick({left:true}, 1000); robot.sequence(d.getTestErrback(function(){ // Find node w/specified id var node = dom.byId(params.id, editor.document); doh.is(params.id, node && node.id, "found " + params.id); // Select the text, collapse to the start of it editor.selection.selectElementChildren(node); editor.selection.collapse(true); }),1000); robot.sequence(d.getTestErrback(function(){ // Make sure states update. editor.onDisplayChanged(); }), 1000); robot.sequence(d.getTestCallback(function(){ if(params.format){ doh.is(params.format, getPlugin("formatBlock").button.get("value"), "format " + params.format + " identified."); } if(params.size){ doh.is(params.size, getPlugin("fontSize").button.get("value"), "font size " + params.size + " identified."); } if(params.name){ doh.is(params.name, getPlugin("fontName").button.get("value"), "font name" + params.name + " identified."); } }), 2000); return d; }, tearDown: function(){ if(editor){editor.set("value", value);} } }; // end of return { ... } // end of function() ) // end of array.map() ); // end of doh.register() // Test changing format/font-size/font-name (ex: changing an <h1> to an <h2>) doh.register("FontChoice: change format/font-size/font", array.map( [ {id: "text", type: "formatBlock", from: "p", to: "pre"}, {id: "text", type: "formatBlock", from: "pre", to: "h1"}, {id: "text", type: "formatBlock", from: "h1", to: "h2"}, {id: "text", type: "formatBlock", from: "h2", to: "h3"}, {id: "sizedText7", type: "fontSize", from: "7", to: "3"}, {id: "comicText", type: "fontName", from: "Comic Sans MS", to: "Times New Roman"} ], function(params){ return { name: "formatBlock: Verify can change " + params.type + " " + params.from.toUpperCase() + " to " + params.to.toUpperCase(), timeout: 20000, setUp: function(){ fcPlugin = getPlugin(params.type); value = editor.get("value"); }, runTest: function(){ var d = new doh.Deferred(); // Focus on the editor window winUtils.scrollIntoView(editor.domNode); editor.focus(); robot.mouseMoveAt(editor.iframe, 1000); robot.mouseClick({left:true}, 1000); robot.sequence(d.getTestErrback(function(){ // Find node var p = dom.byId(params.id, editor.document); doh.is(params.id, p && p.id, "found node"); // Select the text, collapse to the start of it editor.selection.selectElementChildren(p); // Disable collapse. Webkit changed behavior so it now requires // a selection. if(!has("webkit")){ editor.selection.collapse(true) } // Set the format / font-size / font-name plugin to the new value // TODO: use mouse/keyboard to set the value fcPlugin.button.set("value", params.to); }),1000); robot.sequence(d.getTestErrback(function(){ // Make sure states update. editor.onDisplayChanged(); }), 1000); robot.sequence(d.getTestCallback(function(){ doh.is(params.to, fcPlugin.button.get("value"), "verify converted"); // TODO: check that it actually changed the format / font-size / font-name (in the editor contents) }), 2000); return d; }, tearDown: function(){ if(editor){editor.set("value", value);} } }; // end of return { ... } // end of function() ) // end of array.map() ); // end of doh.register() doh.register("formatBlock: multiple changes", { name: "formatBlock: Verify changing multiple nodes to h3", timeout: 20000, setUp: function(){ editor = registry.byId("editor0"); fcPlugin = getPlugin("formatBlock"); value = editor.get("value"); }, runTest: function(){ var d = new doh.Deferred(); // Focus on the editor window winUtils.scrollIntoView(editor.domNode); editor.focus(); robot.mouseMoveAt(editor.iframe, 1000); robot.mouseClick({left:true}, 1000); // Verify the formatBlock plugin was found doh.t(fcPlugin !== null, "formatBlock was found"); robot.sequence(d.getTestErrback(function(){ var p = dom.byId("text", editor.document); doh.is("text", p && p.id, "found text"); // Select the text, collapse to the start of it editor.selection.selectElementChildren(p); editor.selection.collapse(true); // Set the format / font-size / font-name plugin to the new value // TODO: use mouse/keyboard to set the value fcPlugin.button.set("value", "h3"); }),1000); robot.sequence(d.getTestErrback(function(){ // Make sure states update. editor.onDisplayChanged(); }), 1000); robot.sequence(d.getTestErrback(function(){ doh.is("h3", fcPlugin.button.get("value"), "Verify first P converted to H3."); // TODO: check that it actually changed the format (in the editor contents) }), 2000); // Move to the next block and try to change it to h3 too. robot.sequence(d.getTestErrback(function(){ var p = dom.byId("text1", editor.document); doh.is("text1", p && p.id, "found text1"); // Select the text, collapse to the start of it editor.selection.selectElementChildren(p); editor.selection.collapse(true); // Set the format / font-size / font-name plugin to the new value // TODO: use mouse/keyboard to set the value fcPlugin.button.set("value", "h3"); }),1000); robot.sequence(d.getTestErrback(function(){ // Make sure states update. editor.onDisplayChanged(); }), 1000); robot.sequence(d.getTestErrback(function(){ // state should have updated, so, now set value. // TODO: use mouse/keyboard to set the value fcPlugin.button.set("value", "h3"); }),1000); robot.sequence(d.getTestErrback(function(){ // Make sure states update. editor.onDisplayChanged(); }), 1000); robot.sequence(d.getTestCallback(function(){ doh.is("h3", fcPlugin.button.get("value"), "Verify second P converted to H3."); // TODO: check that it actually changed the format (in the editor contents) }), 2000); return d; }, tearDown: function(){ if(editor){editor.set("value", value);} } } ); doh.register("FontChoice: Format Removal Tests", [ { name: "formatBlock: Verify single level format is removed (inside format block).", timeout: 20000, setUp: function(){ editor = registry.byId("editor0"); fcPlugin = getPlugin("formatBlock"); value = editor.get("value"); }, runTest: function(){ var d = new doh.Deferred(); // Focus on the editor window winUtils.scrollIntoView(editor.domNode); editor.focus(); robot.mouseMoveAt(editor.iframe, 1000); robot.mouseClick({left:true}, 1000); // Verify the formatBlock plugin was found doh.t(fcPlugin !== null, "formatBlock was found"); robot.sequence(d.getTestErrback(function(){ var p = dom.byId("text", editor.document); doh.is("text", p && p.id, "found text"); // Select the text, collapse to the start of it editor.selection.selectElementChildren(p); editor.selection.collapse(true); }),1000); robot.sequence(d.getTestErrback(function(){ // Make sure states update. editor.onDisplayChanged(); }), 1000); robot.sequence(d.getTestErrback(function(){ fcPlugin.button.set("value", "noFormat"); }), 1000); robot.sequence(d.getTestErrback(function(){ // Make sure states update. // If change occurred, then the value should // still be noFormat. editor.onDisplayChanged(); }), 1000); robot.sequence(d.getTestCallback(function(){ doh.is("noFormat", fcPlugin.button.get("value"), "Validating current cursor point format is noFormat"); }), 1000); return d; }, tearDown: function(){ if(editor){editor.set("value", value);} } }, { name: "formatBlock: Verify multiple format removal via selection", timeout: 20000, setUp: function(){ editor = registry.byId("editor0"); fcPlugin = getPlugin("formatBlock"); value = editor.get("value"); }, runTest: function(){ var d = new doh.Deferred(); // Focus on the editor window winUtils.scrollIntoView(editor.domNode); editor.focus(); robot.mouseMoveAt(editor.iframe, 1000); robot.mouseClick({left:true}, 1000); // Verify the formatBlock plugin was found doh.isNot(null, fcPlugin, "formatBlock was found"); robot.sequence(d.getTestErrback(function(){ var p = dom.byId("text", editor.document); doh.is("text", p && p.id, "found text"); // Select the text, collapse to the start of it editor.selection.selectElementChildren(p); editor.selection.collapse(true); }),1000); robot.sequence(d.getTestErrback(function(){ // Make sure states update. editor.onDisplayChanged(); }), 1000); robot.sequence(d.getTestErrback(function(){ // Select the children of the block and try to flatten the formatting. var selection = dom.byId("selectionContainer", editor.document); winUtils.scrollIntoView(selection); editor.selection.selectElementChildren(selection); fcPlugin.button.set("value", "noFormat"); }), 1000); robot.sequence(d.getTestCallback(function(){ // Now check that the elements are all gone. var selection = dom.byId("selectionContainer", editor.document); doh.t(selection.childNodes.length > 0, "Checking that there are still child nodes, actual was " + selection.childNodes.length); var i; var nodes = selection.childNodes; for(i = 0; i < nodes.length; i++){ var n = nodes[i]; if(n.nodeType == 1){ var tag = n.nodeName ? n.nodeName.toLowerCase() : ""; doh.isNot("p", tag, "selection node #" + i + " of " + nodes.length); doh.isNot("h3", tag, "selection node #" + i + " of " + nodes.length); doh.isNot("pre", tag, "selection node #" + i + " of " + nodes.length); } } }), 1000); return d; }, tearDown: function(){ if(editor){editor.set("value", value);} } } ]); doh.register("FontChoice: miscellaneous tests", [ { name: "FontChoice: Plain Text labels", timeout: 20000, setUp: function(){ editor = registry.byId("editor1"); fcPlugin = []; var edPlugins = editor._plugins, i; for(i = 0; i < edPlugins.length; i++){ var p = edPlugins[i]; if(p.declaredClass === "dijit._editor.plugins.FontChoice"){ fcPlugin.push(p); } } value = editor.get("value"); }, runTest: function(){ // summary: // This test goes through all the registered FontChoice plugins // and verifies that they're all using plain text labels in the dropdown. var d = new doh.Deferred(); // Focus on the editor window winUtils.scrollIntoView(editor.domNode); editor.focus(); robot.mouseMoveAt(editor.iframe, 1000); robot.mouseClick({left:true}, 1000); robot.sequence(d.getTestCallback(function(){ for(var i = 0; i < fcPlugin.length; i++){ var p = fcPlugin[i]; var store = p.button.select.store; var items = store.query(); for(var j = 0; j < items.length; j++){ var item = items[j]; doh.f(item.name.indexOf("<") === 0, "failed on: " + item.name); } } }), 1000); return d; }, tearDown: function(){ if(editor){editor.set("value", value);} } }, { name: "FontChoice: Validate usage of generic names", timeout: 20000, setUp: function(){ editor = registry.byId("generic"); fcPlugin = null; var edPlugins = editor._plugins, i; for(i = 0; i < edPlugins.length; i++){ var p = edPlugins[i]; if(p.declaredClass === "dijit._editor.plugins.FontChoice" && p.command === "fontName" && p.generic){ fcPlugin = p; } } value = editor.get("value"); }, runTest: function(){ // summary: // This test goes through the font choice plugin registered as generic font names and validates // the font names in the values are the generic map. var d = new doh.Deferred(); // Focus on the editor window winUtils.scrollIntoView(editor.domNode); editor.focus(); robot.mouseMoveAt(editor.iframe, 1000); robot.mouseClick({left:true}, 1000); robot.sequence(d.getTestCallback(function(){ var map = { "sans-serif": false, "serif": false, "cursive": false, "monospace": false, "fantasy": false }; var store = fcPlugin.button.select.store; var items = store.query(); for(var j = 0; j < items.length; j++){ var item = items[j]; map[item.value] = true; } for(j in map){ doh.t(map[j], j); } }), 1000); return d; }, tearDown: function(){ if(editor){editor.set("value", value);} } }, { name: "FontChoice: Validate custom font names", timeout: 20000, setUp: function(){ editor = registry.byId("custom"); fcPlugin = null; var edPlugins = editor._plugins, i; for(i = 0; i < edPlugins.length; i++){ var p = edPlugins[i]; if(p.declaredClass === "dijit._editor.plugins.FontChoice" && p.command === "fontName" && p.custom){ fcPlugin = p; } } value = editor.get("value"); }, runTest: function(){ // summary: // This test goes through the font choice plugin registered as custom font names and validates // the font names in the values are the provided names. var d = new doh.Deferred(); // Focus on the editor window winUtils.scrollIntoView(editor.domNode); editor.focus(); robot.mouseMoveAt(editor.iframe, 1000); robot.mouseClick({left:true}, 1000); robot.sequence(d.getTestCallback(function(){ var map = { "Verdana": false, "Myriad": false, "Garamond": false }; var store = fcPlugin.button.select.store; var items = store.query(); for(var j = 0; j < items.length; j++){ var item = items[j]; map[item.value] = true; } for(j in map){ doh.t(map[j], j); } }), 1000); return d; }, tearDown: function(){ if(editor){editor.set("value", value);} } } ]); doh.run(); }); </script> </head> </html>