/***************************************************************************** * * Copyright (c) 2003-2005 Kupu Contributors. All rights reserved. * * This software is distributed under the terms of the Kupu * License. See LICENSE.txt for license text. For a list of Kupu * Contributors see CREDITS.txt. * *****************************************************************************/ function KupuUITestCase() { this.name = 'KupuUITestCase'; SelectionTestCase.apply(this); this.base_setUp = this.setUp; this.setUp = function() { this.base_setUp(); this.editor = new KupuEditor(this.kupudoc, {}, null); this.preserve = document.getElementById('preserve-this-div').innerHTML; this.ui = new KupuUI('kupu-tb-styles'); this.ui.editor = this.editor; }; this.tearDown = function() { document.getElementById('preserve-this-div').innerHTML = this.preserve; }; this._selectTableCells = function(indices, verificationString) { var tableNodes = this.body.getElementsByTagName("table"); var cellNodes = []; var curNode = null; var direction = null; var foundNext = null; for(var i = 0; i < tableNodes.length; i = i + 1) { curNode = tableNodes[i].firstChild; //what if no child? direction = 'down'; while( curNode.nodeName.toLowerCase() != 'table' ) { /*if(indices[1]==2) { alert(curNode.nodeName); alert(curNode.innerHTML); }*/ if( curNode.nodeName.toLowerCase() == 'td' || curNode.nodeName.toLowerCase() == 'th' ) { cellNodes.push(curNode); }; foundNext = false; while( !foundNext && curNode.nodeName.toLowerCase() != 'table' ) { if( direction == 'right' ) { if( curNode.nextSibling ) { curNode = curNode.nextSibling; direction = 'down'; foundNext = true; } else { curNode = curNode.parentNode; }; } else if( direction == 'down' ) { if( curNode.firstChild ) { curNode = curNode.firstChild; foundNext = true; } else { direction = 'right'; }; }; }; }; }; this.selection.selection.removeAllRanges(); for(var i = 0; i < indices.length; i = i + 1) { var range = this.doc.createRange(); range.selectNode(cellNodes[indices[i]]); this.selection.selection.addRange(range); }; this.assertEquals('"'+this.selection.toString().replace(/\r|\n/g, '')+'"', '"'+verificationString+'"'); }; this.test_updateState = function() { this.body.innerHTML = '
foo
bar
baz
'; var node = this.body.getElementsByTagName('pre')[0]; this.ui.cleanStyles(); this.ui.enableOptions(false); this.ui.tsselect.selectedIndex = 0; this.assertEquals(this.ui.tsselect.selectedIndex, 0); this.ui.updateState(node); this.assertEquals(this.ui.tsselect.selectedIndex, 3); }; this.updateStateTest = function(html, start, end, verify, ieskew, label) { this.body.innerHTML = html; this.ui.cleanStyles(); this.ui.enableOptions(false); this._setSelection(start, null, end, null, verify, ieskew); node = this.editor.getSelectedNode(); this.ui.updateState(node); var select = this.ui.tsselect; this.assertEquals(select.options[select.selectedIndex].text, label); }; this.test_updateState2 = function() { this.updateStateTest('| foo | bar |
| foo | bar |
| foobaz |
| foo baz |
foo
foo
foo
bar
baz
'; // select |bar| this._setSelection(4, null, 7, null, 'bar'); this.ui.setTextStyle('h1'); this.assertEquals(this._cleanHtml(this.body.innerHTML), 'foo
baz
'); }; this.test_setTextStyle_ParaStyle_SingleTableCell = function() { //Apply a paragraph style inside a table cell var data = '| bar |
bar |
foobarbaz |
| foo bar baz |
| foobarbaz |
| foobarbaz |
| foo | bar |
| foo | bar |
| foo |
| bar |
| foo |
| bar |
| bar |
bar |
bar |
| bar |
| bar |
|---|
bar |
|---|
| foo | bar |
foo | bar |
| foo | foz |
| bar | baz |
| foo | foz |
| bar | baz |
| foo | foz |
| bar | baz |
foo | foz |
bar | baz |
foo
baz
'; // select |bar| this._setSelection(4, null, 7, null, 'bar'); this.ui.setTextStyle('h1'); this.assertEquals(this._cleanHtml(this.body.innerHTML), 'foo
baz
'); }; }; KupuUITestCase.prototype = new SelectionTestCase; function ImageToolTestCase() { this.name = 'ImageToolTestCase'; SelectionTestCase.apply(this); this.base_setUp = this.setUp; this.setUp = function() { this.base_setUp(); this.editor = new KupuEditor(this.kupudoc, {}, new DummyLogger()); this.editor._initialized = true; this.imagetool = new ImageTool(); this.imagetool.editor = this.editor; }; this.test_createImage = function() { this.body.innerHTML = 'foo bar baz
'; // select |bar| this._setSelection(4, null, 7, null, 'bar'); this.imagetool.createImage('bar.png'); this.assertEquals(this._cleanHtml(this.body.innerHTML), 'foo
baz
foo bar baz
'; // select |bar| this._setSelection(4, null, 7, null, 'bar'); this.imagetool.createImage('bar.png', 'spam', 'image-inline'); var nodes = this.body.getElementsByTagName('img'); this.assertEquals(nodes.length, 1); this.assertEquals(nodes[0].className, 'image-inline'); this.assertEquals(nodes[0].alt, 'spam'); }; }; ImageToolTestCase.prototype = new SelectionTestCase; function LinkToolTestCase() { this.name = 'LinkToolTestCase'; SelectionTestCase.apply(this); this.base_setUp = this.setUp; this.setUp = function() { this.base_setUp(); this.editor = new KupuEditor(this.kupudoc, {}, new DummyLogger()); this.editor._initialized = true; this.linktool = new LinkTool(); this.linktool.editor = this.editor; }; this.test_createLink = function() { this.body.innerHTML = 'foo bar baz
'; // select |bar| this._setSelection(4, null, 7, null, 'bar'); this.linktool.createLink('http://www.example.org'); this.assertEquals(this._cleanHtml(this.body.innerHTML), 'foo bar baz
'); }; this.test_createLinkEmpty = function() { this.body.innerHTML = 'foo bar baz
'; // select |bar| this._setSelection(4, null, 7, null, 'bar'); this.linktool.createLink(''); this.assertEquals(this._cleanHtml(this.body.innerHTML), 'foo bar baz
'); }; }; LinkToolTestCase.prototype = new SelectionTestCase;