How to use getBody method in Cypress

Best JavaScript code snippet using cypress

Selection.js

Source:Selection.js Github

copy

Full Screen

...23 var rng, eventObj;24 // Get selected contents25 editor.setContent('<p>text</p>');26 rng = editor.dom.createRng();27 rng.setStart(editor.getBody(), 0);28 rng.setEnd(editor.getBody(), 1);29 editor.selection.setRng(rng);30 equal(editor.selection.getContent(), '<p>text</p>', 'Get selected contents');31 // Get selected contents (collapsed)32 editor.setContent('<p>text</p>');33 rng = editor.dom.createRng();34 rng.setStart(editor.getBody(), 0);35 rng.setEnd(editor.getBody(), 0);36 editor.selection.setRng(rng);37 equal(editor.selection.getContent(), '', 'Get selected contents (collapsed)');38 // Get selected contents, onGetContent event39 eventObj = {};40 function handler(event) {41 eventObj = event;42 }43 editor.on('GetContent', handler);44 editor.setContent('<p>text</p>');45 rng = editor.dom.createRng();46 rng.setStart(editor.getBody(), 0);47 rng.setEnd(editor.getBody(), 1);48 editor.selection.setRng(rng);49 editor.selection.getContent();50 equal(eventObj.content, '<p>text</p>', 'Get selected contents, onGetContent event');51 editor.off('GetContent', handler);52});53test('setContent', function() {54 var rng, eventObj;55 // Set contents at selection56 editor.setContent('<p>text</p>');57 rng = editor.dom.createRng();58 rng.setStart(editor.getBody(), 0);59 rng.setEnd(editor.getBody(), 1);60 editor.selection.setRng(rng);61 editor.selection.setContent('<div>test</div>');62 equal(editor.getContent(), '<div>test</div>', 'Set contents at selection');63 // Set contents at selection (collapsed)64 editor.setContent('<p>text</p>');65 rng = editor.dom.createRng();66 rng.setStart(editor.getBody(), 0);67 rng.setEnd(editor.getBody(), 0);68 editor.selection.setRng(rng);69 editor.selection.setContent('<div>test</div>');70 equal(editor.getContent(), '<div>test</div>\n<p>text</p>', 'Set contents at selection (collapsed)');71 // Insert in middle of paragraph72 editor.setContent('<p>beforeafter</p>');73 rng = editor.dom.createRng();74 rng.setStart(editor.getBody().firstChild.firstChild, 'before'.length);75 rng.setEnd(editor.getBody().firstChild.firstChild, 'before'.length);76 editor.selection.setRng(rng);77 editor.selection.setContent('<br />');78 equal(editor.getContent(), '<p>before<br />after</p>', 'Set contents at selection (inside paragraph)');79 // Check the caret is left in the correct position.80 rng = editor.selection.getRng(true);81 if (document.createRange) {82 equal(rng.startContainer, editor.getBody().firstChild, 'Selection start container');83 equal(rng.startOffset, 2, 'Selection start offset');84 equal(rng.endContainer, editor.getBody().firstChild, 'Selection end container');85 equal(rng.endOffset, 2, 'Selection end offset');86 } else {87 // TridentSelection resolves indexed text nodes88 equal(rng.startContainer, editor.getBody().firstChild.lastChild, 'Selection start container');89 equal(rng.startOffset, 0, 'Selection start offset');90 equal(rng.endContainer, editor.getBody().firstChild.lastChild, 'Selection end container');91 equal(rng.endOffset, 0, 'Selection end offset');92 }93 editor.setContent('<p>text</p>');94 rng = editor.dom.createRng();95 rng.setStart(editor.getBody(), 0);96 rng.setEnd(editor.getBody(), 0);97 editor.selection.setRng(rng);98 editor.selection.setContent('');99 equal(editor.getContent(), '<p>text</p>', 'Set contents to empty at selection (collapsed)');100 rng = editor.selection.getRng(true);101 if (!document.createRange) {102 // The old IE selection can only be positioned in text nodes103 equal(rng.startContainer, editor.getBody().firstChild.firstChild, 'Selection start container');104 equal(rng.startOffset, 0, 'Selection start offset');105 equal(rng.endContainer, editor.getBody().firstChild.firstChild, 'Selection end container');106 equal(rng.endOffset, 0, 'Selection end offset');107 } else {108 equal(rng.startContainer, editor.getBody(), 'Selection start container');109 equal(rng.startOffset, 0, 'Selection start offset');110 equal(rng.endContainer, editor.getBody(), 'Selection end container');111 equal(rng.endOffset, 0, 'Selection end offset');112 }113 114 // Set selected contents, onSetContent event115 eventObj = {};116 function handler(event) {117 eventObj = event;118 }119 editor.on('SetContent', handler);120 editor.setContent('<p>text</p>');121 rng = editor.dom.createRng();122 rng.setStart(editor.getBody(), 0);123 rng.setEnd(editor.getBody(), 1);124 editor.selection.setRng(rng);125 editor.selection.setContent('<div>text</div>');126 equal(eventObj.content, '<div>text</div>', 'Set selected contents, onSetContent event');127 editor.off('SetContent', handler);128});129test('getStart/getEnd', function() {130 var rng;131 // Selected contents132 editor.setContent('<p id="a">text</p><p id="b">text</p>');133 rng = editor.dom.createRng();134 rng.setStart(editor.getBody().firstChild.firstChild, 0);135 rng.setEnd(editor.getBody().lastChild.firstChild, 0);136 editor.selection.setRng(rng);137 equal(editor.selection.getStart().id, 'a', 'Selected contents (getStart)');138 equal(editor.selection.getEnd().id, 'b', 'Selected contents (getEnd)');139 // Selected contents (collapsed)140 editor.setContent('<p id="a">text</p>\n<p id="b">text</p>');141 rng = editor.dom.createRng();142 rng.setStart(editor.getBody().firstChild.firstChild, 0);143 rng.setEnd(editor.getBody().firstChild.firstChild, 0);144 editor.selection.setRng(rng);145 equal(editor.selection.getStart().id, 'a', 'Selected contents (getStart, collapsed)');146 equal(editor.selection.getEnd().id, 'a', 'Selected contents (getEnd, collapsed)');147});148test('getBookmark/setBookmark (persistent)', function() {149 var rng, bookmark;150 // Get persistent bookmark simple text selection151 editor.setContent('text');152 rng = editor.dom.createRng();153 rng.setStart(editor.getBody().firstChild, 1);154 rng.setEnd(editor.getBody().firstChild, 3);155 editor.selection.setRng(rng);156 bookmark = editor.selection.getBookmark();157 equal(editor.getContent(), 'text', 'Editor contents (text)');158 editor.selection.moveToBookmark(bookmark);159 equal(editor.selection.getContent(), 'ex', 'Selected contents (text)');160 // Get persistent bookmark multiple elements text selection161 editor.setContent('<p>text</p>\n<p>text</p>');162 rng = editor.dom.createRng();163 rng.setStart(editor.getBody().firstChild.firstChild, 1);164 rng.setEnd(editor.getBody().lastChild.firstChild, 3);165 editor.selection.setRng(rng);166 bookmark = editor.selection.getBookmark();167 equal(editor.getContent(), '<p>text</p>\n<p>text</p>', 'Editor contents (elements)');168 editor.selection.moveToBookmark(bookmark);169 equal(editor.selection.getContent(), '<p>ext</p>\n<p>tex</p>', 'Selected contents (elements)');170});171test('getBookmark/setBookmark (simple)', function() {172 var rng, bookmark;173 // Get persistent bookmark simple text selection174 editor.setContent('text');175 rng = editor.dom.createRng();176 rng.setStart(editor.getBody().firstChild, 1);177 rng.setEnd(editor.getBody().firstChild, 3);178 editor.selection.setRng(rng);179 bookmark = editor.selection.getBookmark(1);180 equal(editor.getContent(), 'text', 'Editor contents (text)');181 editor.selection.moveToBookmark(bookmark);182 equal(editor.selection.getContent(), 'ex', 'Selected contents (text)');183 // Get persistent bookmark multiple elements text selection184 editor.setContent('<p>text</p>\n<p>text</p>');185 rng = editor.dom.createRng();186 rng.setStart(editor.getBody().firstChild.firstChild, 1);187 rng.setEnd(editor.getBody().lastChild.firstChild, 3);188 editor.selection.setRng(rng);189 bookmark = editor.selection.getBookmark(1);190 equal(editor.getContent(), '<p>text</p>\n<p>text</p>', 'Editor contents (elements)');191 editor.selection.moveToBookmark(bookmark);192 equal(editor.selection.getContent(), '<p>ext</p>\n<p>tex</p>', 'Selected contents (elements)');193});194test('getBookmark/setBookmark (nonintrusive) - simple text selection', function() {195 var rng, bookmark;196 expect(2);197 editor.setContent('text');198 rng = editor.dom.createRng();199 rng.setStart(editor.getBody().firstChild, 1);200 rng.setEnd(editor.getBody().firstChild, 3);201 editor.selection.setRng(rng);202 bookmark = editor.selection.getBookmark(2);203 equal(editor.getContent(), 'text', 'Editor contents (text)');204 editor.selection.moveToBookmark(bookmark);205 equal(editor.selection.getContent(), 'ex', 'Selected contents (text)');206});207test('getBookmark/setBookmark (nonintrusive) - Get non intrusive bookmark simple element selection', function() {208 var rng, bookmark;209 expect(1);210 // Get non intrusive bookmark simple element selection211 editor.setContent('<p>text<em>a<strong>b</strong>c</em></p>');212 rng = editor.dom.createRng();213 rng.setStart(editor.dom.select('em')[0], 1);214 rng.setEnd(editor.dom.select('em')[0], 2);215 editor.selection.setRng(rng);216 bookmark = editor.selection.getBookmark(2);217 editor.selection.moveToBookmark(bookmark);218 equal(editor.selection.getContent(), '<strong>b</strong>', 'Selected contents (element)');219});220test('getBookmark/setBookmark (nonintrusive) - Get non intrusive bookmark multiple elements text selection', function() {221 var rng, bookmark;222 expect(2);223 // Get non intrusive bookmark multiple elements text selection224 editor.setContent('<p>text</p>\n<p>text</p>');225 rng = editor.dom.createRng();226 rng.setStart(editor.getBody().firstChild.firstChild, 1);227 rng.setEnd(editor.getBody().lastChild.firstChild, 3);228 editor.selection.setRng(rng);229 bookmark = editor.selection.getBookmark(2);230 equal(editor.getContent(), '<p>text</p>\n<p>text</p>', 'Editor contents (elements)');231 editor.selection.moveToBookmark(bookmark);232 equal(editor.selection.getContent(), '<p>ext</p>\n<p>tex</p>', 'Selected contents (elements)');233});234test('getBookmark/setBookmark (nonintrusive)', function() {235 var rng, bookmark;236 expect(2);237 // Get non intrusive bookmark multiple elements text selection fragmented238 editor.setContent('<p>text</p><p>text</p>');239 editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('a'));240 editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('a'));241 editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('a'));242 editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('text'));243 rng = editor.dom.createRng();244 rng.setStart(editor.getBody().firstChild.lastChild, 1);245 rng.setEnd(editor.getBody().lastChild.firstChild, 3);246 editor.selection.setRng(rng);247 bookmark = editor.selection.getBookmark(2);248 equal(editor.getContent(), '<p>textaaatext</p>\n<p>text</p>', 'Editor contents (fragmented, elements)');249 editor.selection.moveToBookmark(bookmark);250 equal(editor.selection.getContent(), '<p>ext</p>\n<p>tex</p>', 'Selected contents (fragmented, elements)');251});252test('getBookmark/setBookmark (nonintrusive) - fragmentext text (normalized)', function() {253 var rng, bookmark;254 expect(2);255 // Get non intrusive bookmark multiple elements text selection fragmented256 editor.setContent('<p>text</p><p>text</p>');257 editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('a'));258 editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('a'));259 editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('a'));260 editor.dom.select('p')[0].appendChild(editor.dom.doc.createTextNode('text'));261 rng = editor.dom.createRng();262 rng.setStart(editor.getBody().firstChild.lastChild, 1);263 rng.setEnd(editor.getBody().lastChild.firstChild, 3);264 editor.selection.setRng(rng);265 bookmark = editor.selection.getBookmark(2, true);266 editor.setContent(editor.getContent());267 equal(editor.getContent(), '<p>textaaatext</p>\n<p>text</p>', 'Editor contents (fragmented, elements)');268 editor.selection.moveToBookmark(bookmark);269 equal(editor.selection.getContent(), '<p>ext</p>\n<p>tex</p>', 'Selected contents (fragmented, elements)');270});271test('getBookmark/setBookmark (nonintrusive) - Get bookmark before image', function() {272 var rng, bookmark;273 expect(4);274 editor.setContent('<p><img src="about:blank" /></p>');275 rng = editor.dom.createRng();276 rng.setStart(editor.getBody().firstChild, 0);277 rng.setEnd(editor.getBody().firstChild, 0);278 editor.selection.setRng(rng);279 bookmark = editor.selection.getBookmark(2, true);280 editor.getBody().innerHTML = editor.getBody().innerHTML;281 editor.selection.moveToBookmark(bookmark);282 rng = editor.selection.getRng(true);283 equal(rng.startContainer, editor.getBody().firstChild);284 equal(rng.startOffset, 0);285 equal(rng.endContainer, editor.getBody().firstChild);286 equal(rng.endOffset, 0);287});288test('getBookmark/setBookmark (nonintrusive) - Get bookmark before/after image', function() {289 var rng, bookmark;290 expect(4);291 editor.setContent('<p><img src="about:blank" /></p>');292 rng = editor.dom.createRng();293 rng.setStart(editor.getBody().firstChild, 0);294 rng.setEnd(editor.getBody().firstChild, 1);295 editor.selection.setRng(rng);296 bookmark = editor.selection.getBookmark(2, true);297 editor.getBody().innerHTML = editor.getBody().innerHTML;298 editor.selection.moveToBookmark(bookmark);299 rng = editor.selection.getRng(true);300 equal(rng.startContainer, editor.getBody().firstChild);301 equal(rng.startOffset, 0);302 equal(rng.endContainer, editor.getBody().firstChild);303 equal(rng.endOffset, 1);304});305test('getBookmark/setBookmark (nonintrusive) - Get bookmark after image', function() {306 var rng, bookmark;307 expect(4);308 editor.setContent('<p><img src="about:blank" /></p>');309 rng = editor.dom.createRng();310 rng.setStart(editor.getBody().firstChild, 1);311 rng.setEnd(editor.getBody().firstChild, 1);312 editor.selection.setRng(rng);313 bookmark = editor.selection.getBookmark(2, true);314 editor.getBody().innerHTML = editor.getBody().innerHTML;315 editor.selection.moveToBookmark(bookmark);316 rng = editor.selection.getRng(true);317 equal(rng.startContainer, editor.getBody().firstChild);318 equal(rng.startOffset, 1);319 equal(rng.endContainer, editor.getBody().firstChild);320 equal(rng.endOffset, 1);321});322test('getBookmark/setBookmark (nonintrusive) - Get bookmark before element', function() {323 var rng, bookmark;324 expect(4);325 editor.setContent('abc<b>123</b>');326 rng = editor.dom.createRng();327 rng.setStart(editor.getBody().firstChild, 0);328 rng.setEnd(editor.getBody().firstChild, 2);329 editor.selection.setRng(rng);330 bookmark = editor.selection.getBookmark(2, true);331 editor.getBody().innerHTML = editor.getBody().innerHTML;332 editor.selection.moveToBookmark(bookmark);333 rng = editor.selection.getRng(true);334 equal(rng.startContainer, editor.getBody().firstChild);335 equal(rng.startOffset, 0);336 equal(rng.endContainer, editor.getBody().firstChild);337 equal(rng.endOffset, 2);338});339test('getBookmark/setBookmark (nonintrusive) - Get bookmark after element', function() {340 var rng, bookmark;341 expect(4);342 // Get bookmark after element343 editor.setContent('<b>123</b>abc');344 rng = editor.dom.createRng();345 rng.setStart(editor.getBody().lastChild, 1);346 rng.setEnd(editor.getBody().lastChild, 2);347 editor.selection.setRng(rng);348 bookmark = editor.selection.getBookmark(2, true);349 editor.getBody().innerHTML = editor.getBody().innerHTML;350 editor.selection.moveToBookmark(bookmark);351 rng = editor.selection.getRng(true);352 equal(rng.startContainer, editor.getBody().lastChild);353 equal(rng.startOffset, 1);354 equal(rng.endContainer, editor.getBody().lastChild);355 equal(rng.endOffset, 2);356});357test('getBookmark/setBookmark (nonintrusive) - Get bookmark inside element', function() {358 var rng, bookmark;359 expect(4);360 editor.setContent('abc<b>123</b>abc');361 rng = editor.dom.createRng();362 rng.setStart(editor.getBody().childNodes[1].firstChild, 1);363 rng.setEnd(editor.getBody().childNodes[1].firstChild, 2);364 editor.selection.setRng(rng);365 bookmark = editor.selection.getBookmark(2, true);366 editor.getBody().innerHTML = editor.getBody().innerHTML;367 editor.selection.moveToBookmark(bookmark);368 rng = editor.selection.getRng(true);369 equal(rng.startContainer, editor.getBody().childNodes[1].firstChild);370 equal(rng.startOffset, 1);371 equal(rng.endContainer, editor.getBody().childNodes[1].firstChild);372 equal(rng.endOffset, 2);373});374test('getBookmark/setBookmark (nonintrusive) - Get bookmark inside root text', function() {375 var rng, bookmark;376 expect(4);377 editor.setContent('abc');378 rng = editor.dom.createRng();379 rng.setStart(editor.getBody().firstChild, 1);380 rng.setEnd(editor.getBody().firstChild, 2);381 editor.selection.setRng(rng);382 bookmark = editor.selection.getBookmark(2, true);383 editor.getBody().innerHTML = editor.getBody().innerHTML;384 editor.selection.moveToBookmark(bookmark);385 rng = editor.selection.getRng(true);386 equal(rng.startContainer, editor.getBody().firstChild);387 equal(rng.startOffset, 1);388 equal(rng.endContainer, editor.getBody().firstChild);389 equal(rng.endOffset, 2);390});391test('getBookmark/setBookmark (nonintrusive) - Get bookmark inside complex html', function() {392 var rng, bookmark;393 expect(4);394 editor.setContent('<p>abc</p>123<p>123</p><p>123<b>123</b><table><tr><td>abc</td></tr></table></p>');395 editor.execCommand('SelectAll');396 Utils.setSelection('td', 1, 'td', 2);397 bookmark = editor.selection.getBookmark(2, true);398 editor.getBody().innerHTML = editor.getBody().innerHTML;399 editor.selection.moveToBookmark(bookmark);400 rng = editor.selection.getRng(true);401 equal(rng.startContainer, editor.dom.select('td')[0].firstChild);402 equal(rng.startOffset, 1);403 equal(rng.endContainer, editor.dom.select('td')[0].firstChild);404 equal(rng.endOffset, 2);405});406test('select empty TD', function() {407 editor.getBody().innerHTML = '<table><tr><td><br></td></tr></table>';408 editor.selection.select(editor.dom.select('td')[0], true);409 equal(editor.selection.getRng(true).startContainer.nodeName, 'TD');410});411test('select first p', 2, function() {412 editor.setContent('<p>text1</p><p>text2</p>');413 editor.selection.select(editor.dom.select('p')[0]);414 equal(editor.selection.getContent(), '<p>text1</p>', 'Select simple element, content');415 equal(editor.selection.getStart().nodeName, 'P', 'Select simple element, nodeName');416});417test('select table', 2, function() {418 editor.setContent('<table><tbody><tr><td>text1</td></tr></tbody></table>');419 editor.selection.select(editor.dom.select('table')[0]);420 equal(editor.selection.getContent(), '<table>\n<tbody>\n<tr>\n<td>text1</td>\n</tr>\n</tbody>\n</table>', 'Select complex element, content');421 equal(editor.selection.getNode().nodeName, 'TABLE', 'Select complex element, nodeName');422});423test('select table text 1', 2, function() {424 editor.setContent('<table><tbody><tr><td id="a">text1</td><td id="b">text2</td></tr></tbody></table>');425 editor.selection.select(editor.dom.select('table')[0], true);426 equal(editor.selection.getStart().id, 'a', 'Expand to text content 1 (start)');427 equal(editor.selection.getEnd().id, 'b', 'Expand to text content 1 (end)');428});429test('select table text 2', 2, function() {430 editor.setContent('<table><tbody><tr><td id="a"><br /></td><td id="b"><br /></td></tr></tbody></table>');431 editor.selection.select(editor.dom.select('table')[0], true);432 equal(editor.dom.getParent(editor.selection.getStart(), 'td').id, 'a', 'Expand to text content 2 (start)');433 equal(editor.dom.getParent(editor.selection.getEnd(), 'td').id, 'b', 'Expand to text content 2 (end)');434});435test('getNode', function() {436 var rng;437 editor.setContent('<p id="p1"><span id="s1">span1</span> word <span id="s2">span2</span> word <span id="s3">span3</span></p>');438 rng = editor.dom.createRng();439 rng.setStart(editor.dom.get('s1').firstChild, 0);440 rng.setEnd(editor.dom.get('s1').nextSibling, 0);441 editor.selection.setRng(rng);442 deepEqual(editor.selection.getNode(), editor.dom.get('s1'), 'Detect selection ends immediately after node at start of paragraph.');443 rng = editor.dom.createRng();444 rng.setStart(editor.dom.get('s2').previousSibling, editor.dom.get('s2').previousSibling.length);445 rng.setEnd(editor.dom.get('s2').nextSibling, 0);446 editor.selection.setRng(rng);447 deepEqual(editor.selection.getNode(), editor.dom.get('s2'), 'Detect selection immediately surrounds node in middle of paragraph.');448 rng = editor.dom.createRng();449 rng.setStart(editor.dom.get('s3').previousSibling, editor.dom.get('s3').previousSibling.length);450 rng.setEnd(editor.dom.get('s3').lastChild, editor.dom.get('s3').lastChild.length);451 editor.selection.setRng(rng);452 deepEqual(editor.selection.getNode(), editor.dom.get('s3'), 'Detect selection starts immediately before node at end of paragraph.');453 rng = editor.dom.createRng();454 rng.setStart(editor.dom.get('s2').previousSibling, editor.dom.get('s2').previousSibling.length);455 rng.setEnd(editor.dom.get('s3').lastChild, editor.dom.get('s3').lastChild.length);456 editor.selection.setRng(rng);457 deepEqual(editor.selection.getNode(), editor.dom.get('p1'), 'Detect selection wrapping multiple nodes does not collapse.');458});459test('normalize to text node from document', function() {460 var rng;461 if (tinymce.isOpera || tinymce.isIE) {462 ok(true, "Skipped on Opera/IE since Opera doesn't let you to set the range to document and IE will steal focus.");463 return;464 }465 editor.setContent('<p>text</p>');466 rng = editor.dom.createRng();467 rng.setStart(editor.getDoc(), 0);468 rng.setEnd(editor.getDoc(), 0);469 editor.selection.setRng(rng);470 editor.selection.normalize();471 rng = editor.selection.getRng(true);472 equal(rng.startContainer.nodeType, 3, 'startContainer node type');473 equal(rng.startOffset, 0, 'startContainer offset');474 equal(rng.endContainer.nodeType, 3, 'endContainer node type');475 equal(rng.endOffset, 0, 'endOffset offset');476});477test('normalize to br from document', function() {478 var rng;479 if (tinymce.isOpera || tinymce.isIE) {480 ok(true, "Skipped on Opera/IE since Opera doesn't let you to set the range to document and IE will steal focus.");481 return;482 }483 editor.setContent('<p><br /></p>');484 rng = editor.dom.createRng();485 rng.setStart(editor.getDoc(), 0);486 rng.setEnd(editor.getDoc(), 0);487 editor.selection.setRng(rng);488 editor.selection.normalize();489 rng = editor.selection.getRng(true);490 equal(rng.startContainer.nodeName, 'P', 'startContainer node name');491 equal(rng.startContainer.nodeType, 1, 'startContainer node type');492 equal(rng.startOffset, 0, 'startContainer offset');493 equal(rng.endContainer.nodeType, 1, 'endContainer node type');494 equal(rng.endOffset, 0, 'endOffset offset');495});496// Only run on non IE browsers since it's not an issue on IE497if (!tinymce.isIE) {498 test('normalize with contentEditable:false element', function() {499 var rng;500 editor.setContent('<p>a<b contentEditable="false">b</b>c</p>');501 rng = editor.dom.createRng();502 rng.setStart(editor.getBody().firstChild.lastChild, 0);503 rng.setEnd(editor.getBody().firstChild.lastChild, 0);504 editor.selection.setRng(rng);505 editor.selection.normalize();506 rng = editor.selection.getRng(true);507 equal(rng.collapsed, true);508 equal(rng.startContainer.nodeType, 3);509 equal(rng.startContainer.data, 'c');510 });511 test('normalize with contentEditable:false parent and contentEditable:true child element', function() {512 editor.setContent('<p contentEditable="false">a<em contentEditable="true">b</em></p>');513 Utils.setSelection('em', 0);514 editor.selection.normalize();515 var rng = editor.selection.getRng(true);516 equal(rng.collapsed, true);517 equal(rng.startContainer.nodeType, 3);518 equal(rng.startContainer.data, 'b');519 });520 test('normalize with contentEditable:true parent and contentEditable:false child element', function() {521 editor.setContent('<p contentEditable="true">a<em contentEditable="false">b</em></p>');522 Utils.setSelection('em', 0);523 editor.selection.normalize();524 var rng = editor.selection.getRng(true);525 equal(rng.collapsed, true);526 equal(rng.startContainer.nodeType, 3);527 equal(rng.startContainer.data, 'a');528 equal(rng.startOffset, 1);529 });530 test('normalize to text node from body', function() {531 var rng;532 editor.setContent('<p>text</p>');533 rng = editor.dom.createRng();534 rng.setStart(editor.getBody(), 0);535 rng.setEnd(editor.getBody(), 0);536 editor.selection.setRng(rng);537 editor.selection.normalize();538 rng = editor.selection.getRng(true);539 equal(rng.startContainer.nodeType, 3, 'startContainer node type');540 equal(rng.startOffset, 0, 'startContainer offset');541 equal(rng.endContainer.nodeType, 3, 'endContainer node type');542 equal(rng.endOffset, 0, 'endOffset offset');543 });544 test('normalize to br from body', function() {545 var rng;546 editor.setContent('<p><br /></p>');547 rng = editor.dom.createRng();548 rng.setStart(editor.getBody(), 0);549 rng.setEnd(editor.getBody(), 0);550 editor.selection.setRng(rng);551 editor.selection.normalize();552 rng = editor.selection.getRng(true);553 equal(rng.startContainer.nodeName, 'P', 'startContainer node name');554 equal(rng.startContainer.nodeType, 1, 'startContainer node type');555 equal(rng.startOffset, 0, 'startContainer offset');556 equal(rng.endContainer.nodeType, 1, 'endContainer node type');557 equal(rng.endOffset, 0, 'endOffset offset');558 });559 test('normalize ignore img', function() {560 var rng;561 editor.getBody().innerHTML = '<img src="about:blank " />';562 rng = editor.dom.createRng();563 rng.setStart(editor.getBody(), 0);564 rng.setEnd(editor.getBody(), 1);565 editor.selection.setRng(rng);566 editor.selection.normalize();567 rng = editor.selection.getRng(true);568 equal(rng.startContainer.nodeName, 'BODY', 'startContainer node name');569 equal(rng.startContainer.nodeType, 1, 'startContainer node type');570 equal(rng.startOffset, 0, 'startContainer offset');571 equal(rng.endContainer.nodeName, 'BODY', 'endContainer node name');572 equal(rng.endContainer.nodeType, 1, 'endContainer node type');573 equal(rng.endOffset, 1, 'endOffset offset');574 });575 test('normalize to before/after img', function() {576 var rng;577 editor.getBody().innerHTML = '<p><img src="about:blank " /></p>';578 rng = editor.dom.createRng();579 rng.setStart(editor.getBody(), 0);580 rng.setEnd(editor.getBody(), 1);581 editor.selection.setRng(rng);582 editor.selection.normalize();583 rng = editor.selection.getRng(true);584 equal(rng.startContainer.nodeName, 'P', 'startContainer node name');585 equal(rng.startContainer.nodeType, 1, 'startContainer node type');586 equal(rng.startOffset, 0, 'startContainer offset');587 equal(rng.endContainer.nodeName, 'P', 'endContainer node name');588 equal(rng.endContainer.nodeType, 1, 'endContainer node type');589 equal(rng.endOffset, 1, 'endOffset offset');590 });591 test('normalize to text node inside P', function() {592 var rng;593 editor.getBody().innerHTML = '<p>abc</p>';594 rng = editor.dom.createRng();595 rng.setStart(editor.getBody(), 0);596 rng.setEnd(editor.getBody(), 1);597 editor.selection.setRng(rng);598 editor.selection.normalize();599 rng = editor.selection.getRng(true);600 equal(rng.startContainer.nodeName, '#text', 'startContainer node name');601 equal(rng.startOffset, 0, 'startContainer offset');602 equal(rng.endContainer.nodeName, '#text', 'endContainer node name');603 equal(rng.endOffset, 3, 'endOffset offset');604 });605 test('normalize lean left if at the start of text node', function() {606 var rng;607 editor.getBody().innerHTML = '<p><b>a</b><i>b</i></p>';608 Utils.setSelection('i', 0);609 editor.selection.normalize();610 rng = editor.selection.getRng(true);611 equal(rng.startContainer.nodeName, '#text', 'startContainer node name');612 equal(rng.startContainer.parentNode.nodeName, 'B');613 equal(rng.startOffset, 1, 'startContainer offset');614 equal(rng.endContainer.nodeName, '#text');615 equal(rng.endContainer.parentNode.nodeName, 'B');616 equal(rng.endOffset, 1, 'endOffset offset');617 });618 test('normalize lean start to the right if at end of text node', function() {619 var rng;620 editor.getBody().innerHTML = '<p><b>a</b><i>b</i></p>';621 Utils.setSelection('b', 1, 'i', 1);622 editor.selection.normalize();623 rng = editor.selection.getRng(true);624 equal(rng.startContainer.nodeName, '#text', 'startContainer node name');625 equal(rng.startContainer.parentNode.nodeName, 'I');626 equal(rng.startOffset, 0, 'startContainer offset');627 equal(rng.endContainer.nodeName, '#text');628 equal(rng.endContainer.parentNode.nodeName, 'I');629 equal(rng.endOffset, 1, 'endOffset offset');630 });631 test('normalize lean left but break before br', function() {632 var rng;633 editor.getBody().innerHTML = '<p>a<br><b>b</b></p>';634 Utils.setSelection('b', 0);635 editor.selection.normalize();636 rng = editor.selection.getRng(true);637 equal(rng.startContainer.nodeValue, 'b');638 equal(rng.startOffset, 0);639 });640 test('normalize lean left but break before img', function() {641 var rng;642 editor.getBody().innerHTML = '<p>a<img><b>b</b></p>';643 Utils.setSelection('b', 0);644 editor.selection.normalize();645 rng = editor.selection.getRng(true);646 equal(rng.startContainer.nodeValue, 'b');647 equal(rng.startOffset, 0);648 });649 test('normalize lean left but don\'t walk out the parent block', function() {650 var rng;651 editor.getBody().innerHTML = '<p>a</p><p><b>b</b></p>';652 Utils.setSelection('b', 0);653 editor.selection.normalize();654 rng = editor.selection.getRng(true);655 equal(rng.startContainer.nodeValue, 'b');656 equal(rng.startOffset, 0);657 });658 test('normalize lean left into empty inline elements when caret is before br', function() {659 var rng;660 editor.getBody().innerHTML = '<p><i><b></b></i><br /></p>';661 rng = editor.dom.createRng();662 rng.setStartBefore(editor.getBody().firstChild.lastChild);663 rng.setEndBefore(editor.getBody().firstChild.lastChild);664 editor.selection.setRng(rng);665 editor.selection.normalize();666 rng = editor.selection.getRng(true);667 equal(rng.startContainer.nodeName, 'B');668 equal(rng.startOffset, 0);669 });670 test('normalize don\'t lean left into empty inline elements if there is a br element after caret', function() {671 var rng;672 editor.getBody().innerHTML = '<p><i><b></b></i><br /><br /></p>';673 rng = editor.dom.createRng();674 rng.setStartBefore(editor.getBody().firstChild.lastChild);675 rng.setEndBefore(editor.getBody().firstChild.lastChild);676 editor.selection.setRng(rng);677 editor.selection.normalize();678 rng = editor.selection.getRng(true);679 equal(rng.startContainer.nodeName, 'P');680 equal(rng.startOffset, 2);681 });682 test('normalize don\'t lean left into empty inline elements if there is a br element before caret', function() {683 var rng;684 editor.getBody().innerHTML = '<p><i><b><br /></b></i><br /></p>';685 rng = editor.dom.createRng();686 rng.setStartBefore(editor.getBody().firstChild.lastChild);687 rng.setEndBefore(editor.getBody().firstChild.lastChild);688 editor.selection.setRng(rng);689 editor.selection.normalize();690 rng = editor.selection.getRng(true);691 equal(rng.startContainer.nodeName, 'P');692 equal(rng.startOffset, 1);693 });694 test('normalize don\'t move start/end if it\'s before/after table', function() {695 var rng;696 editor.getBody().innerHTML = '<table><tr><td>X</td></tr></table>';697 rng = editor.dom.createRng();698 rng.setStartBefore(editor.getBody().firstChild);699 rng.setEndAfter(editor.getBody().lastChild);700 editor.selection.setRng(rng);701 editor.selection.normalize();702 rng = editor.selection.getRng(true);703 equal(rng.startContainer.nodeName, 'BODY');704 equal(rng.startOffset, 0);705 equal(rng.endContainer.nodeName, 'BODY');706 equal(rng.endOffset, 1);707 });708 test('normalize after paragraph', function() {709 var rng;710 editor.getBody().innerHTML = '<p>a</p>';711 rng = editor.dom.createRng();712 rng.setStartAfter(editor.getBody().firstChild);713 rng.setEndAfter(editor.getBody().lastChild);714 editor.selection.setRng(rng);715 editor.selection.normalize();716 rng = editor.selection.getRng(true);717 equal(rng.startContainer.nodeName, '#text');718 equal(rng.startOffset, 1);719 equal(rng.endContainer.nodeName, '#text');720 equal(rng.endOffset, 1);721 });722 test('normalize caret after trailing BR', function() {723 var rng;724 editor.setContent('<p>a<br /></p>');725 rng = editor.dom.createRng();726 rng.setStart(editor.getBody().firstChild, 2);727 rng.setEnd(editor.getBody().firstChild, 2);728 editor.selection.setRng(rng);729 editor.selection.normalize();730 rng = editor.selection.getRng(true);731 equal(rng.startContainer.nodeName, '#text', 'startContainer node name');732 equal(rng.startOffset, 1, 'startContainer offset');733 equal(rng.endContainer.nodeName, '#text', 'endContainer node name');734 equal(rng.endOffset, 1, 'endOffset offset');735 });736 test('normalize caret after bogus block BR', function() {737 var rng;738 editor.setContent('<p><br /></p>');739 rng = editor.dom.createRng();740 rng.setStart(editor.getBody().firstChild, 1);741 rng.setEnd(editor.getBody().firstChild, 1);742 editor.selection.setRng(rng);743 editor.selection.normalize();744 rng = editor.selection.getRng(true);745 equal(rng.startContainer.nodeName, 'P', 'startContainer node name');746 equal(rng.startOffset, 0, 'startContainer offset');747 equal(rng.endContainer.nodeName, 'P', 'endContainer node name');748 equal(rng.endOffset, 0, 'endOffset offset');749 });750/*751 test('normalize caret after last BR in block', function() {752 var rng;753 editor.setContent('<p><br /><br /></p>');754 rng = editor.dom.createRng();755 rng.setStart(editor.getBody().firstChild, 2);756 rng.setEnd(editor.getBody().firstChild, 2);757 editor.selection.setRng(rng);758 editor.selection.normalize();759 rng = editor.selection.getRng(true);760 equal(rng.startContainer.nodeName, 'P', 'startContainer node name');761 equal(rng.startOffset, 1, 'startContainer offset');762 equal(rng.endContainer.nodeName, 'P', 'endContainer node name');763 equal(rng.endOffset, 1, 'endOffset offset');764 });765*/766 test('normalize caret after double BR', function() {767 var rng;768 editor.setContent('<p>a<br /><br /></p>');769 rng = editor.dom.createRng();770 rng.setStart(editor.getBody().firstChild, 3);771 rng.setEnd(editor.getBody().firstChild, 3);772 editor.selection.setRng(rng);773 editor.selection.normalize();774 rng = editor.selection.getRng(true);775 equal(rng.startContainer.nodeName, 'P', 'startContainer node name');776 equal(rng.startOffset, 3, 'startContainer offset');777 equal(rng.endContainer.nodeName, 'P', 'endContainer node name');778 equal(rng.endOffset, 3, 'endOffset offset');779 });780}781test('custom elements', function() {782 var rng;783 editor.setContent('<custom1>test</custom1><custom2>test</custom2>');784 rng = editor.dom.createRng();785 rng.setStart(editor.getBody(), 0);786 rng.setEnd(editor.getBody(), 2);787 editor.selection.setRng(rng);788 equal(editor.selection.getContent(), '<custom1>test</custom1><custom2>test</custom2>');789});790test('selectorChanged', function() {791 var newState, newArgs;792 editor.selection.selectorChanged('a[href]', function(state, args) {793 newState = state;794 newArgs = args;795 });796 editor.getBody().innerHTML = '<p><a href="#">text</a></p>';797 Utils.setSelection('a', 0, 'a', 4);798 editor.nodeChanged();799 ok(newState);800 equal(newArgs.selector, 'a[href]');801 equal(newArgs.node, editor.getBody().firstChild.firstChild);802 equal(newArgs.parents.length, 2);803 editor.getBody().innerHTML = '<p>text</p>';804 Utils.setSelection('p', 0, 'p', 4);805 editor.nodeChanged();806 equal(newArgs.selector, 'a[href]');807 equal(newArgs.node, editor.getBody().firstChild);808 equal(newArgs.parents.length, 1);809});810test('setRng', function() {811 var rng = editor.dom.createRng();812 editor.setContent('<p>x</p>');813 rng.setStart(editor.$('p')[0].firstChild, 0);814 rng.setEnd(editor.$('p')[0].firstChild, 1);815 editor.selection.setRng(rng);816 editor.selection.setRng(null);817 rng = editor.selection.getRng(true);818 equal(rng.startContainer.nodeName, '#text');819 equal(rng.startOffset, 0);820 equal(rng.endContainer.nodeName, '#text');821 equal(rng.endOffset, 1);...

