| 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <title>Editor Test</title> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2"/> |
| 6 | |
| 7 | <script type="text/javascript" src="../boilerplate.js"></script> |
| 8 | |
| 9 | <script type="text/javascript"> |
| 10 | require([ |
| 11 | "doh/runner", |
| 12 | "dojo/dom", |
| 13 | "dojo/dom-construct", |
| 14 | "dojo/parser", |
| 15 | "dijit/registry", |
| 16 | "dijit/tests/helpers", |
| 17 | "dijit/Editor", |
| 18 | "dojo/domReady!" |
| 19 | ], function(doh, dom, domConstruct, parser, registry, helpers, Editor){ |
| 20 | |
| 21 | doh.register("setup", [ |
| 22 | { |
| 23 | name: "parse", |
| 24 | timeout: 5000, |
| 25 | runTest: function(){ |
| 26 | parser.parse(); |
| 27 | |
| 28 | // In some browsers, the editor will not yet be loaded. Test that no error occurs |
| 29 | // when retrieving the value. |
| 30 | doh.is("initial content", editor.get("value")); |
| 31 | } |
| 32 | }, |
| 33 | { |
| 34 | name: "wait for editors to load", |
| 35 | timeout: 5000, |
| 36 | runTest: helpers.waitForLoad |
| 37 | } |
| 38 | ]); |
| 39 | |
| 40 | doh.register("miscellaneous", [ |
| 41 | { |
| 42 | name: "set value on unfocused editor", |
| 43 | runTest: function(){ |
| 44 | editor.set("value", "hello"); |
| 45 | editor.focus(); |
| 46 | doh.is("hello", editor.editNode.textContent || editor.editNode.innerText); |
| 47 | doh.is("hello", editor.get("value")); |
| 48 | } |
| 49 | }, |
| 50 | { |
| 51 | name: "get value of unloaded editor", |
| 52 | runTest: function(){ |
| 53 | var tmpEditor = new Editor({ value: "test editor value"}); |
| 54 | doh.is("test editor value", tmpEditor.get("value")); |
| 55 | doh.is("test editor value", tmpEditor.value); |
| 56 | doh.f(tmpEditor.isLoaded); |
| 57 | tmpEditor.startup(); |
| 58 | doh.is("test editor value", tmpEditor.get("value")); |
| 59 | doh.is("test editor value", tmpEditor.value); |
| 60 | doh.f(tmpEditor.isLoaded); |
| 61 | } |
| 62 | } |
| 63 | ]); |
| 64 | |
| 65 | doh.register("reparent", [ |
| 66 | { |
| 67 | name: "update editor's value", |
| 68 | runTest: function(){ |
| 69 | var d = new doh.Deferred(); |
| 70 | editor.set("value", "updated content"); |
| 71 | setTimeout(function(){ |
| 72 | d.callback(); |
| 73 | }, 500); |
| 74 | return d; |
| 75 | } |
| 76 | }, |
| 77 | { |
| 78 | name: "reparent", |
| 79 | runTest: function(){ |
| 80 | var d = new doh.Deferred(); |
| 81 | domConstruct.place(dom.byId("editorWrapper"), "anchorDiv", "before"); |
| 82 | |
| 83 | // Reparenting the editor causing another onLoad event on the iframe. |
| 84 | // Wait for that to complete and then check that editor's value wasn't corrupted. |
| 85 | setTimeout(d.getTestCallback(function(){ |
| 86 | doh.is("updated content", editor.get("value"), "get('value')"); |
| 87 | |
| 88 | var realContent = editor.iframe.contentDocument.body.textContent || |
| 89 | editor.iframe.contentDocument.body.innerText; |
| 90 | doh.is("updated content", realContent, "real content") |
| 91 | }), 500); |
| 92 | return d; |
| 93 | } |
| 94 | } |
| 95 | ]); |
| 96 | |
| 97 | doh.register("destroy", [ |
| 98 | { |
| 99 | name: "destroy the editor", |
| 100 | runTest: function(){ |
| 101 | // just making sure this doesn't throw an exception |
| 102 | editor.destroy(); |
| 103 | } |
| 104 | } |
| 105 | ]); |
| 106 | |
| 107 | doh.run(); |
| 108 | }); |
| 109 | </script> |
| 110 | </head> |
| 111 | <body class="claro" role="main"> |
| 112 | <div id="anchorDiv">This is the anchor div.</div> |
| 113 | <div id="editorWrapper"> |
| 114 | <div data-dojo-id="editor" data-dojo-type="dijit/Editor" |
| 115 | data-dojo-props='"aria-label":"editor", name:"field"'>initial content</div> |
| 116 | </div> |
| 117 | </body> |
| 118 | </html> |