editor.js revision e0b25dbc0322a078f384c45b48e5690f23d7eb15
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav GlassYUI({
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass base: '../../../build/',
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass //filter: 'DEBUG',
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass filter: 'RAW',
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass logExclude: {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass 'YUI': true,
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Event: true,
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Base: true,
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Attribute: true,
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass augment: true,
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass useConsole: true
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass }
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass}).use('console', 'test', 'editor', 'node-event-simulate', function(Y) {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass var myConsole = new Y.Console({
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass height: Y.one(window).get('winHeight') + 'px',
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass width: '375px'
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass }).render();
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass var editor = null,
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass template = {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass name: 'Editor Tests',
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass setUp : function() {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass },
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass tearDown : function() {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass },
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass test_load: function() {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isObject(Y.Frame, 'EditorBase was not loaded');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isObject(Y.EditorBase, 'EditorBase was not loaded');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass },
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass test_frame: function() {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass var iframeReady = false,
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass iframe = new Y.Frame({
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass container: '#editor',
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass designMode: true,
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass content: 'This is a test.',
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass use: ['node','selector-css3', 'dd-drag', 'dd-ddm']
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass });
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isInstanceOf(Y.Frame, iframe, 'Iframe instance can not be created');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass iframe.after('ready', function() {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass iframeReady = true;
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass });
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass iframe.render();
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass this.wait(function() {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isTrue(iframeReady, 'IFRAME ready event did not fire');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass var inst = iframe.getInstance();
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isInstanceOf(YUI, inst, 'Internal instance not created');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isObject(inst.DD.Drag, 'DD Not loaded inside the frame');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isObject(inst.DD.DDM, 'DD Not loaded inside the frame');
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass iframe.destroy();
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass Y.Assert.isNull(Y.one('#editor iframe'), 'iframe DOM node was not destroyed');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass }, 1500);
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass },
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass test_editor: function() {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.EditorBase.USE.push('dd');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.EditorBase.USE.push('node-event-simulate');
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass var iframeReady = false;
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass editor = new Y.EditorBase({
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass content: 'Hello <b>World</b>!!',
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass extracss: 'b { color: red; }'
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass });
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isInstanceOf(Y.EditorBase, editor, 'EditorBase instance can not be created');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass editor.after('frame:ready', function() {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass iframeReady = true;
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass });
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass editor.on('nodeChange', function(e) {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.areSame('mousedown', e.changedType, 'NodeChange working');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isTrue(e.changedNode.test('b, body'), 'Changed Node');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass });
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass editor.render('#editor');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass this.wait(function() {
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isTrue(iframeReady, 'IFRAME ready event did not fire');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass var inst = editor.getInstance();
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isInstanceOf(YUI, inst, 'Internal instance not created');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isObject(inst.DD.Drag, 'DD Not loaded inside the frame');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.isObject(inst.DD.DDM, 'DD Not loaded inside the frame');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Assert.areSame(Y.EditorBase.FILTER_RGB(inst.one('b').getStyle('color')), '#ff0000', 'Extra CSS Failed');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass inst.one('body').simulate('mousedown');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass inst.one('b').simulate('mousedown');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass }, 1500);
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass },
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass test_window: function() {
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass Y.Assert.areEqual(Y.Node.getDOMNode(Y.one('#editor iframe').get('contentWindow')), Y.Node.getDOMNode(editor.getInstance().one('win')), 'Window object is not right');
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass },
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass test_doc: function() {
e0b25dbc0322a078f384c45b48e5690f23d7eb15Dav Glass Y.Assert.areEqual(Y.Node.getDOMNode(Y.one('#editor iframe').get('contentWindow.document')), Y.Node.getDOMNode(editor.getInstance().one('doc')), 'Document object is not right');
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass }
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass };
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass var suite = new Y.Test.Suite("Editor");
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass suite.add(new Y.Test.Case(template));
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Test.Runner.add(suite);
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass Y.Test.Runner.run();
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass});
fc2d50365b169f761de7a15d7a4fe406b33fd403Dav Glass