Full Screen

Full Screen

TridentSelection.js

Source:TridentSelection.js Github

copy

Full Screen

...26 format: 'raw'27 });28 29 var rng = editor.dom.createRng();30 rng.setStart(editor.getBody(), 0);31 rng.setEnd(editor.getBody(), 1);32 editor.selection.setRng(rng);33 34 rng = editor.selection.getRng(1);35 equal(rng.startContainer.nodeName, '#text', 'Start container is text node');36 equal(rng.endContainer.nodeName, '#text', 'End container is text node');37 equal(rng.startOffset, 0, 'Start of text node');38 equal(rng.endOffset, 3, 'End of text node');39 equal(editor.dom.getOuterHTML(rng.cloneContents()), '123', 'Contents matches');40 });41 42 test("Single image selection", function(){43 expect(6);44 45 editor.setContent('<p><img src="about:blank" /></p>', {46 format: 'raw'47 });48 49 var rng = editor.dom.createRng();50 rng.setStartBefore(editor.dom.select('img')[0]);51 rng.setEndAfter(editor.dom.select('img')[0]);52 editor.selection.setRng(rng);53 54 rng = editor.selection.getRng(1);55 equal(rng.startContainer.nodeName, 'P', 'Check startContainer');56 equal(rng.endContainer.nodeName, 'P', 'Check endContainer');57 equal(rng.startOffset, 0, 'Check startOffset');58 equal(rng.endOffset, 1, 'Check endOffset');59 equal(Utils.cleanHtml(editor.dom.getOuterHTML(rng.cloneContents()).toLowerCase()), '<img src="about:blank">', 'Check contents');60 ok(editor.selection.getRng().item, 'Check if it\'s a control selection');61 });62 63 test("Multiple image selection", function(){64 expect(6);65 66 editor.setContent('<p><img src="about:blank" /><img src="about:blank" /></p>', {67 format: 'raw'68 });69 70 var rng = editor.dom.createRng();71 rng.setStartBefore(editor.dom.select('img')[0]);72 rng.setEndAfter(editor.dom.select('img')[1]);73 editor.selection.setRng(rng);74 75 rng = editor.selection.getRng(1);76 equal(rng.startContainer.nodeName, 'P');77 equal(rng.endContainer.nodeName, 'P');78 equal(rng.startOffset, 0);79 equal(rng.endOffset, 2);80 equal(editor.dom.getOuterHTML(rng.cloneContents()).toLowerCase(), '<img src="about:blank"><img src="about:blank">');81 ok(editor.selection.getRng().parentElement, 'Is text selection');82 });83 84 test("Text node selection", function(){85 expect(5);86 87 editor.setContent('<p>1234</p>', {88 format: 'raw'89 });90 91 var rng = editor.dom.createRng();92 rng.setStart(editor.getBody().firstChild.firstChild, 1);93 rng.setEnd(editor.getBody().firstChild.firstChild, 3);94 editor.selection.setRng(rng);95 96 rng = editor.selection.getRng(1);97 equal(rng.startContainer.nodeName, '#text');98 equal(rng.endContainer.nodeName, '#text');99 equal(rng.startOffset, 1);100 equal(rng.endOffset, 3);101 equal(editor.dom.getOuterHTML(rng.cloneContents()), '23');102 });103 104 test("Text node selection between two elements", function(){105 expect(5);106 107 editor.setContent('<p>1234</p><p>abcd</p>', {108 format: 'raw'109 });110 111 var rng = editor.dom.createRng();112 rng.setStart(editor.getBody().firstChild.firstChild, 1);113 rng.setEnd(editor.getBody().childNodes[1].firstChild, 3);114 editor.selection.setRng(rng);115 116 rng = editor.selection.getRng(1);117 equal(rng.startContainer.nodeName, '#text');118 equal(rng.endContainer.nodeName, '#text');119 equal(rng.startOffset, 1);120 equal(rng.endOffset, 3);121 equal(editor.dom.getOuterHTML(rng.cloneContents()).replace(/[\r\n]/g, '').toLowerCase(), '<p>234</p><p>abc</p>');122 123 editor.setContent('<p>1</p><p>1234</p><p>abcd</p><p>2</p>', {124 format: 'raw'125 });126 });127 128 test("Mixed selection start at element end at text", function(){129 expect(5);130 131 editor.setContent('<p><img src="about:blank" />text</p>', {132 format: 'raw'133 });134 135 var rng = editor.dom.createRng();136 rng.setStartBefore(editor.dom.select('img')[0]);137 rng.setEnd(editor.getBody().firstChild.lastChild, 3);138 editor.selection.setRng(rng);139 140 rng = editor.selection.getRng(1);141 equal(rng.startContainer.nodeName, 'P');142 equal(rng.endContainer.nodeName, '#text');143 equal(rng.startOffset, 0);144 equal(rng.endOffset, 3);145 equal(editor.dom.getOuterHTML(rng.cloneContents()).toLowerCase(), '<img src="about:blank">tex');146 });147 148 test("Mixed selection start at text end at element", function(){149 expect(5);150 151 editor.setContent('<p>text<img src="about:blank" /></p>', {152 format: 'raw'153 });154 155 var rng = editor.dom.createRng();156 rng.setStart(editor.getBody().firstChild.firstChild, 1);157 rng.setEndAfter(editor.getBody().firstChild.lastChild);158 editor.selection.setRng(rng);159 160 rng = editor.selection.getRng(1);161 162 equal(rng.startContainer.nodeName, '#text');163 equal(rng.startOffset, 1);164 165 equal(rng.endContainer.nodeName, 'P');166 equal(rng.endOffset, 2);167 168 equal(editor.dom.getOuterHTML(rng.cloneContents()).toLowerCase(), 'ext<img src="about:blank">');169 });170 171 test("Caret position before image", function(){172 expect(4);173 174 editor.setContent('<p><img src="about:blank" /><img src="about:blank" /></p>', {175 format: 'raw'176 });177 178 var rng = editor.dom.createRng();179 rng.setStartBefore(editor.dom.select('img')[0]);180 rng.setEndBefore(editor.dom.select('img')[0]);181 editor.selection.setRng(rng);182 183 rng = editor.selection.getRng(1);184 equal(rng.startContainer.nodeName, 'P');185 equal(rng.endContainer.nodeName, 'P');186 equal(rng.startOffset, 0);187 equal(rng.endOffset, 0);188 });189 190 test("Caret position between images", function(){191 expect(4);192 193 editor.setContent('<p><img src="about:blank" /><img src="about:blank" /></p>', {194 format: 'raw'195 });196 197 var rng = editor.dom.createRng();198 rng.setStartAfter(editor.dom.select('img')[0]);199 rng.setEndAfter(editor.dom.select('img')[0]);200 editor.selection.setRng(rng);201 202 rng = editor.selection.getRng(1);203 equal(rng.startContainer.nodeName, 'P');204 equal(rng.endContainer.nodeName, 'P');205 equal(rng.startOffset, 1);206 equal(rng.endOffset, 1);207 });208 209 test("Caret position after image", function(){210 expect(4);211 212 editor.setContent('<p><img src="about:blank" /><img src="about:blank" /></p>', {213 format: 'raw'214 });215 216 var rng = editor.dom.createRng();217 rng.setStartAfter(editor.dom.select('img')[1]);218 rng.setEndAfter(editor.dom.select('img')[1]);219 editor.selection.setRng(rng);220 221 rng = editor.selection.getRng(1);222 equal(rng.startContainer.nodeName, 'P');223 equal(rng.endContainer.nodeName, 'P');224 equal(rng.startOffset, 2);225 equal(rng.endOffset, 2);226 });227 228 test("Selection of empty text element", function(){229 expect(6);230 231 editor.setContent('<div></div>', {232 format: 'raw'233 });234 235 var rng = editor.dom.createRng();236 rng.setStart(editor.getBody(), 0);237 rng.setEnd(editor.getBody(), 1);238 editor.selection.setRng(rng);239 240 rng = editor.selection.getRng(true);241 equal(rng.startContainer.nodeName, 'BODY');242 equal(rng.endContainer.nodeName, 'BODY');243 equal(rng.startOffset, 0);244 equal(rng.endOffset, 1);245 equal(rng.startContainer.childNodes[0].innerHTML, '');246 equal(editor.dom.getOuterHTML(rng.cloneContents()).toLowerCase(), '<div></div>');247 });248 test("Selection of empty text element with caret inside", function(){249 expect(6);250 251 editor.setContent('<div></div>', {252 format: 'raw'253 });254 255 var rng = editor.dom.createRng();256 rng.setStart(editor.getBody().firstChild, 0);257 rng.setEnd(editor.getBody().firstChild, 0);258 editor.selection.setRng(rng);259 260 rng = editor.selection.getRng(true);261 equal(rng.startContainer.nodeName, 'DIV');262 equal(rng.endContainer.nodeName, 'DIV');263 equal(rng.startOffset, 0);264 equal(rng.endOffset, 0);265 equal(rng.startContainer.innerHTML, '');266 equal(editor.dom.getOuterHTML(rng.cloneContents()).toLowerCase(), '');267 });268 /*test("Caret position before table", function() {269 var table, rng;270 editor.focus();271 editor.setContent('<p>Before</p><table id="table" border="1"><tr><td>Cell 1</td><td>Cell 2</td></tr><tr><td>Cell 3</td><td>Cell 4</td></tr></table><p>After</p>');272 table = editor.dom.get('table');273 rng = editor.selection.getRng();274 rng.moveToElementText(table);275 rng.move('character', -1);276 rng.select();277 rng = editor.selection.getRng(1);278 equal(rng.startContainer.nodeName, 'BODY');279 equal(rng.startOffset, 1);280 equal(rng.endContainer.nodeName, 'BODY');281 equal(rng.endOffset, 1);282 });*/283 test("Selection end within empty element", function() {284 var rng;285 editor.focus();286 editor.getBody().innerHTML = '<p>123</p><p></p>';287 rng = editor.execCommand('SelectAll');288 rng = editor.selection.getRng(true);289 equal(rng.startContainer.nodeName, '#text');290 equal(rng.startOffset, 0);291 equal(rng.endContainer.nodeName, 'BODY');292 equal(rng.endOffset, 2);293 });294 test("Selection after paragraph", function() {295 var rng;296 editor.focus();297 editor.getBody().innerHTML = '<p>123</p><p>abcd</p>';298 rng = editor.dom.createRng();299 rng.setStart(editor.getBody().firstChild, 1);300 rng.setEnd(editor.getBody().firstChild, 1);301 editor.selection.setRng(rng);302 rng = editor.selection.getRng(true);303 ok(rng.startContainer == rng.endContainer);304 equal(rng.startContainer.nodeName, '#text');305 equal(rng.startOffset, 3);306 equal(rng.endContainer.nodeName, '#text');307 equal(rng.endOffset, 3);308 });309 test("Selection of text outside of a block element", function() {310 var r;311 312 editor.settings.forced_root_block = '';313 editor.focus();314 editor.getBody().innerHTML = '<ul><li>Item</li></ul>Text';315 r = editor.dom.createRng();316 r.setStart(editor.getBody().lastChild, 2);317 r.setEnd(editor.getBody().lastChild, 2);318 editor.selection.setRng(r);319 r = editor.selection.getRng(true);320 equal(r.startContainer, editor.getBody().lastChild, "Start container is text node.");321 equal(r.endContainer, editor.getBody().lastChild, "End container is text node.");322 equal(r.startOffset, 2);323 equal(r.endOffset, 2);324 equal(editor.selection.getStart(), editor.getBody(), "Selection start is body.");325 deepEqual(editor.selection.getSelectedBlocks(), [], "No blocks selected.");326 });327 test("Resizable element text selection", function() {328 var r;329 editor.getBody().innerHTML = '<div style="width: 100px; height:100px;"><table><tr><td>.</td></tr></table>abc</div>';330 editor.focus();331 r = editor.dom.createRng();332 r.setStart(editor.getBody().firstChild.lastChild, 1);333 r.setEnd(editor.getBody().firstChild.lastChild, 2);334 editor.selection.setRng(r);335 r = editor.selection.getRng(true);336 equal(r.startContainer, editor.getBody().firstChild.lastChild, "Start container is text node.");337 equal(r.endContainer, editor.getBody().firstChild.lastChild, "End container is text node.");338 equal(r.startOffset, 1);339 equal(r.endOffset, 2);340 });341 test("Resizable element before table selection", function() {342 var r;343 editor.getBody().innerHTML = '<div style="width: 100px; height:100px;"><table><tr><td>.</td></tr></table></div>';344 editor.focus();345 r = editor.dom.createRng();346 r.setStart(editor.getBody().firstChild, 0);347 r.setEnd(editor.getBody().firstChild, 0);348 editor.selection.setRng(r);349 r = editor.selection.getRng(true);350 equal(r.startContainer, editor.getBody().firstChild, "Start container is div node.");351 equal(r.endContainer, editor.getBody().firstChild, "End container is div node.");352 equal(r.startOffset, 0);353 equal(r.endOffset, 0);354 });355 test("Fragmented text nodes after element", function() {356 var r;357 editor.getBody().innerHTML = '<b>x</b>';358 editor.getBody().appendChild(editor.getDoc().createTextNode('1'));359 editor.getBody().appendChild(editor.getDoc().createTextNode('23'));360 editor.getBody().appendChild(editor.getDoc().createTextNode('456'));361 editor.getBody().appendChild(editor.getDoc().createTextNode('7890'));362 editor.focus();363 r = editor.dom.createRng();364 r.setStart(editor.getBody().lastChild, 1);365 r.setEnd(editor.getBody().lastChild, 1);366 editor.selection.setRng(r);367 r = editor.selection.getRng(true);368 equal(r.startContainer, editor.getBody().lastChild, "Start container is last text node.");369 equal(r.endContainer, editor.getBody().lastChild, "End container is last text node.");370 equal(r.startOffset, 1);371 equal(r.endOffset, 1);372 r = editor.dom.createRng();373 r.setStart(editor.getBody().childNodes[2], 2);374 r.setEnd(editor.getBody().childNodes[2], 2);375 editor.selection.setRng(r);376 r = editor.selection.getRng(true);377 equal(r.startContainer, editor.getBody().childNodes[2], "Start container is second text node.");378 equal(r.endContainer, editor.getBody().childNodes[2], "End container is second text node.");379 equal(r.startOffset, 2);380 equal(r.endOffset, 2);381 r = editor.dom.createRng();382 r.setStart(editor.getBody().childNodes[3], 0);383 r.setEnd(editor.getBody().childNodes[3], 1);384 editor.selection.setRng(r);385 r = editor.selection.getRng(true);386 equal(r.startContainer, editor.getBody().childNodes[2], "Start container is second text node (lean left).");387 equal(r.endContainer, editor.getBody().childNodes[3], "End container is third text node.");388 equal(r.startOffset, 2);389 equal(r.endOffset, 1);390 });391 test("Fragmented text nodes before element", function() {392 var r;393 editor.getBody().innerHTML = '';394 editor.getBody().appendChild(editor.getDoc().createTextNode('1'));395 editor.getBody().appendChild(editor.getDoc().createTextNode('23'));396 editor.getBody().appendChild(editor.getDoc().createTextNode('456'));397 editor.getBody().appendChild(editor.getDoc().createTextNode('7890'));398 editor.getBody().appendChild(editor.dom.create('b', null, 'x'));399 editor.focus();400 r = editor.dom.createRng();401 r.setStart(editor.getBody().childNodes[3], 1);402 r.setEnd(editor.getBody().childNodes[3], 1);403 editor.selection.setRng(r);404 r = editor.selection.getRng(true);405 equal(r.startContainer, editor.getBody().childNodes[3], "Start container is last text node.");406 equal(r.endContainer, editor.getBody().childNodes[3], "End container is last text node.");407 equal(r.startContainer.nodeValue, '7890');408 equal(r.startOffset, 1);409 equal(r.endOffset, 1);410 r = editor.dom.createRng();411 r.setStart(editor.getBody().childNodes[1], 2);412 r.setEnd(editor.getBody().childNodes[1], 2);413 editor.selection.setRng(r);414 r = editor.selection.getRng(true);415 equal(r.startContainer, editor.getBody().childNodes[2], "Start container is second text node. (lean right)");416 equal(r.endContainer, editor.getBody().childNodes[2], "End container is second text node.");417 equal(r.startContainer.nodeValue, '456');418 equal(r.startOffset, 0);419 equal(r.endOffset, 0);420 r = editor.dom.createRng();421 r.setStart(editor.getBody().childNodes[1], 0);422 r.setEnd(editor.getBody().childNodes[1], 1);423 editor.selection.setRng(r);424 r = editor.selection.getRng(true);425 equal(r.startContainer, editor.getBody().childNodes[1], "Start container is second text node.");426 equal(r.endContainer, editor.getBody().childNodes[1], "End container is third text node.");427 equal(r.startContainer.nodeValue, '23');428 equal(r.endContainer.nodeValue, '23');429 equal(r.startOffset, 0);430 equal(r.endOffset, 1);431 });432 test("Non contentEditable elements", function() {433 var r;434 editor.getBody().innerHTML = '<span contentEditable="false">a</span><span contentEditable="false">a</span><span contentEditable="false">a</span>';435 editor.focus();436 r = editor.dom.createRng();437 r.setStart(editor.getBody(), 0);438 r.setEnd(editor.getBody(), 0);439 editor.selection.setRng(r);440 r = editor.selection.getRng(true);441 equal(r.startContainer, editor.getBody(), "Start container is before first nonEditable.");442 equal(r.endContainer, editor.getBody(), "End container is before first nonEditable.");443 equal(r.startOffset, 0);444 equal(r.endOffset, 0);445 r = editor.dom.createRng();446 r.setStart(editor.getBody(), 0);447 r.setEnd(editor.getBody(), 1);448 editor.selection.setRng(r);449 r = editor.selection.getRng(true);450 equal(r.startContainer, editor.getBody(), "Start container before first nonEditable.");451 equal(r.endContainer, editor.getBody(), "End container is after first nonEditable.");452 equal(r.startOffset, 0);453 equal(r.endOffset, 1);454 r = editor.dom.createRng();455 r.setStart(editor.getBody(), 0);456 r.setEnd(editor.getBody(), 2);457 editor.selection.setRng(r);458 r = editor.selection.getRng(true);459 equal(r.startContainer, editor.getBody(), "Start container before first nonEditable.");460 equal(r.endContainer, editor.getBody(), "End container is after second nonEditable.");461 equal(r.startOffset, 0);462 equal(r.endOffset, 2);463 r = editor.dom.createRng();464 r.setStart(editor.getBody(), 1);465 r.setEnd(editor.getBody(), 1);466 editor.selection.setRng(r);467 r = editor.selection.getRng(true);468 equal(r.startContainer, editor.getBody(), "Start container is before second nonEditable.");469 equal(r.endContainer, editor.getBody(), "End container is div before second nonEditable.");470 equal(r.startOffset, 1);471 equal(r.endOffset, 1);472 r = editor.dom.createRng();473 r.setStart(editor.getBody(), 2);474 r.setEnd(editor.getBody(), 2);475 editor.selection.setRng(r);476 r = editor.selection.getRng(true);477 equal(r.startContainer, editor.getBody(), "Start container is after last nonEditable.");478 equal(r.endContainer, editor.getBody(), "End container is after last nonEditable.");479 equal(r.startOffset, 2);480 equal(r.endOffset, 2);481 });482} else {483 test("Skipped ie_selection tests as not running in IE.", function() {484 ok(true, "Dummy assert");485 });...

Full Screen

Full Screen

QuirksWebkitTest.js

Source:QuirksWebkitTest.js Github

copy

Full Screen

...14 var failure = arguments[arguments.length - 1];15 var suite = LegacyUnit.createSuite();16 Theme();17 suite.test('Delete from beginning of P into H1', function (editor) {18 editor.getBody().innerHTML = '<h1>a</h1><p>b</p>';19 LegacyUnit.setSelection(editor, 'p', 0);20 editor.execCommand('Delete');21 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<h1>ab</h1>');22 LegacyUnit.equal(editor.selection.getStart().nodeName, 'H1');23 });24 suite.test('Delete between empty paragraphs', function (editor) {25 editor.getBody().innerHTML = '<p>a</p><p><br></p><p><br></p><p>b</p>';26 LegacyUnit.setSelection(editor, 'p:last', 0);27 editor.execCommand('Delete');28 LegacyUnit.equal(HtmlUtils.normalizeHtml(HtmlUtils.cleanHtml(editor.getBody().innerHTML)), '<p>a</p><p><br /></p><p>b</p>');29 LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');30 });31 suite.test('Delete range from middle of H1 to middle of span in P', function (editor) {32 editor.getBody().innerHTML = '<h1>ab</h1><p>b<span style="color:red">cd</span></p>';33 LegacyUnit.setSelection(editor, 'h1', 1, 'span', 1);34 editor.execCommand('Delete');35 LegacyUnit.equal(36 HtmlUtils.normalizeHtml(HtmlUtils.cleanHtml(editor.getBody().innerHTML)),37 '<h1>a<span style="color: red;">d</span></h1>'38 );39 LegacyUnit.equal(editor.selection.getStart().nodeName, 'H1');40 });41 suite.test('Delete from beginning of P with style span inside into H1 with inline block', function (editor) {42 editor.getBody().innerHTML = '<h1>a<input type="text"></h1><p>b<span style="color:red">c</span></p>';43 LegacyUnit.setSelection(editor, 'p', 0);44 editor.execCommand('Delete');45 LegacyUnit.equal(editor.getContent(), '<h1>a<input type="text" />b<span style="color: red;">c</span></h1>');46 LegacyUnit.equal(editor.selection.getNode().nodeName, 'H1');47 });48 suite.test('Delete from beginning of P with style span inside into H1', function (editor) {49 editor.getBody().innerHTML = '<h1>a</h1><p>b<span style="color:red">c</span></p>';50 LegacyUnit.setSelection(editor, 'p', 0);51 editor.execCommand('Delete');52 LegacyUnit.equal(editor.getContent(), '<h1>ab<span style="color: red;">c</span></h1>');53 LegacyUnit.equal(editor.selection.getStart().nodeName, 'H1');54 });55 suite.test('Delete from beginning of P into H1 with contentEditable:false', function (editor) {56 editor.getBody().innerHTML = '<h1 contentEditable="false">a</h1><p>b<span style="color:red">c</span></p>';57 LegacyUnit.setSelection(editor, 'p', 0);58 editor.execCommand('Delete');59 LegacyUnit.equal(editor.getContent(), '<h1 contenteditable="false">a</h1><p>b<span style="color: red;">c</span></p>');60 LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');61 });62 suite.test('Delete from beginning of P with style span inside into H1 with trailing BR', function (editor) {63 editor.getBody().innerHTML = '<h1>a<br></h1><p>b<span style="color:red">c</span></p>';64 LegacyUnit.setSelection(editor, 'p', 0);65 editor.execCommand('Delete');66 LegacyUnit.equal(editor.getContent(), '<h1>ab<span style="color: red;">c</span></h1>');67 LegacyUnit.equal(editor.selection.getStart().nodeName, 'H1');68 });69 suite.test('Delete from empty P with style span inside into H1', function (editor) {70 editor.getBody().innerHTML = '<h1>a<br></h1><p><span style="color:red">b</span></p>';71 LegacyUnit.setSelection(editor, 'span', 0);72 editor.execCommand('Delete');73 LegacyUnit.equal(editor.getContent(), '<h1>a<span style="color: red;">b</span></h1>');74 LegacyUnit.equal(editor.selection.getNode().nodeName, 'H1');75 });76 suite.test('Delete from beginning of P with span style to H1', function (editor) {77 editor.getBody().innerHTML = '<h1>a</h1><p><span style="color:red">b</span></p>';78 LegacyUnit.setSelection(editor, 'span', 0);79 editor.execCommand('Delete');80 LegacyUnit.equal(editor.getContent(), '<h1>a<span style="color: red;">b</span></h1>');81 LegacyUnit.equal(editor.selection.getNode().nodeName, 'H1');82 });83 suite.test('Delete from beginning of P with BR line to H1', function (editor) {84 editor.getBody().innerHTML = '<h1>a</h1><p>b<br>c</p>';85 LegacyUnit.setSelection(editor, 'p', 0);86 editor.execCommand('Delete');87 LegacyUnit.equal(HtmlUtils.normalizeHtml(HtmlUtils.cleanHtml(editor.getBody().innerHTML)), '<h1>ab<br />c</h1>');88 LegacyUnit.equal(editor.selection.getStart().nodeName, 'H1');89 });90 suite.test('Delete from after image to paragraph', function (editor) {91 editor.getBody().innerHTML = '<p>a</p><p><img src="about:blank"></p>';92 var rng = editor.dom.createRng();93 rng.setStartAfter(editor.dom.select('img')[0]);94 rng.setEndAfter(editor.dom.select('img')[0]);95 editor.selection.setRng(rng);96 editor.execCommand('Delete');97 LegacyUnit.equal(HtmlUtils.normalizeHtml(HtmlUtils.cleanHtml(editor.getBody().innerHTML)), '<p>a</p><p><br /></p>');98 LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');99 });100 suite.test('ForwardDelete from end of H1 to P with style span', function (editor) {101 editor.getBody().innerHTML = '<h1>a</h1><p><span style="color:red">b</span></p>';102 LegacyUnit.setSelection(editor, 'h1', 1);103 editor.execCommand('ForwardDelete');104 LegacyUnit.equal(editor.getContent(), '<h1>a<span style="color: red;">b</span></h1>');105 LegacyUnit.equal(editor.selection.getNode().nodeName, 'H1');106 });107 suite.test('ForwardDelete from end of H1 with trailing BR to P with style span', function (editor) {108 editor.getBody().innerHTML = '<h1>a<br></h1><p><span style="color:red">b</span></p>';109 LegacyUnit.setSelection(editor, 'h1', 1);110 editor.execCommand('ForwardDelete');111 LegacyUnit.equal(editor.getContent(), '<h1>a<span style="color: red;">b</span></h1>');112 LegacyUnit.equal(editor.selection.getNode().nodeName, 'H1');113 });114 suite.test('ForwardDelete from end of H1 with two trailing BR:s to P with style span', function (editor) {115 editor.getBody().innerHTML = '<h1>a<br><br></h1><p><span style="color:red">b</span></p>';116 LegacyUnit.setSelection(editor, 'h1', 1);117 editor.execCommand('ForwardDelete');118 LegacyUnit.equal(editor.getContent(), '<h1>a</h1><p><span style="color: red;">b</span></p>');119 LegacyUnit.equal(editor.selection.getStart().nodeName, 'H1');120 });121 suite.test('ForwardDelete from end of H1 to P with style and inline block element', function (editor) {122 editor.getBody().innerHTML = '<h1>a</h1><p><input type="text"><span style="color:red">b</span></p>';123 LegacyUnit.setSelection(editor, 'h1', 1);124 editor.execCommand('ForwardDelete');125 LegacyUnit.equal(editor.getContent(), '<h1>a<input type="text" /><span style="color: red;">b</span></h1>');126 LegacyUnit.equal(editor.selection.getStart().nodeName, 'H1');127 });128 suite.test('ForwardDelete from end of H1 with BR line to P', function (editor) {129 editor.getBody().innerHTML = '<h1>a<br>b</h1><p>c</p>';130 var rng = editor.selection.getRng();131 rng.setStart(editor.$('h1')[0].lastChild, 1);132 rng.setEnd(editor.$('h1')[0].lastChild, 1);133 editor.selection.setRng(rng);134 editor.execCommand('ForwardDelete');135 LegacyUnit.equal(HtmlUtils.normalizeHtml(HtmlUtils.cleanHtml(editor.getBody().innerHTML)), '<h1>a<br />bc</h1>');136 LegacyUnit.equal(editor.selection.getStart().nodeName, 'H1');137 });138 suite.test('ForwardDelete from end of H1 into P', function (editor) {139 editor.getBody().innerHTML = '<h1>a</h1><p>b</p>';140 LegacyUnit.setSelection(editor, 'h1', 1);141 editor.execCommand('ForwardDelete');142 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<h1>ab</h1>');143 LegacyUnit.equal(editor.selection.getStart().nodeName, 'H1');144 });145 suite.test('ForwardDelete from end of H1 into P with contentEditable:false', function (editor) {146 editor.getBody().innerHTML = '<h1>a</h1><p contentEditable="false">b</p>';147 LegacyUnit.setSelection(editor, 'h1', 1);148 editor.execCommand('ForwardDelete');149 LegacyUnit.equal(editor.getContent(), '<h1>a</h1><p contenteditable="false">b</p>');150 });151 suite.test('ForwardDelete from end of H1 into P with style span inside', function (editor) {152 editor.getBody().innerHTML = '<h1>a</h1><p>b<span style="color: #010203">c</span></p>';153 LegacyUnit.setSelection(editor, 'h1', 1);154 editor.execCommand('ForwardDelete');155 LegacyUnit.equal(editor.getContent(), '<h1>ab<span style="color: #010203;">c</span></h1>');156 LegacyUnit.equal(editor.selection.getStart().nodeName, 'H1');157 });158 suite.test('Backspace key from beginning of P into H1', function (editor) {159 editor.getBody().innerHTML = '<h1>a</h1><p>b</p>';160 LegacyUnit.setSelection(editor, 'p', 0);161 editor.fire("keydown", { keyCode: 8, shiftKey: false, ctrlKey: false, altKey: false, metaKey: false });162 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<h1>ab</h1>');163 LegacyUnit.equal(editor.selection.getNode().nodeName, 'H1');164 });165 suite.test('Delete key from end of H1 into P', function (editor) {166 editor.getBody().innerHTML = '<h1>a</h1><p>b</p>';167 LegacyUnit.setSelection(editor, 'h1', 1);168 editor.fire("keydown", { keyCode: 46, shiftKey: false, ctrlKey: false, altKey: false, metaKey: false });169 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<h1>ab</h1>');170 LegacyUnit.equal(editor.selection.getStart().nodeName, 'H1');171 });172/*173 // These used to be supported in the Quirks branch however not sure if174 // we need to deal with this very uncommon operations. If we do we need175 // to re-introduce them in the new Backspace/Delete logic176 suite.test('Backspace previous word', function (editor) {177 editor.getBody().innerHTML = '<p>abc 123</p>';178 LegacyUnit.setSelection(editor, 'p', 7);179 editor.fire("keydown", { keyCode: 8, ctrlKey: true });180 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p>abc&nbsp;</p>');181 LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');182 });183 suite.test('Backspace previous line', function (editor) {184 editor.getBody().innerHTML = '<p>abc 123</p>';185 LegacyUnit.setSelection(editor, 'p', 7);186 editor.fire("keydown", { keyCode: 8, metaKey: true });187 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p><br></p>');188 LegacyUnit.equal(editor.selection.getStart().nodeName, 'BR');189 });190 suite.test('Delete next word', function (editor) {191 editor.getBody().innerHTML = '<p>abc 123</p>';192 LegacyUnit.setSelection(editor, 'p', 0);193 editor.fire("keydown", { keyCode: 46, ctrlKey: true });194 // Remove nbsp since very old WebKit has an slight issue195 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML).replace('&nbsp;', ''), '<p>123</p>');196 LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');197 });198 suite.test('Delete next line', function (editor) {199 editor.getBody().innerHTML = '<p>abc 123</p>';200 LegacyUnit.setSelection(editor, 'p', 0);201 editor.fire("keydown", { keyCode: 46, metaKey: true });202 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p><br></p>');203 LegacyUnit.equal(editor.selection.getStart().nodeName, 'BR');204 });205 suite.test('Type over bold text in fully selected block and keep bold', function (editor) {206 editor.getBody().innerHTML = '<p><i><b>x</b></i></p><p>y</p>';207 LegacyUnit.setSelection(editor, 'b', 0, 'b', 1);208 editor.fire("keypress", { keyCode: 65, charCode: 65 });209 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p><i><b>a</b></i></p><p>y</p>');210 LegacyUnit.equal(editor.selection.getStart().nodeName, 'B');211 });212 suite.test('Type over partial bold text and keep bold', function (editor) {213 editor.getBody().innerHTML = '<p><b>xy</b></p>';214 LegacyUnit.setSelection(editor, 'b', 0, 'b', 1);215 editor.fire("keypress", { keyCode: 65, charCode: 65 });216 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p><b>ay</b></p>');217 LegacyUnit.equal(editor.selection.getStart().nodeName, 'B');218 });219 suite.test('Type over bold text wrapped inside other formats', function (editor) {220 editor.getBody().innerHTML = '<p><i>1<b>2</b>3</i></p>';221 LegacyUnit.setSelection(editor, 'b', 0, 'b', 1);222 editor.fire("keypress", { keyCode: 65, charCode: 65 });223 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p><i>1<b>a</b>3</i></p>');224 LegacyUnit.equal(editor.selection.getStart().nodeName, 'B');225 });226 suite.test('Delete last character in formats', function (editor) {227 editor.getBody().innerHTML = '<p><b><i>b</i></b></p>';228 LegacyUnit.setSelection(editor, 'i', 1);229 editor.fire("keydown", { keyCode: 8 });230 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p><b><i><br></i></b></p>');231 LegacyUnit.equal(editor.selection.getStart(true).nodeName, 'I');232 });233 suite.test('ForwardDelete last character in formats', function (editor) {234 editor.getBody().innerHTML = '<p><b><i>b</i></b></p>';235 LegacyUnit.setSelection(editor, 'i', 0);236 editor.fire("keydown", { keyCode: 46 });237 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p><b><i><br></i></b></p>');238 LegacyUnit.equal(editor.selection.getStart(true).nodeName, 'I');239 });240 suite.test('Delete in empty in formats text block', function (editor) {241 var rng;242 editor.getBody().innerHTML = '<p>a</p><p><b><i><br></i></b></p><p><b><i><br></i></b></p>';243 rng = editor.dom.createRng();244 rng.setStartBefore(editor.$('br:last')[0]);245 rng.setEndBefore(editor.$('br:last')[0]);246 editor.selection.setRng(rng);247 editor.fire("keydown", { keyCode: 8 });248 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p>a</p><p><b><i><br></i></b></p>');249 LegacyUnit.equal(editor.selection.getStart(true).nodeName, 'I');250 });251 suite.test('ForwardDelete in empty formats text block', function (editor) {252 var rng;253 editor.getBody().innerHTML = '<p>a</p><p><b><i><br></i></b></p><p><b><i><br></i></b></p>';254 rng = editor.dom.createRng();255 rng.setStartBefore(editor.$('br:first')[0]);256 rng.setEndBefore(editor.$('br:first')[0]);257 editor.selection.setRng(rng);258 editor.fire("keydown", { keyCode: 46 });259 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p>a</p><p><b><i><br></i></b></p>');260 LegacyUnit.equal(editor.selection.getStart(true).nodeName, 'I');261 });262 suite.test('Type over all contents', function (editor) {263 editor.getBody().innerHTML = '<p>abc</p>';264 LegacyUnit.setSelection(editor, 'p', 0, 'p', 3);265 editor.fire('keypress', { charCode: 97 });266 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p>a</p>');267 LegacyUnit.equal(editor.selection.getRng().startContainer.data, 'a');268 LegacyUnit.equal(editor.selection.getRng().startOffset, 1);269 });270*/271 suite.test('ForwardDelete all contents', function (editor) {272 editor.getBody().innerHTML = '<p>abc</p>';273 LegacyUnit.setSelection(editor, 'p', 0, 'p', 3);274 editor.fire('keydown', { keyCode: 46 });275 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p><br data-mce-bogus="1"></p>');276 LegacyUnit.equal(editor.selection.getStart(true).nodeName, 'P');277 });278 suite.test('Delete all contents', function (editor) {279 editor.getBody().innerHTML = '<p>abc</p>';280 LegacyUnit.setSelection(editor, 'p', 0, 'p', 3);281 editor.fire('keydown', { keyCode: 8 });282 LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '<p><br data-mce-bogus="1"></p>');283 LegacyUnit.equal(editor.selection.getStart(true).nodeName, 'P');284 });285 TinyLoader.setup(function (editor, onSuccess, onFailure) {286 var steps = Env.webkit ? suite.toSteps(editor) : [];287 Pipeline.async({}, steps, onSuccess, onFailure);288 }, {289 add_unload_trigger: false,290 indent: false,291 disable_nodechange: true,292 skin_url: '/project/src/skins/lightgray/dist/lightgray'293 }, success, failure);294 }...

Full Screen

Full Screen

Quirks_webkit.js

Source:Quirks_webkit.js Github

copy

Full Screen

...16 }17});18if (tinymce.isWebKit) {19 test('Delete from beginning of P into H1', function() {20 editor.getBody().innerHTML = '<h1>a</h1><p>b</p>';21 Utils.setSelection('p', 0);22 editor.execCommand('Delete');23 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<h1>ab</h1>');24 equal(editor.selection.getStart().nodeName, 'H1');25 });26/*27 test('Delete whole H1 before P', function() {28 editor.getBody().innerHTML = '<h1>a</h1><p>b</p>';29 var rng = editor.selection.getRng();30 rng.setStartBefore(editor.getBody().firstChild);31 rng.setEndAfter(editor.getBody().firstChild);32 editor.selection.setRng(rng);33 editor.execCommand('Delete');34 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<h1>b<br></h1>');35 equal(editor.selection.getStart().nodeName, 'H1');36 });37 test('ForwardDelete whole H1 before P', function() {38 editor.getBody().innerHTML = '<h1>a</h1><p>b</p>';39 var rng = editor.selection.getRng();40 rng.setStartBefore(editor.getBody().firstChild);41 rng.setEndAfter(editor.getBody().firstChild);42 editor.selection.setRng(rng);43 editor.execCommand('ForwardDelete');44 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<h1>b<br></h1>');45 equal(editor.selection.getStart().nodeName, 'H1');46 });47*/48 test('Delete between empty paragraphs', function() {49 editor.getBody().innerHTML = '<p>a</p><p><br></p><p><br></p><p>b</p>';50 Utils.setSelection('p:last', 0);51 editor.execCommand('Delete');52 equal(Utils.normalizeHtml(Utils.cleanHtml(editor.getBody().innerHTML)), '<p>a</p><p><br /></p><p>b<br /></p>');53 equal(editor.selection.getStart().nodeName, 'P');54 });55 test('Delete range from middle of H1 to middle of span in P', function() {56 editor.getBody().innerHTML = '<h1>ab</h1><p>b<span style="color:red">cd</span></p>';57 Utils.setSelection('h1', 1, 'span', 1);58 editor.execCommand('Delete');59 equal(Utils.normalizeHtml(Utils.cleanHtml(editor.getBody().innerHTML)), '<h1>a<span style="color: red;">d</span></h1>');60 equal(editor.selection.getStart().nodeName, 'H1');61 });62 test('Delete from beginning of P with style span inside into H1 with inline block', function() {63 editor.getBody().innerHTML = '<h1>a<input type="text"></h1><p>b<span style="color:red">c</span></p>';64 Utils.setSelection('p', 0);65 editor.execCommand('Delete');66 equal(editor.getContent(), '<h1>a<input type="text" />b<span style="color: red;">c</span></h1>');67 equal(editor.selection.getStart().nodeName, 'H1');68 });69 test('Delete from beginning of P with style span inside into H1', function() {70 editor.getBody().innerHTML = '<h1>a</h1><p>b<span style="color:red">c</span></p>';71 Utils.setSelection('p', 0);72 editor.execCommand('Delete');73 equal(editor.getContent(), '<h1>ab<span style="color: red;">c</span></h1>');74 equal(editor.selection.getStart().nodeName, 'H1');75 });76 test('Delete from beginning of P into H1 with contentEditable:false', function() {77 editor.getBody().innerHTML = '<h1 contentEditable="false">a</h1><p>b<span style="color:red">c</span></p>';78 Utils.setSelection('p', 0);79 editor.execCommand('Delete');80 equal(editor.getContent(), '<h1 contenteditable="false">a</h1><p>b<span style="color: red;">c</span></p>');81 equal(editor.selection.getStart().nodeName, 'H1');82 });83 test('Delete from beginning of P with style span inside into H1 with trailing BR', function() {84 editor.getBody().innerHTML = '<h1>a<br></h1><p>b<span style="color:red">c</span></p>';85 Utils.setSelection('p', 0);86 editor.execCommand('Delete');87 equal(editor.getContent(), '<h1>ab<span style="color: red;">c</span></h1>');88 equal(editor.selection.getStart().nodeName, 'H1');89 });90 test('Delete from empty P with style span inside into H1', function() {91 editor.getBody().innerHTML = '<h1>a<br></h1><p><span style="color:red"><br></span></p>';92 Utils.setSelection('span', 0);93 editor.execCommand('Delete');94 equal(editor.getContent(), '<h1>a</h1>');95 equal(editor.selection.getStart().nodeName, 'H1');96 });97 test('Delete from beginning of P with span style to H1', function() {98 editor.getBody().innerHTML = '<h1>a</h1><p><span style="color:red">b</span></p>';99 Utils.setSelection('span', 0);100 editor.execCommand('Delete');101 equal(editor.getContent(), '<h1>a<span style="color: red;">b</span></h1>');102 equal(editor.selection.getStart().nodeName, 'H1');103 });104 test('Delete from beginning of P with BR line to H1', function() {105 editor.getBody().innerHTML = '<h1>a</h1><p>b<br>c</p>';106 Utils.setSelection('p', 0);107 editor.execCommand('Delete');108 equal(Utils.normalizeHtml(Utils.cleanHtml(editor.getBody().innerHTML)), '<h1>ab<br />c</h1>');109 equal(editor.selection.getStart().nodeName, 'H1');110 });111 test('ForwardDelete from end of H1 to P with style span', function() {112 editor.getBody().innerHTML = '<h1>a</h1><p><span style="color:red">b</span></p>';113 Utils.setSelection('h1', 1);114 editor.execCommand('ForwardDelete');115 equal(editor.getContent(), '<h1>a<span style="color: red;">b</span></h1>');116 equal(editor.selection.getStart().nodeName, 'H1');117 });118 test('ForwardDelete from end of H1 with trailing BR to P with style span', function() {119 editor.getBody().innerHTML = '<h1>a<br></h1><p><span style="color:red">b</span></p>';120 Utils.setSelection('h1', 1);121 editor.execCommand('ForwardDelete');122 equal(editor.getContent(), '<h1>a<span style="color: red;">b</span></h1>');123 equal(editor.selection.getStart().nodeName, 'H1');124 });125 test('ForwardDelete from end of H1 with two trailing BR:s to P with style span', function() {126 editor.getBody().innerHTML = '<h1>a<br><br></h1><p><span style="color:red">b</span></p>';127 Utils.setSelection('h1', 1);128 editor.execCommand('ForwardDelete');129 equal(editor.getContent(), '<h1>a</h1><p><span style="color: red;">b</span></p>');130 equal(editor.selection.getStart().nodeName, 'H1');131 });132 test('ForwardDelete from end of H1 to P with style and inline block element', function() {133 editor.getBody().innerHTML = '<h1>a</h1><p><input type="text"><span style="color:red">b</span></p>';134 Utils.setSelection('h1', 1);135 editor.execCommand('ForwardDelete');136 equal(editor.getContent(), '<h1>a<input type="text" /><span style="color: red;">b</span></h1>');137 equal(editor.selection.getStart().nodeName, 'H1');138 });139 test('ForwardDelete from end of H1 with BR line to P', function() {140 editor.getBody().innerHTML = '<h1>a<br>b</h1><p>c</p>';141 var rng = editor.selection.getRng();142 rng.setStart(editor.$('h1')[0].lastChild, 1);143 rng.setEnd(editor.$('h1')[0].lastChild, 1);144 editor.selection.setRng(rng);145 editor.execCommand('ForwardDelete');146 equal(Utils.normalizeHtml(Utils.cleanHtml(editor.getBody().innerHTML)), '<h1>a<br />bc</h1>');147 equal(editor.selection.getStart().nodeName, 'H1');148 });149 test('ForwardDelete from end of H1 into P', function() {150 editor.getBody().innerHTML = '<h1>a</h1><p>b</p>';151 Utils.setSelection('h1', 1);152 editor.execCommand('ForwardDelete');153 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<h1>ab</h1>');154 equal(editor.selection.getStart().nodeName, 'H1');155 });156 test('ForwardDelete from end of H1 into P with contentEditable:false', function() {157 editor.getBody().innerHTML = '<h1>a</h1><p contentEditable="false">b</p>';158 Utils.setSelection('h1', 1);159 editor.execCommand('ForwardDelete');160 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<h1>a</h1><p contenteditable="false">b</p>');161 equal(editor.selection.getStart().nodeName, 'H1');162 });163 test('ForwardDelete from end of H1 into P with style span inside', function() {164 editor.getBody().innerHTML = '<h1>a</h1><p>b<span style="color: #010203">c</span></p>';165 Utils.setSelection('h1', 1);166 editor.execCommand('ForwardDelete');167 equal(editor.getContent(), '<h1>ab<span style="color: #010203;">c</span></h1>');168 equal(editor.selection.getStart().nodeName, 'H1');169 });170 test('Backspace key from beginning of P into H1', function() {171 editor.getBody().innerHTML = '<h1>a</h1><p>b</p>';172 Utils.setSelection('p', 0);173 editor.fire("keydown", {keyCode: 8});174 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<h1>ab</h1>');175 equal(editor.selection.getStart().nodeName, 'H1');176 });177 test('Delete key from end of H1 into P', function() {178 editor.getBody().innerHTML = '<h1>a</h1><p>b</p>';179 Utils.setSelection('h1', 1);180 editor.fire("keydown", {keyCode: 46});181 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<h1>ab</h1>');182 equal(editor.selection.getStart().nodeName, 'H1');183 });184 test('Backspace previous word', function() {185 editor.getBody().innerHTML = '<p>abc 123</p>';186 Utils.setSelection('p', 7);187 editor.fire("keydown", {keyCode: 8, ctrlKey: true});188 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<p>abc&nbsp;</p>');189 equal(editor.selection.getStart().nodeName, 'P');190 });191 test('Backspace previous line', function() {192 editor.getBody().innerHTML = '<p>abc 123</p>';193 Utils.setSelection('p', 7);194 editor.fire("keydown", {keyCode: 8, metaKey: true});195 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<p><br></p>');196 equal(editor.selection.getStart().nodeName, 'BR');197 });198 test('Delete next word', function() {199 editor.getBody().innerHTML = '<p>abc 123</p>';200 Utils.setSelection('p', 0);201 editor.fire("keydown", {keyCode: 46, ctrlKey: true});202 // Remove nbsp since very old WebKit has an slight issue203 equal(Utils.cleanHtml(editor.getBody().innerHTML).replace('&nbsp;', ''), '<p>123</p>');204 equal(editor.selection.getStart().nodeName, 'P');205 });206 test('Delete next line', function() {207 editor.getBody().innerHTML = '<p>abc 123</p>';208 Utils.setSelection('p', 0);209 editor.fire("keydown", {keyCode: 46, metaKey: true});210 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<p><br></p>');211 equal(editor.selection.getStart().nodeName, 'BR');212 });213 test('Type over bold text in fully selected block and keep bold', function() {214 editor.getBody().innerHTML = '<p><i><b>x</b></i></p>';215 Utils.setSelection('b', 0, 'b', 1);216 editor.fire("keypress", {keyCode: 65, charCode: 65});217 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<p><i><b>a</b></i></p>');218 equal(editor.selection.getStart().nodeName, 'B');219 });220 test('Type over partial bold text and keep bold', function() {221 editor.getBody().innerHTML = '<p><b>xy</b></p>';222 Utils.setSelection('b', 0, 'b', 1);223 editor.fire("keypress", {keyCode: 65, charCode: 65});224 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<p><b>ay</b></p>');225 equal(editor.selection.getStart().nodeName, 'B');226 });227 test('Type over bold text wrapped inside other formats', function() {228 editor.getBody().innerHTML = '<p><i>1<b>2</b>3</i></p>';229 Utils.setSelection('b', 0, 'b', 1);230 editor.fire("keypress", {keyCode: 65, charCode: 65});231 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<p><i>1<b>a</b>3</i></p>');232 equal(editor.selection.getStart().nodeName, 'B');233 });234 test('Delete last character in formats', function() {235 editor.getBody().innerHTML = '<p><b><i>b</i></b></p>';236 Utils.setSelection('i', 1);237 editor.fire("keydown", {keyCode: 8});238 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<p><b><i><br></i></b></p>');239 equal(editor.selection.getStart(true).nodeName, 'I');240 });241 test('ForwardDelete last character in formats', function() {242 editor.getBody().innerHTML = '<p><b><i>b</i></b></p>';243 Utils.setSelection('i', 0);244 editor.fire("keydown", {keyCode: 46});245 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<p><b><i><br></i></b></p>');246 equal(editor.selection.getStart(true).nodeName, 'I');247 });248 test('Delete in empty in formats text block', function() {249 var rng;250 editor.getBody().innerHTML = '<p>a</p><p><b><i><br></i></b></p><p><b><i><br></i></b></p>';251 rng = editor.dom.createRng();252 rng.setStartBefore(editor.$('br:last')[0]);253 rng.setEndBefore(editor.$('br:last')[0]);254 editor.selection.setRng(rng);255 editor.fire("keydown", {keyCode: 8});256 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<p>a</p><p><b><i><br></i></b></p>');257 equal(editor.selection.getStart(true).nodeName, 'I');258 });259 test('ForwardDelete in empty formats text block', function() {260 var rng;261 editor.getBody().innerHTML = '<p>a</p><p><b><i><br></i></b></p><p><b><i><br></i></b></p>';262 rng = editor.dom.createRng();263 rng.setStartBefore(editor.$('br:first')[0]);264 rng.setEndBefore(editor.$('br:first')[0]);265 editor.selection.setRng(rng);266 editor.fire("keydown", {keyCode: 46});267 equal(Utils.cleanHtml(editor.getBody().innerHTML), '<p>a</p><p><b><i><br></i></b></p>');268 equal(editor.selection.getStart(true).nodeName, 'I');269 });270} else {271 test("Skipped since the browser isn't WebKit", function() {272 ok(true, "Skipped");273 });...

Full Screen

Full Screen

profile.service.js

Source:profile.service.js Github

copy

Full Screen

1import { post, getBody } from './http';2const url = '/rest/customer';3// getHobbyList4export function getHobbyList(params) {5 return post(url+'/getHobbyList', getBody(params));6}7export function getJobList(params) {8 return post(url+'/getJobList', getBody(params));9}10// getCustomer11export function getCustomer(params) {12 return post(url+'/getCustomer', getBody(params)).then(13 res => {14 return Object.assign({},res.data, {status: res.status});15 }16 );17}18// updateUserAvatar19export function updateUserAvatar(params) {20 return post(url+'/updateUserAvatar', getBody(params));21}22export function updateGender(params) {23 return post(url+'/updateGender', getBody(params));24}25export function updateNickname(params) {26 return post(url+'/updateNickName', getBody(params));27}28// updateBirthday29export function updateBirthday(params) {30 return post(url+'/updateBirthday', getBody(params));31}32// updateHobby33export function updateHobby(params) {34 return post(url+'/updateHobby', getBody(params));35}36// updateJob37export function updateJob(params) {38 return post(url+'/updateJob', getBody(params));39}40// updateIdentify41export function updateIdentify(params) {42 return post(url+'/updateIdentify', getBody(params));43}44// updateHomeAddress45export function updateHomeAddress(params) {46 return post(url+'/updateHomeAddress', getBody(params));47}48// addBankCardCheck49export function addBankCardCheck(params={}) {50 return post('/rest/customerAccount'+'/addBankCardCheck', getBody(params));51}52// findCashDepositSum53export function findCashDepositSum(params={}) {54 return post('/rest/customerAccount'+'/findCashDepositSum', getBody(params));55}56// 实名认证 获取信息57export function findOneCustomerInfo(params={}) {58 return post('/rest/customerInfo/findOneCustomerInfo', getBody(params));59}60// 实名认证 证件类型61export function getCardTypeList(params={}) {62 return post('/rest/customerInfo/getCardTypeList', getBody(params));63}64// 实名认证65export function createCustomerInfo(params={}) {66 if(params.confirmStatus ===3 ||params.confirmStatus ===2){67 return post('/rest/customerInfo/updateCustomerInfo', getBody(params));68 } else {69 return post('/rest/customerInfo/createCustomerInfo', getBody(params));70 }71}72// 获取个人订单 数量73export function getOrderCount(params={}) {74 return post('/rest/order/getOrderCount', getBody(params));75}76// 获取 冻结金额详情77export function getForzenAccount (params={}) {78 return post('/rest/customerAccount/getForzenAccount', getBody(params));79}80// 退出登录 loginOut81export function loginOut (params={}) {82 return post(url+'/loginOut', getBody(params));83}84// 今日订单量85export function findCountByCustomer (params={}) {86 return post('/rest/order/findCountByCustomer', getBody(params));87}88// 今日销售额 findAmountByCustomer89export function findAmountByCustomer (params={}) {90 return post('/rest/order/findAmountByCustomer', getBody(params));91}92//获取会员93export function findCustomerRank (params={}) {94 return post('/rest/customer/findCustomerRank', getBody(params));...

Full Screen

Full Screen

pay.service.js

Source:pay.service.js Github

copy

Full Screen

2const url = '/rest/customerAccount';3const url2 = '/rest/order';4// 获得余额5export function getAccount(params = {}) {6 return post(url + '/getAccount', getBody(params));7}8// 本地货币支付9export function payByLocalCurrency(params) {10 return post(url2 + '/payByLocalCurrency', getBody(params));11}12// 获取 积分13export function getIntegral(params) {14 return post( '/rest/customerAccount/getIntegral', getBody(params));15}16// 微信支付 获得验签17export function getPaySignature(params) {18 return post('/rest/orderPay/getPaySignature', getBody(params));19}20//第三方充值U币21export function getUPaySignature(params) {22 return post('/rest/orderPay/getUPaySignature', getBody(params));23}24// 通过小金库充值u币 depositByCoffers25export function depositByCoffers(params) {26 return post(url+'/depositByCoffers', getBody(params));27}28//获取支付金额29export function getCustomerAmountByOrderId(params) {30 return post(url2+'/getCustomerAmountByPayId', getBody(params));31}32// 确认代付信息33export function getPayInfo(params) {34 return post(url2+'/getPayInfo', getBody(params));35}36// 代付的人 获取代付信息37export function getPayInfo2(params) {38 return post('/anotherPay/getPayInfo', getBody(params));39}40// 代付的人 代付交易41export function getAnotherPaySignature(params) {42 return post('/orderAnotherPay/getAnotherPaySignature', getBody(params));43}44//获取今日收益45export function getfindTodayEarnings(params) {46 return post('/rest/customer/findTodayEarnings', getBody(params));47}48//获取本月收益49export function getMonthlyIncome(params) {50 return post('/rest/customer/findMonthEarnings',getBody(params));51}52//获取 e卡 可抵扣额度53export function getSkuEcardAmount(params) {54 return post('/product/getSkuEcardAmount',getBody(params));55}56//获取提现费率57export function getWithdrawalServiceRate(params) {58 return post(url+'/getWithdrawalServiceRate',getBody(params));...

Full Screen

Full Screen

newProfile.js

Source:newProfile.js Github

copy

Full Screen

1import { post, getBody } from '../http';2const url = '/rest/stat';3// 我的 页面 获取 数据4export function newProfileData(params={}) {5 return post(url + '/getIndexSales', getBody(params));6}7// 获得指标8export function findTeamSales(params={}) {9 return post('/rest/customerTeam/findTeamSales', getBody(params));10}11// 获取 省了多少钱 getSaveMoney12export function getSaveMoney(params={}) {13 return post('/rest/order/getSaveMoney', getBody(params));14}15// 收益 页面 获取 统计16export function getTotal(params={}) {17 return post(url + '/getSumAmount', getBody(params));18}19// 月结收益20export function getMonthEarnings(params={}) {21 return post(url + '/getMonthEarnings', getBody(params));22}23// 后面24export function getMonthEarningsSummary(params={}) {25 return post(url + '/getMonthEarningsSummary', getBody(params));26}27// 收益 订单 数据 getEarningsOrderList28export function getEarningsOrderList(params={}) {29 return post(url + '/getEarningsOrderList', getBody(params));30}31// 销售额 数据32export function orderOutingFindPage(params={}) {33 return post('/rest/order/outingFindPage', getBody(params));34}35// 期权36export function findShareoPtion(params={}) {37 return post(url + '/findShareoPtion', getBody(params));38}39// 我的成长 团队分部40export function findTeamNumberByRank(params={}) {41 return post(url + '/findTeamNumberByRank', getBody(params));42}43//获取今日业绩44export function getTodayPerformance(params={}) {45 return post('/rest/stat/getTodayPerformance', getBody(params));46}47//获取月业绩48export function getMonthPerformance(params={}) {49 return post('/rest/stat/getMonthPerformance', getBody(params));50}51// 待发放 getSumDelayAmount52export function getSumDelayAmount(params={}) {53 return post(url + '/getSumDelayAmount', getBody(params));54}55// 晋升差额56export function getUpgradeProgress(params={}) {57 return post('/rest/customer/getUpgradeProgress',getBody(params));...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getBody } = require('cypress-xpath')2describe('My First Test', function() {3 it('Does not do much!', function() {4 cy.contains('type').click()5 getBody('input').type('Hello World')6 })7})

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.Commands.add('getBody', () => {2 return cy.get('body');3});4Cypress.Commands.add('getBody', () => {5 return cy.get('body');6});7Cypress.Commands.add('getBody', () => {8 return cy.get('body');9});10Cypress.Commands.add('getBody', () => {11 return cy.get('body');12});13Cypress.Commands.add('getBody', () => {14 return cy.get('body');15});16Cypress.Commands.add('getBody', () => {17 return cy.get('body');18});19Cypress.Commands.add('getBody', () => {20 return cy.get('body');21});22Cypress.Commands.add('getBody', () => {23 return cy.get('body');24});25Cypress.Commands.add('getBody', () => {26 return cy.get('body');27});28Cypress.Commands.add('getBody', () => {29 return cy.get('body');30});31Cypress.Commands.add('getBody', () => {32 return cy.get('body');33});34Cypress.Commands.add('getBody', () => {35 return cy.get('body');36});37Cypress.Commands.add('getBody', () => {38 return cy.get('body');39});

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2describe('My First Test', function() {3 it('Gets, types and asserts', function() {4 cy.contains('type').click()5 cy.url().should('include', '/commands/actions')6 cy.get('.action-email')7 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test API', function() {2 it('Test API', function() {3 .its('body')4 .then((body) => {5 expect(body).to.have.property('userId', 1)6 })7 })8})9{10}11describe('Test API', function() {12 it('Test API', function() {13 cy.request('/todos/1')14 .its('body')15 .then((body) => {16 expect(body).to.have.property('userId', 1)17 })18 })19})20describe('Test API', function() {21 it('Test API', function() {22 cy.request('/todos/1')23 .should((response) => {24 expect(response.status).to.eq(200)25 expect(response.body).to.have.property('userId', 1)26 })27 })28})29describe('Test API', function() {30 it('Test API', function() {31 cy.request('/todos/1')32 .should((response) => {33 expect(response.status).to.eq(200)34 expect(response.body).to.have.property('userId', 1)35 expect(response.body).to.have.property('id', 1)36 expect(response.body).to.have.property('title', 'delectus aut autem')37 expect(response.body).to.have.property('completed', false)38 })39 })40})41describe('Test API', function() {42 it('Test API', function() {43 cy.request('/todos/1')44 .should((response) => {45 expect(response.status).to.eq(200)46 expect(response.body).to.have.property('userId', 1)47 expect(response.body

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful