webgui/www/extras/yui/tests/editor.html
JT Smith 20f8df1291 upgrading to YUI 2.6
data tables are going to need some work yet, but the other stuff seems to be working 100%
2008-10-22 23:53:29 +00:00

356 lines
20 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Editor Test Suite</title>
<link rel="stylesheet" type="text/css" href="../build/reset-fonts-grids/reset-fonts-grids.css">
<link type="text/css" rel="stylesheet" href="../build/logger/assets/logger.css">
<link type="text/css" rel="stylesheet" href="../build/yuitest/assets/testlogger.css">
<link rel="stylesheet" type="text/css" href="../build/container/assets/skins/sam/container.css">
<link rel="stylesheet" type="text/css" href="../build/menu/assets/skins/sam/menu.css">
<link rel="stylesheet" type="text/css" href="../build/button/assets/skins/sam/button.css">
<link rel="stylesheet" type="text/css" href="../build/resize/assets/skins/sam/resize.css">
<link rel="stylesheet" type="text/css" href="../build/editor/assets/skins/sam/editor.css">
<script type="text/javascript" src="../build/utilities/utilities.js"></script>
<script type="text/javascript" src="../build/logger/logger-min.js"></script>
<script type="text/javascript" src="../build/container/container_core-min.js"></script>
<script type="text/javascript" src="../build/menu/menu-min.js"></script>
<script type="text/javascript" src="../build/button/button-min.js"></script>
<script type="text/javascript" src="../build/resize/resize-min.js"></script>
<script type="text/javascript" src="../build/editor/editor.js"></script>
<script type="text/javascript" src="../build/yuitest/yuitest.js"></script>
<style>
#testRegEx, #testRegEx2 {
display: none;
}
</style>
<script type="text/javascript">
var editor = null;
(function() {
var Dom = YAHOO.util.Dom,
Event = YAHOO.util.Event,
Tool = YAHOO.tool,
Suite = new Tool.TestSuite('yuisuite'),
Assert = YAHOO.util.Assert;
Event.onDOMReady(function() {
editor = new YAHOO.widget.Editor('editor', {
dompath: true,
nodeChangeDelay: false,
removeLineBreaks: true,
animate: true,
resize: true,
drag: true
});
editor.render();
var logger = new Tool.TestLogger(null, { height: '80%' });
editor.on('windowRender', function() { //We have to wait until the all windows render before we can start testing it..
Suite.add( new Tool.TestCase({
name: 'YAHOO.widget.Editor',
test_render: function() {
Assert.areEqual(Dom.get('editor_container'), editor.get('element_cont').get('element'), 'Could not find Editors container');
Assert.areEqual(Dom.get('editor_toolbar'), editor.toolbar.get('element'), 'Could not find Editors Toolbar');
Assert.isInstanceOf(YAHOO.widget.Toolbar, editor.toolbar, 'Could not find Toolbars Instance');
Assert.areEqual(Dom.getStyle('editor', 'display'), editor.getStyle('display'), 'Textarea is visible..');
Assert.isInstanceOf(YAHOO.widget.Overlay, editor.get('panel'), 'Could not find Overlay Instance');
},
test_content: function() {
var t_data = Dom.get('editor').value;
var e_data = editor.getEditorHTML();
Assert.areEqual(t_data, e_data, 'Editor data is different than text area');
},
test_window: function() {
Assert.areEqual(document.getElementById('editor_editor').contentWindow, editor._getWindow(), 'Window object is not right');
},
test_doc: function() {
Assert.areEqual(document.getElementById('editor_editor').contentWindow.document, editor._getDoc(), 'Document object is not right');
},
test_regex: function() {
editor.setEditorHTML(Dom.get('testRegEx').innerHTML);
//editor._getDoc().body.innerHTML = Dom.get('testRegEx').innerHTML;
var e_data = (editor.cleanHTML()).toLowerCase().replace(/;"/g, '"');
var real_data = editor.filter_all_rgb(Dom.get('testRegEx2').innerHTML.toLowerCase()).replace(/;"/g, '"');
Assert.areEqual(real_data, e_data, 'Regex save routine failed');
},
test_blank_image: function() {
editor.toolbar.resetAllButtons();
var picURL = editor.get('blankimage');
editor._focusWindow();
editor.toolbar.getButtonByValue('insertimage').fireEvent('mousedown', { ev: 'mousedown' });
var pic = editor._getDoc().getElementsByTagName('img')[0];
Assert.areEqual(picURL, pic.getAttribute('src', 2), 'Image source and string do not match');
Assert.isInstanceOf(YAHOO.widget.EditorWindow, editor.currentWindow, 'Editor Window Failed to Open');
editor.closeWindow();
Assert.areEqual(null, editor.currentWindow, 'Editor Window Failed to Close');
editor.toolbar.resetAllButtons();
Assert.areEqual(null, pic.parentNode, 'Image is still inside the editor');
},
test_insertimage: function() {
var picURL = 'http:/'+'/farm1.static.flickr.com/171/379031784_e4ba36a375_t_d.jpg';
editor._focusWindow();
editor.execCommand('insertimage', picURL);
var pic = editor._getDoc().getElementsByTagName('img')[0];
Assert.areEqual(picURL, pic.getAttribute('src', 2));
},
test_image_props: function() {
var pic = editor._getDoc().getElementsByTagName('img')[0];
YAHOO.util.UserAction.dblclick(pic);
Assert.isInstanceOf(YAHOO.widget.EditorWindow, editor.currentWindow, 'Editor Window Failed to Open');
},
test_close_window: function() {
editor.closeWindow();
Assert.areEqual(null, editor.currentWindow, 'Editor Window Failed to Close');
editor.toolbar.resetAllButtons();
},
test_selected_element: function() {
editor.setEditorHTML('<em id="test">This is a test element</em>');
editor._selectNode(editor._getDoc().getElementById('test'));
Assert.areEqual(editor._getDoc().getElementById('test'), editor._getSelectedElement(), 'Selected Element is not em#test');
Assert.areEqual(true, editor.toolbar.getButtonByValue('italic').hasClass('yui-button-selected'), 'Italic button is not selected');
editor.toolbar.resetAllButtons();
},
test_dom_path: function() {
editor.setEditorHTML('<p>This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.</p><p>This is a test. This is a test. <em style="font-family: Comic Sans MS">This is a test. <strong id="test">This is a test.</strong> This is a test.</em> This is a test. This is a test. This is a test.</p><p>This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.</p>');
editor._selectNode(editor._getDoc().getElementById('test'));
//Editor timing is out here, force a DomPath write..
editor._writeDomPath();
Assert.areEqual('<span title=body>body</span> &lt; <span title=p>p</span> &lt; <span title=em>em</span> &lt; <span title=strong#test>strong#tes...</span>', editor.dompath.innerHTML.toLowerCase().replace(/"/g, ''), 'Dom path is not correct..');
Assert.areEqual(true, editor.toolbar.getButtonByValue('bold').hasClass('yui-button-selected'), 'Bold button is not selected');
Assert.areEqual(true, editor.toolbar.getButtonByValue('italic').hasClass('yui-button-selected'), 'Italic button is not selected');
editor.toolbar.resetAllButtons();
},
test_hidden_elements: function() {
editor.toolbar.getButtonByValue('hiddenelements').fireEvent('mousedown', { ev: 'mousedown' });
Assert.areEqual(true, Dom.hasClass(editor._getDoc().body, 'yui-hidden'), 'hidden class is not on the body');
editor.toolbar.getButtonByValue('hiddenelements').fireEvent('mousedown', { ev: 'mousedown' });
Assert.areEqual(false, Dom.hasClass(editor._getDoc().body, 'yui-hidden'), 'hidden class is on the body');
},
test_event_before_mouseup: function() {
var event = false;
editor.on('beforeEditorMouseUp', function() {
event = true;
});
YAHOO.util.UserAction.mouseup(editor._getDoc().body);
Assert.areEqual(true, event, 'BeforeMouseUP Event failed to Fired');
},
test_event_mouseup: function() {
var event = false;
editor.on('editorMouseUp', function() {
event = true;
});
YAHOO.util.UserAction.mouseup(editor._getDoc().body);
Assert.areEqual(true, event, 'MouseUP Event failed to Fired');
},
test_event_before_mousedown: function() {
var event = false;
editor.on('beforeEditorMouseDown', function() {
event = true;
});
YAHOO.util.UserAction.mousedown(editor._getDoc().body);
Assert.areEqual(true, event, 'BeforeMouseDsaveown Event failed to Fired');
},
test_event_mousedown: function() {
var event = false;
editor.on('editorMouseDown', function() {
event = true;
});
YAHOO.util.UserAction.mousedown(editor._getDoc().body);
Assert.areEqual(true, event, 'MouseDown Event failed to Fired');
},
test_event_before_click: function() {
var event = false;
editor.on('beforeEditorClick', function() {
event = true;
});
YAHOO.util.UserAction.click(editor._getDoc().body);
Assert.areEqual(true, event, 'BeforeClick Event failed to Fired');
},
test_event_click: function() {
var event = false;
editor.on('editorClick', function() {
event = true;
});
YAHOO.util.UserAction.click(editor._getDoc().body);
Assert.areEqual(true, event, 'Click Event failed to Fired');
},
test_event_before_double_click: function() {
var event = false;
editor.on('beforeEditorDoubleClick', function() {
event = true;
});
YAHOO.util.UserAction.dblclick(editor._getDoc().body);
Assert.areEqual(true, event, 'BeforeDoubleClick Event failed to Fired');
},
test_event_double_click: function() {
var event = false;
editor.on('editorDoubleClick', function() {
event = true;
});
YAHOO.util.UserAction.dblclick(editor._getDoc().body);
Assert.areEqual(true, event, 'DoubleClick Event failed to Fired');
},
test_event_before_keyup: function() {
var event = false;
editor.on('beforeEditorKeyUp', function() {
event = true;
});
YAHOO.util.UserAction.keyup(editor._getDoc().body);
Assert.areEqual(true, event, 'beforeKeyUp Event failed to Fired');
},
test_event_keyup: function() {
var event = false;
editor.on('editorKeyUp', function() {
event = true;
});
YAHOO.util.UserAction.keyup(editor._getDoc().body);
Assert.areEqual(true, event, 'KeyUp Event failed to Fired');
},
test_event_before_keydown: function() {
var event = false;
editor.on('beforeEditorKeyDown', function() {
event = true;
});
YAHOO.util.UserAction.keydown(editor._getDoc().body);
Assert.areEqual(true, event, 'BeforeKeyDown Event failed to Fired');
},
test_event_keydown: function() {
var event = false;
editor.on('editorKeyDown', function() {
event = true;
});
YAHOO.util.UserAction.keydown(editor._getDoc().body);
Assert.areEqual(true, event, 'KeyDown Event failed to Fired');
},
test_event_before_keypress: function() {
var event = false;
editor.on('beforeEditorKeyPress', function() {
event = true;
});
YAHOO.util.UserAction.keypress(editor._getDoc().body);
Assert.areEqual(true, event, 'BeforeKeyPress Event failed to Fired');
},
test_event_keypress: function() {
var event = false;
editor.on('editorKeyPress', function() {
event = true;
});
YAHOO.util.UserAction.keypress(editor._getDoc().body);
Assert.areEqual(true, event, 'KeyPress Event failed to Fired');
},
test_createlink: function() {
editor.toolbar.resetAllButtons();
editor.setEditorHTML('test');
var e_data = editor.getEditorHTML();
Assert.areEqual('test', e_data, 'Editor data is different than what was injected');
editor.execCommand('selectall', '');
editor.toolbar.getButtonByValue('createlink').fireEvent('mousedown', { ev: 'mousedown' });
Assert.isInstanceOf(YAHOO.widget.EditorWindow, editor.currentWindow, 'Editor Window Failed to Open');
Dom.get(editor.get('id') + '_createlink_url').value = 'http:/'+'/www.yahoo.com';
editor.closeWindow();
Assert.areEqual(null, editor.currentWindow, 'Editor Window Failed to Close');
var link = editor._getDoc().getElementsByTagName('a')[0];
var linkURL = link.getAttribute('href', 2);
Assert.areEqual('http:/'+'/www.yahoo.com', linkURL, 'Link url does not match what was set');
editor.toolbar.resetAllButtons();
},
test_content_after: function() {
var t_data = Dom.get('editor').value;
editor.setEditorHTML(t_data);
var e_data = editor.getEditorHTML();
Assert.areEqual(t_data, e_data, 'Editor data is different than text area');
},
test_undo: function() {
var one = '<p>this is a test.</p>',
two = '<p>this is a test.</p><p>this is another test</p>';
editor._undoLevel = 0;
editor._undoCache = [];
editor.setEditorHTML(one);
editor.nodeChange();
editor.setEditorHTML(two);
editor.nodeChange();
Assert.areEqual(2, editor._undoLevel, 'Editor undo level is not high enough');
editor.execCommand('undo');
editor.execCommand('undo');
Assert.areEqual(one, editor.saveHTML().toLowerCase(), 'Editor undo level did not undo');
editor.execCommand('redo');
Assert.areEqual(two, editor.saveHTML().toLowerCase(), 'Editor undo level did not redo');
},
test_dd: function() {
Assert.isInstanceOf(YAHOO.util.DD, editor.dd, 'DD not instantiated');
},
test_resize: function() {
Assert.isInstanceOf(YAHOO.util.Resize, editor.resize, 'Resize not instantiated');
},
test_destroy: function() {
var panel = editor.get('panel').element;
editor.destroy();
Assert.isNull(panel.offsetParent, 'Panel offsetParent is not null')
},
test_render_node: function() {
var el = document.getElementById('editor');
editor = new YAHOO.widget.SimpleEditor(el);
editor.render();
Assert.areEqual(true, editor._rendered, 'Editor failed to render with HTML element passed to constructor');
window.setTimeout(function() {
editor.destroy();
}, 3000);
},
test_no_textarea: function() {
var div = document.createElement('div');
div.id = 'editor_div';
div.style.height = '300px';
div.style.width = '700px';
div.innerHTML = '<strong>This is a new div</strong>';
document.body.appendChild(div);
editor2 = new YAHOO.widget.SimpleEditor('editor_div');
editor2.render();
window.setTimeout(function() {
editor2.destroy();
}, 3000);
Assert.areEqual('div', editor2._configs.element.value.tagName.toLowerCase(), 'Editor failed to render with HTML element (non TEXTAREA) passed to constructor');
}
}));
Tool.TestRunner.add(Suite);
if (parent && parent != window) {
YAHOO.tool.TestManager.load();
} else {
YAHOO.tool.TestRunner.run();
}
});
});
})();
</script>
<style type="text/css">
</style>
</head>
<body class="yui-skin-sam">
<div id="doc">
<textarea id="editor" style="height: 300px; width: 522px">This is a test.</textarea>
<div id="testRegEx">This is a test. <b>This</b> is a test. This is a <i>test</i>. This is a <u>test</u>. This is a test. This is a test. This is a test. <span style="font-size: 16px; font-family: Comic Sans MS;" tabindex="1" tag="span" class="yui-tag-span yui-tag">This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. </span>This is a test. This is a test. This is a test. This is a test. This is a test.<br><br>This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. <span style="font-size: 18px; font-family: Trebuchet MS; color: rgb(160, 64, 255);" tabindex="1" tag="span" class="yui-tag-span yui-tag">This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.</span> This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. </div>
<div id="testRegEx2">This is a test. <strong>This</strong> is a test. This is a <em>test</em>. This is a <span style="text-decoration: underline;">test</span>. This is a test. This is a test. This is a test. <span style="font-size: 16px; font-family: Comic Sans MS;" tabindex="1">This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. </span>This is a test. This is a test. This is a test. This is a test. This is a test.<br><br>This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. <span style="font-size: 18px; font-family: Trebuchet MS; color: #a040ff;" tabindex="1">This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.</span> This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.</div>
</div>
</body>
</html>