Example #1
0
  suite.test('isAtStart/isAtEnd/isTextPosition', function () {
    setupHtml('<b>abc</b><p><input></p>');

    LegacyUnit.equal(CaretPosition.isAtStart(CaretPosition(getRoot().firstChild.firstChild, 0)), true);
    LegacyUnit.equal(CaretPosition.isAtStart(CaretPosition(getRoot().firstChild.firstChild, 1)), false);
    LegacyUnit.equal(CaretPosition.isAtStart(CaretPosition(getRoot().firstChild.firstChild, 3)), false);
    LegacyUnit.equal(CaretPosition.isAtStart(CaretPosition(getRoot().lastChild, 0)), true);
    LegacyUnit.equal(CaretPosition.isAtStart(CaretPosition(getRoot().lastChild, 1)), false);
    LegacyUnit.equal(CaretPosition.isAtEnd(CaretPosition(getRoot().firstChild.firstChild, 3)), true);
    LegacyUnit.equal(CaretPosition.isAtEnd(CaretPosition(getRoot().firstChild.firstChild, 1)), false);
    LegacyUnit.equal(CaretPosition.isAtEnd(CaretPosition(getRoot().firstChild.firstChild, 0)), false);
    LegacyUnit.equal(CaretPosition.isAtEnd(CaretPosition(getRoot().lastChild, 1)), true);
    LegacyUnit.equal(CaretPosition.isAtEnd(CaretPosition(getRoot().lastChild, 0)), false);
    LegacyUnit.equal(CaretPosition.isTextPosition(CaretPosition(getRoot().firstChild.firstChild, 0)), true);
    LegacyUnit.equal(CaretPosition.isTextPosition(CaretPosition(getRoot().lastChild, 0)), false);
  });
Example #2
0
 suite.test('startsWithCaretContainer', function () {
   setupHtml(Zwsp.ZWSP + 'abc');
   LegacyUnit.equal(CaretContainer.startsWithCaretContainer(getRoot().firstChild), true);
 });
Example #3
0
UnitTest.asynctest('browser.tinymce.core.CaretContainerTest', function () {
  const success = arguments[arguments.length - 2];
  const failure = arguments[arguments.length - 1];
  const suite = LegacyUnit.createSuite();
  const viewBlock = ViewBlock();

  if (!Env.ceFalse) {
    return;
  }

  const getRoot = function () {
    return viewBlock.get();
  };

  const setupHtml = function (html) {
    viewBlock.update(html);
  };

  suite.test('isCaretContainer', function () {
    LegacyUnit.equal(CaretContainer.isCaretContainer(document.createTextNode('text')), false);
    LegacyUnit.equal(CaretContainer.isCaretContainer(DomQuery('<span></span>')[0]), false);
    LegacyUnit.equal(CaretContainer.isCaretContainer(DomQuery('<span data-mce-caret="1"></span>')[0]), true);
    LegacyUnit.equal(CaretContainer.isCaretContainer(DomQuery('<span data-mce-caret="1">x</span>')[0].firstChild), true);
    LegacyUnit.equal(CaretContainer.isCaretContainer(document.createTextNode(Zwsp.ZWSP)), true);
  });

  suite.test('isCaretContainerBlock', function () {
    LegacyUnit.equal(CaretContainer.isCaretContainerBlock(document.createTextNode('text')), false);
    LegacyUnit.equal(CaretContainer.isCaretContainerBlock(DomQuery('<span></span>')[0]), false);
    LegacyUnit.equal(CaretContainer.isCaretContainerBlock(DomQuery('<span data-mce-caret="1"></span>')[0]), true);
    LegacyUnit.equal(CaretContainer.isCaretContainerBlock(DomQuery('<span data-mce-caret="1">a</span>')[0].firstChild), true);
    LegacyUnit.equal(CaretContainer.isCaretContainerBlock(document.createTextNode(Zwsp.ZWSP)), false);
  });

  suite.test('isCaretContainerInline', function () {
    LegacyUnit.equal(CaretContainer.isCaretContainerInline(document.createTextNode('text')), false);
    LegacyUnit.equal(CaretContainer.isCaretContainerInline(DomQuery('<span></span>')[0]), false);
    LegacyUnit.equal(CaretContainer.isCaretContainerInline(DomQuery('<span data-mce-caret="1"></span>')[0]), false);
    LegacyUnit.equal(CaretContainer.isCaretContainerInline(DomQuery('<span data-mce-caret="1">a</span>')[0].firstChild), false);
    LegacyUnit.equal(CaretContainer.isCaretContainerInline(document.createTextNode(Zwsp.ZWSP)), true);
  });

  suite.test('insertInline before element', function () {
    setupHtml('<span contentEditable="false">1</span>');
    LegacyUnit.equalDom(CaretContainer.insertInline(getRoot().firstChild, true), getRoot().firstChild);
    LegacyUnit.equal(CaretContainer.isCaretContainerInline(getRoot().firstChild), true);
  });

  suite.test('insertInline after element', function () {
    setupHtml('<span contentEditable="false">1</span>');
    LegacyUnit.equalDom(CaretContainer.insertInline(getRoot().firstChild, false), getRoot().lastChild);
    LegacyUnit.equal(CaretContainer.isCaretContainerInline(getRoot().lastChild), true);
  });

  suite.test('insertInline between elements', function () {
    setupHtml('<span contentEditable="false">1</span><span contentEditable="false">1</span>');
    LegacyUnit.equalDom(CaretContainer.insertBlock('p', getRoot().lastChild, true), getRoot().childNodes[1]);
    LegacyUnit.equal(CaretContainer.isCaretContainerBlock(getRoot().childNodes[1]), true);
  });

  suite.test('insertInline before element with ZWSP', function () {
    setupHtml('abc' + Zwsp.ZWSP + '<span contentEditable="false">1</span>');
    LegacyUnit.equalDom(CaretContainer.insertInline(getRoot().lastChild, true), getRoot().childNodes[1]);
    LegacyUnit.equal(CaretContainer.isCaretContainerInline(getRoot().firstChild), false);
    LegacyUnit.equal(CaretContainer.isCaretContainerInline(getRoot().childNodes[1]), true);
  });

  suite.test('insertInline after element with ZWSP', function () {
    setupHtml('<span contentEditable="false">1</span>' + Zwsp.ZWSP + 'abc');
    LegacyUnit.equalDom(CaretContainer.insertInline(getRoot().firstChild, false), getRoot().childNodes[1]);
    LegacyUnit.equal(CaretContainer.isCaretContainerInline(getRoot().lastChild), false);
    LegacyUnit.equal(CaretContainer.isCaretContainerInline(getRoot().childNodes[1]), true);
  });

  suite.test('insertBlock before element', function () {
    setupHtml('<span contentEditable="false">1</span>');
    LegacyUnit.equalDom(CaretContainer.insertBlock('p', getRoot().firstChild, true), getRoot().firstChild);
    LegacyUnit.equal(CaretContainer.isCaretContainerBlock(getRoot().firstChild), true);
  });

  suite.test('insertBlock after element', function () {
    setupHtml('<span contentEditable="false">1</span>');
    LegacyUnit.equalDom(CaretContainer.insertBlock('p', getRoot().firstChild, false), getRoot().lastChild);
    LegacyUnit.equal(CaretContainer.isCaretContainerBlock(getRoot().lastChild), true);
  });

  suite.test('insertBlock between elements', function () {
    setupHtml('<span contentEditable="false">1</span><span contentEditable="false">1</span>');
    LegacyUnit.equalDom(CaretContainer.insertInline(getRoot().lastChild, true), getRoot().childNodes[1]);
    LegacyUnit.equal(CaretContainer.isCaretContainerInline(getRoot().childNodes[1]), true);
  });

  suite.test('startsWithCaretContainer', function () {
    setupHtml(Zwsp.ZWSP + 'abc');
    LegacyUnit.equal(CaretContainer.startsWithCaretContainer(getRoot().firstChild), true);
  });

  suite.test('endsWithCaretContainer', function () {
    setupHtml('abc');
    const textNode = viewBlock.get().firstChild as Text;
    textNode.appendData(Zwsp.ZWSP);
    LegacyUnit.equal(CaretContainer.endsWithCaretContainer(getRoot().firstChild), true);
  });

  suite.test('hasContent', function () {
    setupHtml('<span contentEditable="false">1</span>');
    const caretContainerBlock = CaretContainer.insertBlock('p', getRoot().firstChild, true);
    LegacyUnit.equal(CaretContainer.hasContent(caretContainerBlock), false);
    caretContainerBlock.insertBefore(document.createTextNode('a'), caretContainerBlock.firstChild);
    LegacyUnit.equal(CaretContainer.hasContent(caretContainerBlock), true);
  });

  suite.test('showCaretContainerBlock', function () {
    setupHtml('<span contentEditable="false">1</span>');
    const caretContainerBlock = CaretContainer.insertBlock('p', getRoot().firstChild, true) as HTMLElement;
    caretContainerBlock.insertBefore(document.createTextNode('a'), caretContainerBlock.firstChild);
    CaretContainer.showCaretContainerBlock(caretContainerBlock);
    LegacyUnit.equal(caretContainerBlock.outerHTML, '<p>a</p>');
  });

  suite.test('prependInline', function () {
    setupHtml('a');
    const caretContainerTextNode = CaretContainer.prependInline(getRoot().firstChild) as Text;
    LegacyUnit.equal(caretContainerTextNode.data, Zwsp.ZWSP + 'a');
  });

  suite.test('prependInline 2', function () {
    setupHtml('<b>a</b>');
    LegacyUnit.equal(CaretContainer.prependInline(getRoot().firstChild), null);
    LegacyUnit.equal(CaretContainer.prependInline(null), null);
  });

  suite.test('appendInline', function () {
    setupHtml('a');
    const caretContainerTextNode = CaretContainer.appendInline(getRoot().firstChild) as Text;
    LegacyUnit.equal(caretContainerTextNode.data, 'a' + Zwsp.ZWSP);
  });

  suite.test('isBeforeInline', function () {
    setupHtml(Zwsp.ZWSP + 'a');
    LegacyUnit.equal(CaretContainer.isBeforeInline(CaretPosition(getRoot().firstChild, 0)), true);
    LegacyUnit.equal(CaretContainer.isBeforeInline(CaretPosition(getRoot().firstChild, 1)), false);
  });

  suite.test('isAfterInline', function () {
    setupHtml(Zwsp.ZWSP + 'a');
    LegacyUnit.equal(CaretContainer.isAfterInline(CaretPosition(getRoot().firstChild, 1)), true);
    LegacyUnit.equal(CaretContainer.isAfterInline(CaretPosition(getRoot().firstChild, 0)), false);
  });

  viewBlock.attach();
  Pipeline.async({}, suite.toSteps({}), function () {
    viewBlock.detach();
    success();
  }, failure);
});
  suite.test('Formatting commands (xhtmlTextStyles)', function (editor) {
    editor.focus();
    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('Bold');
    LegacyUnit.equal(editor.getContent(), '<p><strong>test 123</strong></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('Italic');
    LegacyUnit.equal(editor.getContent(), '<p><em>test 123</em></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('Underline');
    LegacyUnit.equal(editor.getContent(), '<p><span style="text-decoration: underline;">test 123</span></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('Strikethrough');
    LegacyUnit.equal(editor.getContent(), '<p><span style="text-decoration: line-through;">test 123</span></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('FontName', false, 'Arial');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-family: Arial;">test 123</span></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('FontSize', false, '7');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-size: xx-large;">test 123</span></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('ForeColor', false, '#FF0000');
    LegacyUnit.equal(editor.getContent(), '<p><span style="color: #ff0000;">test 123</span></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('HiliteColor', false, '#FF0000');
    LegacyUnit.equal(editor.getContent(), '<p><span style="background-color: #ff0000;">test 123</span></p>');

    editor.setContent('<p><span style="text-decoration: underline;">test 123</span></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="text-decoration: underline;">test 123</span></p>');

    editor.setContent('<p><span style="text-decoration: line-through;">test 123</span></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="text-decoration: line-through;">test 123</span></p>');

    editor.setContent('<p><span style="font-family: Arial;">test 123</span></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-family: Arial;">test 123</span></p>');

    editor.setContent('<p><span style="font-size: xx-large;">test 123</span></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-size: xx-large;">test 123</span></p>');

    editor.setContent('<p><strike>test 123</strike></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="text-decoration: line-through;">test 123</span></p>');

    editor.setContent('<p><font face="Arial">test 123</font></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-family: Arial;">test 123</span></p>');

    editor.setContent('<p><font size="7">test 123</font></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-size: 300%;">test 123</span></p>');

    editor.setContent('<p><font face="Arial" size="7">test 123</font></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-size: 300%; font-family: Arial;">test 123</span></p>');

    editor.setContent('<font style="background-color: #ff0000" color="#ff0000">test</font><font face="Arial">test</font>');
    LegacyUnit.equal(
      editor.getContent(),
      '<p><span style="color: #ff0000; background-color: #ff0000;">test</span><span style="font-family: Arial;">test</span></p>'
    );

    editor.setContent('<p><font face="Arial" style="color: #ff0000">test 123</font></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="color: #ff0000; font-family: Arial;">test 123</span></p>');
  });
 suite.test('unlink - unselected a[href] with childNodes', function (editor) {
   editor.setContent('<p><a href="test"><strong><em>test</em></strong></a></p>');
   LegacyUnit.setSelection(editor, 'em', 0);
   editor.execCommand('unlink');
   LegacyUnit.equal(editor.getContent(), '<p><strong><em>test</em></strong></p>');
 });
 suite.test('mceInsertLink (link absolute)', function (editor) {
   editor.setContent('<p>test 123</p>');
   editor.execCommand('SelectAll');
   editor.execCommand('mceInsertLink', false, 'http://www.site.com');
   LegacyUnit.equal(editor.getContent(), '<p><a href="http://www.site.com">test 123</a></p>');
 });
 suite.test('mceInsertLink (link with space)', function (editor) {
   editor.setContent('<p>test 123</p>');
   editor.execCommand('SelectAll');
   editor.execCommand('mceInsertLink', false, { href: 'foo bar' });
   LegacyUnit.equal(editor.getContent(), '<p><a href="foo%20bar">test 123</a></p>');
 });
Example #8
0
 suite.test('collapse', function () {
   LegacyUnit.deepEqual(ClientRect.collapse(rect(10, 20, 30, 40), true), rect(10, 20, 0, 40));
   LegacyUnit.deepEqual(ClientRect.collapse(rect(10, 20, 30, 40), false), rect(40, 20, 0, 40));
 });
Example #9
0
 suite.test('isBelow', function () {
   LegacyUnit.equal(ClientRect.isBelow(rect(10, 70, 10, 40), rect(20, 40, 10, 20)), true);
   LegacyUnit.equal(ClientRect.isBelow(rect(10, 40, 10, 20), rect(20, 70, 10, 40)), false);
 });
UnitTest.asynctest('tinymce.lists.browser.RemoveTest', function () {
  const success = arguments[arguments.length - 2];
  const failure = arguments[arguments.length - 1];
  const suite = LegacyUnit.createSuite();

  Plugin();
  Theme();

  suite.test('Remove UL at single LI', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ul>' +
      '<li>a</li>' +
      '</ul>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'li');
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<p>a</p>'
    );
    LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
  });

  suite.test('Remove UL at start LI', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ul>' +
      '<li>a</li>' +
      '<li>b</li>' +
      '<li>c</li>' +
      '</ul>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'li');
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<p>a</p>' +
      '<ul>' +
      '<li>b</li>' +
      '<li>c</li>' +
      '</ul>'
    );
    LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
  });

  suite.test('Remove UL at start empty LI', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ul>' +
      '<li><br></li>' +
      '<li>b</li>' +
      '<li>c</li>' +
      '</ul>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'li');
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<p>\u00a0</p>' +
      '<ul>' +
      '<li>b</li>' +
      '<li>c</li>' +
      '</ul>'
    );
    LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
  });

  suite.test('Remove UL at middle LI', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ul>' +
      '<li>a</li>' +
      '<li>b</li>' +
      '<li>c</li>' +
      '</ul>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'li:nth-child(2)', 1);
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<ul>' +
      '<li>a</li>' +
      '</ul>' +
      '<p>b</p>' +
      '<ul>' +
      '<li>c</li>' +
      '</ul>'
    );
    LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
  });

  suite.test('Remove UL at middle empty LI', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ul>' +
      '<li>a</li>' +
      '<li><br></li>' +
      '<li>c</li>' +
      '</ul>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'li:nth-child(2)', 0);
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<ul>' +
      '<li>a</li>' +
      '</ul>' +
      '<p>\u00a0</p>' +
      '<ul>' +
      '<li>c</li>' +
      '</ul>'
    );
    LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
  });

  suite.test('Remove UL at end LI', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ul>' +
      '<li>a</li>' +
      '<li>b</li>' +
      '<li>c</li>' +
      '</ul>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'li:last', 1);
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<ul>' +
      '<li>a</li>' +
      '<li>b</li>' +
      '</ul>' +
      '<p>c</p>'
    );
    LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
  });

  suite.test('Remove UL at end empty LI', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ul>' +
      '<li>a</li>' +
      '<li>b</li>' +
      '<li><br></li>' +
      '</ul>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'li:last', 0);
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<ul>' +
      '<li>a</li>' +
      '<li>b</li>' +
      '</ul>' +
      '<p>\u00a0</p>'
    );
    LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
  });

  suite.test('Remove UL at middle LI inside parent OL', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ol>' +
      '<li>a</li>' +
      '<ul>' +
      '<li>b</li>' +
      '<li>c</li>' +
      '<li>d</li>' +
      '</ul>' +
      '<li>e</li>' +
      '</ol>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'ul li:nth-child(2)', 1);
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<ol>' +
      '<li>a</li>' +
      '<ul>' +
      '<li>b</li>' +
      '</ul>' +
      '</ol>' +
      '<p>c</p>' +
      '<ol>' +
      '<ul>' +
      '<li>d</li>' +
      '</ul>' +
      '<li>e</li>' +
      '</ol>'
    );
    LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
  });

  suite.test('Remove UL at middle LI inside parent OL (html5)', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ol>' +
      '<li>a' +
      '<ul>' +
      '<li>b</li>' +
      '<li>c</li>' +
      '<li>d</li>' +
      '</ul>' +
      '</li>' +
      '<li>e</li>' +
      '</ol>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'ul li:nth-child(2)', 1);
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<ol>' +
      '<li>a' +
      '<ul>' +
      '<li>b</li>' +
      '</ul>' +
      '</li>' +
      '</ol>' +
      '<p>c</p>' +
      '<ol>' +
      '<li style="list-style-type: none;">' +
      '<ul>' +
      '<li>d</li>' +
      '</ul>' +
      '</li>' +
      '<li>e</li>' +
      '</ol>'
    );
    LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
  });

  suite.test('Remove OL on a deep nested LI', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ol>' +
      '<li>a' +
      '<ol>' +
      '<li>b</li>' +
      '<li>c' +
      '<ol>' +
      '<li>d</li>' +
      '<li>e</li>' +
      '<li>f</li>' +
      '</ol>' +
      '</li>' +
      '<li>g</li>' +
      '<li>h</li>' +
      '</ol>' +
      '</li>' +
      '<li>i</li>' +
      '</ol>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'ol ol ol li:nth-child(2)', 1);
    LegacyUnit.execCommand(editor, 'InsertOrderedList');

    LegacyUnit.equal(editor.getContent(),
      '<ol>' +
      '<li>a' +
      '<ol>' +
      '<li>b</li>' +
      '<li>c' +
      '<ol>' +
      '<li>d</li>' +
      '</ol>' +
      '</li>' +
      '</ol>' +
      '</li>' +
      '</ol>' +
      '<p>e</p>' +
      '<ol>' +
      '<li style="list-style-type: none;">' +
      '<ol>' +
      '<li style="list-style-type: none;">' +
      '<ol>' +
      '<li>f</li>' +
      '</ol>' +
      '</li>' +
      '<li>g</li>' +
      '<li>h</li>' +
      '</ol>' +
      '</li>' +
      '<li>i</li>' +
      '</ol>'
    );

    LegacyUnit.equal(editor.selection.getStart().nodeName, 'P');
  });

  suite.test('Remove UL with single LI in BR mode', function (editor) {
    editor.settings.forced_root_block = false;

    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ul>' +
      '<li>a</li>' +
      '</ul>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'li', 1);
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      'a'
    );
    LegacyUnit.equal(editor.selection.getStart().nodeName, 'BODY');

    editor.settings.forced_root_block = 'p';
  });

  suite.test('Remove UL with multiple LI in BR mode', function (editor) {
    editor.settings.forced_root_block = false;

    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ul>' +
      '<li>a</li>' +
      '<li>b</li>' +
      '</ul>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'li:first', 1, 'li:last', 1);
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      'a<br />' +
      'b'
    );
    LegacyUnit.equal(editor.selection.getStart().nodeName, 'BODY');

    editor.settings.forced_root_block = 'p';
  });

  suite.test('Remove empty UL between two textblocks', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<div>a</div>' +
      '<ul>' +
      '<li></li>' +
      '</ul>' +
      '<div>b</div>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'li:first', 0);
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<div>a</div>' +
      '<p>\u00a0</p>' +
      '<div>b</div>'
    );
    LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
  });

  suite.test('Remove indented list with single item', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ul>' +
      '<li>a' +
      '<ul>' +
      '<li>b</li>' +
      '</ul>' +
      '</li>' +
      '<li>c</li>' +
      '</ul>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'li li', 0, 'li li', 1);
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<ul>' +
      '<li>a</li>' +
      '</ul>' +
      '<p>b</p>' +
      '<ul>' +
      '<li>c</li>' +
      '</ul>'
    );
    LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
  });

  suite.test('Remove indented list with multiple items', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ul>' +
      '<li>a' +
      '<ul>' +
      '<li>b</li>' +
      '<li>c</li>' +
      '</ul>' +
      '</li>' +
      '<li>d</li>' +
      '</ul>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'li li:first', 0, 'li li:last', 1);
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<ul>' +
      '<li>a</li>' +
      '</ul>' +
      '<p>b</p>' +
      '<p>c</p>' +
      '<ul>' +
      '<li>d</li>' +
      '</ul>'
    );
    LegacyUnit.equal(editor.selection.getStart().firstChild.data, 'b');
    LegacyUnit.equal(editor.selection.getEnd().firstChild.data, 'c');
  });

  suite.test('Remove indented list with multiple items', function (editor) {
    editor.getBody().innerHTML = LegacyUnit.trimBrs(
      '<ul>' +
        '<li>a</li>' +
        '<li><p>b</p></li>' +
        '<li>c</li>' +
      '</ul>'
    );

    editor.focus();
    LegacyUnit.setSelection(editor, 'p', 0);
    LegacyUnit.execCommand(editor, 'InsertUnorderedList');

    LegacyUnit.equal(editor.getContent(),
      '<ul>' +
        '<li>a</li>' +
      '</ul>' +
      '<p>b</p>' +
      '<ul>' +
        '<li>c</li>' +
      '</ul>'
    );
  });

  // Ignore on IE 7, 8 this is a known bug not worth fixing
  if (!Env.ie || Env.ie > 8) {
    suite.test('Remove empty UL between two textblocks in BR mode', function (editor) {
      editor.settings.forced_root_block = false;

      editor.getBody().innerHTML = LegacyUnit.trimBrs(
        '<div>a</div>' +
        '<ul>' +
        '<li></li>' +
        '</ul>' +
        '<div>b</div>'
      );

      editor.focus();
      LegacyUnit.setSelection(editor, 'li:first', 0);
      LegacyUnit.execCommand(editor, 'InsertUnorderedList');

      LegacyUnit.equal(editor.getContent(),
        '<div>a</div>' +
        '<br />' +
        '<div>b</div>'
      );
      LegacyUnit.equal(editor.selection.getStart().nodeName, 'BR');

      editor.settings.forced_root_block = 'p';
    });
  }

  TinyLoader.setup(function (editor, onSuccess, onFailure) {
    Pipeline.async({}, suite.toSteps(editor), onSuccess, onFailure);
  }, {
    plugins: 'lists',
    add_unload_trigger: false,
    disable_nodechange: true,
    indent: false,
    entities: 'raw',
    valid_elements:
      'li[style|class|data-custom],ol[style|class|data-custom],' +
      'ul[style|class|data-custom],dl,dt,dd,em,strong,span,#p,div,br',
    valid_styles: {
      '*': 'color,font-size,font-family,background-color,font-weight,' +
        'font-style,text-decoration,float,margin,margin-top,margin-right,' +
        'margin-bottom,margin-left,display,position,top,left,list-style-type'
    },
    skin_url: '/project/js/tinymce/skins/lightgray'
  }, success, failure);
});
Example #11
0
 suite.test('clone', function () {
   LegacyUnit.deepEqual(ClientRect.clone(rect(10, 20, 30, 40)), rect(10, 20, 30, 40));
   LegacyUnit.deepEqual(ClientRect.clone(rect(10.1, 20.1, 30.1, 40.1)), rect(10, 20, 30, 40));
 });
UnitTest.asynctest('tinymce.lists.browser.BackspaceDeleteInlineTest', (success, failure) => {
  const suite = LegacyUnit.createSuite();

  Plugin();

  suite.test('TestCase-TBA: Lists: Backspace at beginning of LI on body UL', function (editor) {
    editor.focus();
    editor.selection.setCursorLocation(editor.getBody().firstChild.firstChild, 0);
    editor.plugins.lists.backspaceDelete();
    LegacyUnit.equal(DomQuery('#lists ul').length, 3);
    LegacyUnit.equal(DomQuery('#lists li').length, 3);
  });

  suite.test('TestCase-TBA: Lists: Delete at end of LI on body UL', function (editor) {
    editor.focus();
    editor.selection.setCursorLocation(editor.getBody().firstChild.firstChild, 1);
    editor.plugins.lists.backspaceDelete(true);
    LegacyUnit.equal(DomQuery('#lists ul').length, 3);
    LegacyUnit.equal(DomQuery('#lists li').length, 3);
  });

  const teardown = function (editor, div) {
    editor.remove();
    div.parentNode.removeChild(div);
  };

  const setup = function (success, failure) {
    const div = document.createElement('div');

    div.innerHTML = (
      '<div id="lists">' +
      '<ul><li>before</li></ul>' +
      '<ul id="inline"><li>x</li></ul>' +
      '<ul><li>after</li></ul>' +
      '</div>'
    );

    document.body.appendChild(div);

    EditorManager.init({
      selector: '#inline',
      inline: true,
      add_unload_trigger: false,
      skin: false,
      plugins: 'lists',
      disable_nodechange: true,
      init_instance_callback (editor) {
        Pipeline.async({}, Log.steps('TBA', 'Lists: Backspace delete inline tests', suite.toSteps(editor)), function () {
          teardown(editor, div);
          success();
        }, failure);
      },
      valid_styles: {
        '*': 'color,font-size,font-family,background-color,font-weight,font-style,text-decoration,float,' +
        'margin,margin-top,margin-right,margin-bottom,margin-left,display,position,top,left,list-style-type'
      }
    });
  };

  setup(success, failure);
});
Example #13
0
 suite.test('isEqual', function () {
   setupHtml('abc');
   LegacyUnit.equal(CaretPosition(getRoot(), 0).isEqual(CaretPosition(getRoot(), 0)), true);
   LegacyUnit.equal(CaretPosition(getRoot(), 1).isEqual(CaretPosition(getRoot(), 0)), false);
   LegacyUnit.equal(CaretPosition(getRoot(), 0).isEqual(CaretPosition(getRoot().firstChild, 0)), false);
 });
Example #14
0
UnitTest.asynctest('browser.tinymce.core.CaretPositionTest', function () {
  const success = arguments[arguments.length - 2];
  const failure = arguments[arguments.length - 1];
  const suite = LegacyUnit.createSuite();
  const createRange = CaretAsserts.createRange;
  const viewBlock = ViewBlock();

  if (!Env.ceFalse) {
    return;
  }

  const getRoot = function () {
    return viewBlock.get();
  };

  const setupHtml = function (html) {
    viewBlock.update(html);
  };

  suite.test('Constructor', function () {
    setupHtml('abc');
    LegacyUnit.equalDom(CaretPosition(getRoot(), 0).container(), getRoot());
    LegacyUnit.strictEqual(CaretPosition(getRoot(), 1).offset(), 1);
    LegacyUnit.equalDom(CaretPosition(getRoot().firstChild, 0).container(), getRoot().firstChild);
    LegacyUnit.strictEqual(CaretPosition(getRoot().firstChild, 1).offset(), 1);
  });

  suite.test('fromRangeStart', function () {
    setupHtml('abc');
    CaretAsserts.assertCaretPosition(CaretPosition.fromRangeStart(createRange(getRoot(), 0)), CaretPosition(getRoot(), 0));
    CaretAsserts.assertCaretPosition(CaretPosition.fromRangeStart(createRange(getRoot(), 1)), CaretPosition(getRoot(), 1));
    CaretAsserts.assertCaretPosition(
      CaretPosition.fromRangeStart(createRange(getRoot().firstChild, 1)),
      CaretPosition(getRoot().firstChild, 1)
    );
  });

  suite.test('fromRangeEnd', function () {
    setupHtml('abc');
    CaretAsserts.assertCaretPosition(
      CaretPosition.fromRangeEnd(createRange(getRoot(), 0, getRoot(), 1)),
      CaretPosition(getRoot(), 1)
    );
    CaretAsserts.assertCaretPosition(
      CaretPosition.fromRangeEnd(createRange(getRoot().firstChild, 0, getRoot().firstChild, 1)),
      CaretPosition(getRoot().firstChild, 1)
    );
  });

  suite.test('after', function () {
    setupHtml('abc<b>123</b>');
    CaretAsserts.assertCaretPosition(CaretPosition.after(getRoot().firstChild), CaretPosition(getRoot(), 1));
    CaretAsserts.assertCaretPosition(CaretPosition.after(getRoot().lastChild), CaretPosition(getRoot(), 2));
  });

  suite.test('before', function () {
    setupHtml('abc<b>123</b>');
    CaretAsserts.assertCaretPosition(CaretPosition.before(getRoot().firstChild), CaretPosition(getRoot(), 0));
    CaretAsserts.assertCaretPosition(CaretPosition.before(getRoot().lastChild), CaretPosition(getRoot(), 1));
  });

  suite.test('isAtStart', function () {
    setupHtml('abc<b>123</b>123');
    LegacyUnit.equal(CaretPosition(getRoot(), 0).isAtStart(), true);
    LegacyUnit.equal(!CaretPosition(getRoot(), 1).isAtStart(), true);
    LegacyUnit.equal(!CaretPosition(getRoot(), 3).isAtStart(), true);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild, 0).isAtStart(), true);
    LegacyUnit.equal(!CaretPosition(getRoot().firstChild, 1).isAtStart(), true);
    LegacyUnit.equal(!CaretPosition(getRoot().firstChild, 3).isAtStart(), true);
  });

  suite.test('isAtEnd', function () {
    setupHtml('abc<b>123</b>123');
    LegacyUnit.equal(CaretPosition(getRoot(), 3).isAtEnd(), true);
    LegacyUnit.equal(!CaretPosition(getRoot(), 2).isAtEnd(), true);
    LegacyUnit.equal(!CaretPosition(getRoot(), 0).isAtEnd(), true);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild, 3).isAtEnd(), true);
    LegacyUnit.equal(!CaretPosition(getRoot().firstChild, 0).isAtEnd(), true);
    LegacyUnit.equal(!CaretPosition(getRoot().firstChild, 1).isAtEnd(), true);
  });

  suite.test('toRange', function () {
    setupHtml('abc');
    CaretAsserts.assertRange(CaretPosition(getRoot(), 0).toRange(), createRange(getRoot(), 0));
    CaretAsserts.assertRange(CaretPosition(getRoot(), 1).toRange(), createRange(getRoot(), 1));
    CaretAsserts.assertRange(CaretPosition(getRoot().firstChild, 1).toRange(), createRange(getRoot().firstChild, 1));
  });

  suite.test('isEqual', function () {
    setupHtml('abc');
    LegacyUnit.equal(CaretPosition(getRoot(), 0).isEqual(CaretPosition(getRoot(), 0)), true);
    LegacyUnit.equal(CaretPosition(getRoot(), 1).isEqual(CaretPosition(getRoot(), 0)), false);
    LegacyUnit.equal(CaretPosition(getRoot(), 0).isEqual(CaretPosition(getRoot().firstChild, 0)), false);
  });

  suite.test('isVisible', function () {
    setupHtml('<b>  abc</b>');
    LegacyUnit.equal(CaretPosition(getRoot().firstChild.firstChild, 0).isVisible(), false);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild.firstChild, 3).isVisible(), true);
  });

  suite.test('getClientRects', function () {
    setupHtml(
      '<b>abc</b>' +
      '<div contentEditable="false">1</div>' +
      '<div contentEditable="false">2</div>' +
      '<div contentEditable="false">2</div>' +
      '<input style="margin: 10px">' +
      '<input style="margin: 10px">' +
      '<input style="margin: 10px">' +
      '<p>123</p>' +
      '<br>'
    );

    LegacyUnit.equal(CaretPosition(getRoot().firstChild.firstChild, 0).getClientRects().length, 1);
    LegacyUnit.equal(CaretPosition(getRoot(), 1).getClientRects().length, 1);
    LegacyUnit.equal(CaretPosition(getRoot(), 2).getClientRects().length, 2);
    LegacyUnit.equal(CaretPosition(getRoot(), 3).getClientRects().length, 2);
    LegacyUnit.equal(CaretPosition(getRoot(), 4).getClientRects().length, 2);
    LegacyUnit.equal(CaretPosition(getRoot(), 5).getClientRects().length, 1);
    LegacyUnit.equal(CaretPosition(getRoot(), 6).getClientRects().length, 1);
    LegacyUnit.equal(CaretPosition(getRoot(), 7).getClientRects().length, 1);
    LegacyUnit.equal(CaretPosition(getRoot(), 8).getClientRects().length, 1);
    LegacyUnit.equal(CaretPosition(getRoot(), 9).getClientRects().length, 0);
  });

  suite.test('getClientRects between inline node and cE=false', function () {
    setupHtml(
      '<span contentEditable="false">def</span>' +
      '<b>ghi</b>'
    );

    LegacyUnit.equal(CaretPosition(getRoot(), 1).getClientRects().length, 1);
  });

  suite.test('getClientRects at last visible character', function () {
    setupHtml('<b>a  </b>');

    LegacyUnit.equal(CaretPosition(getRoot().firstChild.firstChild, 1).getClientRects().length, 1);
  });

  suite.test('getClientRects at extending character', function () {
    setupHtml('a');
    const textNode = getRoot().firstChild as Text;
    textNode.appendData('\u0301b');

    LegacyUnit.equal(CaretPosition(getRoot().firstChild, 0).getClientRects().length, 1);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild, 1).getClientRects().length, 0);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild, 2).getClientRects().length, 1);
  });

  suite.test('getClientRects at whitespace character', function () {
    setupHtml('  a  ');

    LegacyUnit.equal(CaretPosition(getRoot().firstChild, 0).getClientRects().length, 0);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild, 1).getClientRects().length, 0);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild, 2).getClientRects().length, 1);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild, 3).getClientRects().length, 1);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild, 4).getClientRects().length, 0);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild, 5).getClientRects().length, 0);
  });

  suite.test('getClientRects at only one text node should return client rects', function () {
    setupHtml('<p>a<br>b</p>');
    LegacyUnit.equal(CaretPosition(getRoot().firstChild.firstChild, 0).getClientRects().length > 0, true);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild.firstChild, 1).getClientRects().length > 0, true);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild.lastChild, 0).getClientRects().length > 0, true);
    LegacyUnit.equal(CaretPosition(getRoot().firstChild.lastChild, 1).getClientRects().length > 0, true);
  });

  suite.test('getNode', function () {
    setupHtml('<b>abc</b><input><input>');

    LegacyUnit.equalDom(CaretPosition(getRoot().firstChild.firstChild, 0).getNode(), getRoot().firstChild.firstChild);
    LegacyUnit.equalDom(CaretPosition(getRoot(), 1).getNode(), getRoot().childNodes[1]);
    LegacyUnit.equalDom(CaretPosition(getRoot(), 2).getNode(), getRoot().childNodes[2]);
    LegacyUnit.equalDom(CaretPosition(getRoot(), 3).getNode(), getRoot().childNodes[2]);
  });

  suite.test('getNode (before)', function () {
    setupHtml('<b>abc</b><input><input>');

    LegacyUnit.equalDom(CaretPosition(getRoot().firstChild.firstChild, 0).getNode(true), getRoot().firstChild.firstChild);
    LegacyUnit.equalDom(CaretPosition(getRoot(), 1).getNode(true), getRoot().childNodes[0]);
    LegacyUnit.equalDom(CaretPosition(getRoot(), 2).getNode(true), getRoot().childNodes[1]);
    LegacyUnit.equalDom(CaretPosition(getRoot(), 3).getNode(true), getRoot().childNodes[2]);
  });

  suite.test('isAtStart/isAtEnd/isTextPosition', function () {
    setupHtml('<b>abc</b><p><input></p>');

    LegacyUnit.equal(CaretPosition.isAtStart(CaretPosition(getRoot().firstChild.firstChild, 0)), true);
    LegacyUnit.equal(CaretPosition.isAtStart(CaretPosition(getRoot().firstChild.firstChild, 1)), false);
    LegacyUnit.equal(CaretPosition.isAtStart(CaretPosition(getRoot().firstChild.firstChild, 3)), false);
    LegacyUnit.equal(CaretPosition.isAtStart(CaretPosition(getRoot().lastChild, 0)), true);
    LegacyUnit.equal(CaretPosition.isAtStart(CaretPosition(getRoot().lastChild, 1)), false);
    LegacyUnit.equal(CaretPosition.isAtEnd(CaretPosition(getRoot().firstChild.firstChild, 3)), true);
    LegacyUnit.equal(CaretPosition.isAtEnd(CaretPosition(getRoot().firstChild.firstChild, 1)), false);
    LegacyUnit.equal(CaretPosition.isAtEnd(CaretPosition(getRoot().firstChild.firstChild, 0)), false);
    LegacyUnit.equal(CaretPosition.isAtEnd(CaretPosition(getRoot().lastChild, 1)), true);
    LegacyUnit.equal(CaretPosition.isAtEnd(CaretPosition(getRoot().lastChild, 0)), false);
    LegacyUnit.equal(CaretPosition.isTextPosition(CaretPosition(getRoot().firstChild.firstChild, 0)), true);
    LegacyUnit.equal(CaretPosition.isTextPosition(CaretPosition(getRoot().lastChild, 0)), false);
  });

  viewBlock.attach();
  Pipeline.async({}, suite.toSteps({}), function () {
    viewBlock.detach();
    success();
  }, failure);
});
 const ok = function (value, label?) {
   return LegacyUnit.equal(value, true, label);
 };
Example #16
0
UnitTest.asynctest('browser.tinymce.core.geom.ClientRectTest', function () {
  const success = arguments[arguments.length - 2];
  const failure = arguments[arguments.length - 1];
  const suite = LegacyUnit.createSuite();

  const rect = function (x, y, w, h) {
    return {
      left: x,
      top: y,
      bottom: y + h,
      right: x + w,
      width: w,
      height: h
    };
  };

  suite.test('clone', function () {
    LegacyUnit.deepEqual(ClientRect.clone(rect(10, 20, 30, 40)), rect(10, 20, 30, 40));
    LegacyUnit.deepEqual(ClientRect.clone(rect(10.1, 20.1, 30.1, 40.1)), rect(10, 20, 30, 40));
  });

  suite.test('collapse', function () {
    LegacyUnit.deepEqual(ClientRect.collapse(rect(10, 20, 30, 40), true), rect(10, 20, 0, 40));
    LegacyUnit.deepEqual(ClientRect.collapse(rect(10, 20, 30, 40), false), rect(40, 20, 0, 40));
  });

  suite.test('isAbove', function () {
    LegacyUnit.equal(ClientRect.isAbove(rect(10, 70, 10, 40), rect(20, 40, 10, 20)), false);
    LegacyUnit.equal(ClientRect.isAbove(rect(10, 40, 10, 20), rect(20, 70, 10, 40)), true);
  });

  suite.test('isAbove intersects', function () {
    LegacyUnit.equal(ClientRect.isAbove(rect(10, 20, 10, 10), rect(20, 20, 10, 10)), false);
    LegacyUnit.equal(ClientRect.isAbove(rect(10, 20, 10, 40), rect(20, 20, 10, 10)), false);
    LegacyUnit.equal(ClientRect.isAbove(rect(10, 20, 10, 10), rect(20, 20, 10, 40)), false);
    LegacyUnit.equal(ClientRect.isAbove(rect(10, 10, 10, 10), rect(20, 15, 10, 10)), false);
    LegacyUnit.equal(ClientRect.isAbove(rect(10, 15, 10, 10), rect(20, 20, 10, 10)), false);
    LegacyUnit.equal(ClientRect.isAbove(rect(10, 10, 10, 10), rect(20, 20, 10, 10)), true);
    LegacyUnit.equal(ClientRect.isAbove(rect(10, 10, 10, 10), rect(20, 16, 10, 10)), true);
  });

  suite.test('isBelow', function () {
    LegacyUnit.equal(ClientRect.isBelow(rect(10, 70, 10, 40), rect(20, 40, 10, 20)), true);
    LegacyUnit.equal(ClientRect.isBelow(rect(10, 40, 10, 20), rect(20, 70, 10, 40)), false);
  });

  suite.test('isBelow intersects', function () {
    LegacyUnit.equal(ClientRect.isBelow(rect(10, 30, 10, 20), rect(20, 10, 10, 20)), true);
    LegacyUnit.equal(ClientRect.isBelow(rect(10, 30, 10, 20), rect(20, 10, 10, 25)), true);
    LegacyUnit.equal(ClientRect.isBelow(rect(10, 15, 10, 20), rect(20, 30, 10, 20)), false);
    LegacyUnit.equal(ClientRect.isBelow(rect(10, 29, 10, 20), rect(20, 10, 10, 30)), false);
    LegacyUnit.equal(ClientRect.isBelow(rect(10, 30, 10, 20), rect(20, 10, 10, 30)), true);
    LegacyUnit.equal(ClientRect.isBelow(rect(10, 20, 10, 20), rect(20, 10, 10, 30)), false);
  });

  suite.test('isLeft', function () {
    LegacyUnit.equal(ClientRect.isLeft(rect(10, 20, 30, 40), rect(20, 20, 30, 40)), true);
    LegacyUnit.equal(ClientRect.isLeft(rect(20, 20, 30, 40), rect(10, 20, 30, 40)), false);
  });

  suite.test('isRight', function () {
    LegacyUnit.equal(ClientRect.isRight(rect(10, 20, 30, 40), rect(20, 20, 30, 40)), false);
    LegacyUnit.equal(ClientRect.isRight(rect(20, 20, 30, 40), rect(10, 20, 30, 40)), true);
  });

  suite.test('compare', function () {
    LegacyUnit.equal(ClientRect.compare(rect(10, 70, 10, 40), rect(10, 40, 10, 20)), 1);
    LegacyUnit.equal(ClientRect.compare(rect(10, 40, 10, 20), rect(10, 70, 10, 40)), -1);
    LegacyUnit.equal(ClientRect.compare(rect(5, 10, 10, 10), rect(10, 10, 10, 10)), -1);
    LegacyUnit.equal(ClientRect.compare(rect(15, 10, 10, 10), rect(10, 10, 10, 10)), 1);
  });

  suite.test('containsXY', function () {
    LegacyUnit.equal(ClientRect.containsXY(rect(10, 70, 10, 40), 1, 2), false);
    LegacyUnit.equal(ClientRect.containsXY(rect(10, 70, 10, 40), 15, 2), false);
    LegacyUnit.equal(ClientRect.containsXY(rect(10, 70, 10, 40), 25, 2), false);
    LegacyUnit.equal(ClientRect.containsXY(rect(10, 70, 10, 40), 10, 70), true);
    LegacyUnit.equal(ClientRect.containsXY(rect(10, 70, 10, 40), 20, 110), true);
    LegacyUnit.equal(ClientRect.containsXY(rect(10, 70, 10, 40), 15, 75), true);
  });

  Pipeline.async({}, suite.toSteps({}), function () {
    success();
  }, failure);
});
 suite.test('mceInsertLink (relative)', function (editor) {
   editor.setContent('test 123');
   editor.execCommand('SelectAll');
   editor.execCommand('mceInsertLink', false, 'test');
   LegacyUnit.equal(editor.getContent(), '<p><a href="test">test 123</a></p>');
 });
Example #18
0
 suite.test('isRight', function () {
   LegacyUnit.equal(ClientRect.isRight(rect(10, 20, 30, 40), rect(20, 20, 30, 40)), false);
   LegacyUnit.equal(ClientRect.isRight(rect(20, 20, 30, 40), rect(10, 20, 30, 40)), true);
 });
 suite.test('mceInsertLink (link encoded and with class)', function (editor) {
   editor.setContent('<p>test 123</p>');
   editor.execCommand('SelectAll');
   editor.execCommand('mceInsertLink', false, { href: '"&<>', class: 'test' });
   LegacyUnit.equal(editor.getContent(), '<p><a class="test" href="&quot;&amp;&lt;&gt;">test 123</a></p>');
 });
Example #20
0
 suite.test('compare', function () {
   LegacyUnit.equal(ClientRect.compare(rect(10, 70, 10, 40), rect(10, 40, 10, 20)), 1);
   LegacyUnit.equal(ClientRect.compare(rect(10, 40, 10, 20), rect(10, 70, 10, 40)), -1);
   LegacyUnit.equal(ClientRect.compare(rect(5, 10, 10, 10), rect(10, 10, 10, 10)), -1);
   LegacyUnit.equal(ClientRect.compare(rect(15, 10, 10, 10), rect(10, 10, 10, 10)), 1);
 });
 suite.test('mceInsertLink (link floated img)', function (editor) {
   editor.setContent('<p><img style="float: right;" src="about:blank" /></p>');
   editor.execCommand('SelectAll');
   editor.execCommand('mceInsertLink', false, 'link');
   LegacyUnit.equal(editor.getContent(), '<p><a href="link"><img style="float: right;" src="about:blank" /></a></p>');
 });
  suite.test('construction', function () {
    let node;

    node = new Node('#text', 3);
    LegacyUnit.equal(node.name, '#text');
    LegacyUnit.equal(node.type, 3);

    node = new Node('#comment', 8);
    LegacyUnit.equal(node.name, '#comment');
    LegacyUnit.equal(node.type, 8);

    node = new Node('b', 1);
    LegacyUnit.equal(node.name, 'b');
    LegacyUnit.equal(node.type, 1);
    LegacyUnit.deepEqual(node.attributes, []);

    node = new Node('#pi', 7);
    LegacyUnit.equal(node.name, '#pi');
    LegacyUnit.equal(node.type, 7);

    node = new Node('#doctype', 10);
    LegacyUnit.equal(node.name, '#doctype');
    LegacyUnit.equal(node.type, 10);

    node = new Node('#cdata', 4);
    LegacyUnit.equal(node.name, '#cdata');
    LegacyUnit.equal(node.type, 4);

    node = new Node('#frag', 11);
    LegacyUnit.equal(node.name, '#frag');
    LegacyUnit.equal(node.type, 11);
  });
 suite.test('unlink', function (editor) {
   editor.setContent('<p><a href="test">test</a> <a href="test">123</a></p>');
   editor.execCommand('SelectAll');
   editor.execCommand('unlink');
   LegacyUnit.equal(editor.getContent(), '<p>test 123</p>');
 });
  suite.test('attr', function () {
    let node;

    node = new Node('b', 1);
    LegacyUnit.deepEqual(node.attributes, []);
    node.attr('attr1', 'value1');
    LegacyUnit.equal(node.attr('attr1'), 'value1');
    LegacyUnit.equal(node.attr('attr2'), undefined);
    LegacyUnit.deepEqual(node.attributes, [{ name: 'attr1', value: 'value1' }]);
    LegacyUnit.deepEqual(node.attributes.map, { attr1: 'value1' });

    node = new Node('b', 1);
    LegacyUnit.deepEqual(node.attributes, []);
    node.attr('attr1', 'value1');
    node.attr('attr1', 'valueX');
    LegacyUnit.equal(node.attr('attr1'), 'valueX');
    LegacyUnit.deepEqual(node.attributes, [{ name: 'attr1', value: 'valueX' }]);
    LegacyUnit.deepEqual(node.attributes.map, { attr1: 'valueX' });

    node = new Node('b', 1);
    LegacyUnit.deepEqual(node.attributes, []);
    node.attr('attr1', 'value1');
    node.attr('attr2', 'value2');
    LegacyUnit.equal(node.attr('attr1'), 'value1');
    LegacyUnit.equal(node.attr('attr2'), 'value2');
    LegacyUnit.deepEqual(node.attributes, [{ name: 'attr1', value: 'value1' }, { name: 'attr2', value: 'value2' }]);
    LegacyUnit.deepEqual(node.attributes.map, { attr1: 'value1', attr2: 'value2' });

    node = new Node('b', 1);
    LegacyUnit.deepEqual(node.attributes, []);
    node.attr('attr1', 'value1');
    node.attr('attr1', null);
    LegacyUnit.equal(node.attr('attr1'), undefined);
    LegacyUnit.deepEqual(node.attributes, []);
    LegacyUnit.deepEqual(node.attributes.map, {});

    node = new Node('b', 1);
    node.attr({ a: '1', b: '2' });
    LegacyUnit.deepEqual(node.attributes, [{ name: 'a', value: '1' }, { name: 'b', value: '2' }]);
    LegacyUnit.deepEqual(node.attributes.map, { a: '1', b: '2' });

    node = new Node('b', 1);
    node.attr(null);
    LegacyUnit.deepEqual(node.attributes, []);
    LegacyUnit.deepEqual(node.attributes.map, {});
  });
UnitTest.asynctest('browser.tinymce.core.FormattingCommandsTest', function () {
  const success = arguments[arguments.length - 2];
  const failure = arguments[arguments.length - 1];
  const suite = LegacyUnit.createSuite();

  Theme();

  const ok = function (value, label?) {
    return LegacyUnit.equal(value, true, label);
  };

  suite.test('Justify - multiple block elements selected - queryCommandState', function (editor) {
    editor.setContent(
      '<div style="text-align: left;"><div id="a" style="text-align: right;">' +
      'one</div><div id="b" style="text-align: right;">two</div></div>'
    );
    LegacyUnit.setSelection(editor, '#a', 0, '#b', 3);
    LegacyUnit.equal(editor.queryCommandState('JustifyLeft'), false);
    ok(editor.queryCommandState('JustifyRight'));
  });

  suite.test('Formatting commands (xhtmlTextStyles)', function (editor) {
    editor.focus();
    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('Bold');
    LegacyUnit.equal(editor.getContent(), '<p><strong>test 123</strong></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('Italic');
    LegacyUnit.equal(editor.getContent(), '<p><em>test 123</em></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('Underline');
    LegacyUnit.equal(editor.getContent(), '<p><span style="text-decoration: underline;">test 123</span></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('Strikethrough');
    LegacyUnit.equal(editor.getContent(), '<p><span style="text-decoration: line-through;">test 123</span></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('FontName', false, 'Arial');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-family: Arial;">test 123</span></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('FontSize', false, '7');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-size: xx-large;">test 123</span></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('ForeColor', false, '#FF0000');
    LegacyUnit.equal(editor.getContent(), '<p><span style="color: #ff0000;">test 123</span></p>');

    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('HiliteColor', false, '#FF0000');
    LegacyUnit.equal(editor.getContent(), '<p><span style="background-color: #ff0000;">test 123</span></p>');

    editor.setContent('<p><span style="text-decoration: underline;">test 123</span></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="text-decoration: underline;">test 123</span></p>');

    editor.setContent('<p><span style="text-decoration: line-through;">test 123</span></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="text-decoration: line-through;">test 123</span></p>');

    editor.setContent('<p><span style="font-family: Arial;">test 123</span></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-family: Arial;">test 123</span></p>');

    editor.setContent('<p><span style="font-size: xx-large;">test 123</span></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-size: xx-large;">test 123</span></p>');

    editor.setContent('<p><strike>test 123</strike></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="text-decoration: line-through;">test 123</span></p>');

    editor.setContent('<p><font face="Arial">test 123</font></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-family: Arial;">test 123</span></p>');

    editor.setContent('<p><font size="7">test 123</font></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-size: 300%;">test 123</span></p>');

    editor.setContent('<p><font face="Arial" size="7">test 123</font></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="font-size: 300%; font-family: Arial;">test 123</span></p>');

    editor.setContent('<font style="background-color: #ff0000" color="#ff0000">test</font><font face="Arial">test</font>');
    LegacyUnit.equal(
      editor.getContent(),
      '<p><span style="color: #ff0000; background-color: #ff0000;">test</span><span style="font-family: Arial;">test</span></p>'
    );

    editor.setContent('<p><font face="Arial" style="color: #ff0000">test 123</font></p>');
    LegacyUnit.equal(editor.getContent(), '<p><span style="color: #ff0000; font-family: Arial;">test 123</span></p>');
  });

  suite.test('Formatting commands (alignInline)', function (editor) {
    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('JustifyLeft');
    LegacyUnit.equal(editor.getContent(), '<p style="text-align: left;">test 123</p>');

    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('JustifyCenter');
    LegacyUnit.equal(editor.getContent(), '<p style="text-align: center;">test 123</p>');

    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('JustifyRight');
    LegacyUnit.equal(editor.getContent(), '<p style="text-align: right;">test 123</p>');

    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('JustifyFull');
    LegacyUnit.equal(editor.getContent(), '<p style="text-align: justify;">test 123</p>');

    editor.setContent('<img src="tinymce/ui/img/raster.gif" />');
    editor.selection.select(editor.dom.select('img')[0]);
    editor.execCommand('JustifyLeft');
    LegacyUnit.equal(editor.getContent(), '<p><img style="float: left;" src="tinymce/ui/img/raster.gif" /></p>');

    editor.setContent('<img src="tinymce/ui/img/raster.gif" />');
    editor.selection.select(editor.dom.select('img')[0]);
    editor.execCommand('JustifyCenter');
    LegacyUnit.equal(
      editor.getContent(),
      '<p><img style="margin-right: auto; margin-left: auto; display: block;" src="tinymce/ui/img/raster.gif" /></p>'
    );

    editor.setContent('<img src="tinymce/ui/img/raster.gif" />');
    editor.selection.select(editor.dom.select('img')[0]);
    editor.execCommand('JustifyRight');
    LegacyUnit.equal(editor.getContent(), '<p><img style="float: right;" src="tinymce/ui/img/raster.gif" /></p>');
  });

  suite.test('mceBlockQuote', function (editor) {
    editor.focus();
    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('mceBlockQuote');
    LegacyUnit.equal(editor.getContent().replace(/\s+/g, ''), '<blockquote><p>test123</p></blockquote>');

    editor.setContent('<p>test 123</p><p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('mceBlockQuote');
    LegacyUnit.equal(editor.getContent().replace(/\s+/g, ''), '<blockquote><p>test123</p><p>test123</p></blockquote>');
  });

  suite.test('FormatBlock', function (editor) {
    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('FormatBlock', false, 'h1');
    LegacyUnit.equal(editor.getContent(), '<h1>test 123</h1>');

    editor.execCommand('SelectAll');
    editor.execCommand('FormatBlock', false, 'h2');
    LegacyUnit.equal(editor.getContent(), '<h2>test 123</h2>');

    editor.execCommand('SelectAll');
    editor.execCommand('FormatBlock', false, 'h3');
    LegacyUnit.equal(editor.getContent(), '<h3>test 123</h3>');

    editor.execCommand('SelectAll');
    editor.execCommand('FormatBlock', false, 'h4');
    LegacyUnit.equal(editor.getContent(), '<h4>test 123</h4>');

    editor.execCommand('SelectAll');
    editor.execCommand('FormatBlock', false, 'h5');
    LegacyUnit.equal(editor.getContent(), '<h5>test 123</h5>');

    editor.execCommand('SelectAll');
    editor.execCommand('FormatBlock', false, 'h6');
    LegacyUnit.equal(editor.getContent(), '<h6>test 123</h6>');

    editor.execCommand('SelectAll');

    try {
      editor.execCommand('FormatBlock', false, 'div');
    } catch (ex) {
      // t.log('Failed: ' + ex.message);
    }

    LegacyUnit.equal(editor.getContent(), '<div>test 123</div>');

    editor.execCommand('SelectAll');
    editor.execCommand('FormatBlock', false, 'address');
    LegacyUnit.equal(editor.getContent(), '<address>test 123</address>');

    editor.execCommand('SelectAll');
    editor.execCommand('FormatBlock', false, 'pre');
    LegacyUnit.equal(editor.getContent(), '<pre>test 123</pre>');
  });

  suite.test('mceInsertLink (relative)', function (editor) {
    editor.setContent('test 123');
    editor.execCommand('SelectAll');
    editor.execCommand('mceInsertLink', false, 'test');
    LegacyUnit.equal(editor.getContent(), '<p><a href="test">test 123</a></p>');
  });

  suite.test('mceInsertLink (link absolute)', function (editor) {
    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('mceInsertLink', false, 'http://www.site.com');
    LegacyUnit.equal(editor.getContent(), '<p><a href="http://www.site.com">test 123</a></p>');
  });

  suite.test('mceInsertLink (link encoded)', function (editor) {
    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('mceInsertLink', false, '"&<>');
    LegacyUnit.equal(editor.getContent(), '<p><a href="&quot;&amp;&lt;&gt;">test 123</a></p>');
  });

  suite.test('mceInsertLink (link encoded and with class)', function (editor) {
    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('mceInsertLink', false, { href: '"&<>', class: 'test' });
    LegacyUnit.equal(editor.getContent(), '<p><a class="test" href="&quot;&amp;&lt;&gt;">test 123</a></p>');
  });

  suite.test('mceInsertLink (link with space)', function (editor) {
    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('mceInsertLink', false, { href: 'foo bar' });
    LegacyUnit.equal(editor.getContent(), '<p><a href="foo%20bar">test 123</a></p>');
  });

  suite.test('mceInsertLink (link floated img)', function (editor) {
    editor.setContent('<p><img style="float: right;" src="about:blank" /></p>');
    editor.execCommand('SelectAll');
    editor.execCommand('mceInsertLink', false, 'link');
    LegacyUnit.equal(editor.getContent(), '<p><a href="link"><img style="float: right;" src="about:blank" /></a></p>');
  });

  suite.test('mceInsertLink (link adjacent text)', function (editor) {
    let rng;

    editor.setContent('<p><a href="#">a</a>b</p>');

    rng = editor.dom.createRng();
    rng.setStart(editor.getBody().firstChild.lastChild, 0);
    rng.setEnd(editor.getBody().firstChild.lastChild, 1);
    editor.selection.setRng(rng);

    editor.execCommand('mceInsertLink', false, 'link');
    LegacyUnit.equal(editor.getContent(), '<p><a href="#">a</a><a href="link">b</a></p>');
  });

  suite.test('mceInsertLink (link text inside text)', function (editor) {
    editor.setContent('<p><a href="#"><em>abc</em></a></p>');
    LegacyUnit.setSelection(editor, 'em', 1, 'em', 2);

    editor.execCommand('mceInsertLink', false, 'link');
    LegacyUnit.equal(editor.getContent(), '<p><a href="link"><em>abc</em></a></p>');
  });

  suite.test('mceInsertLink (link around existing links)', function (editor) {
    editor.setContent('<p><a href="#1">1</a><a href="#2">2</a></p>');
    editor.execCommand('SelectAll');

    editor.execCommand('mceInsertLink', false, 'link');
    LegacyUnit.equal(editor.getContent(), '<p><a href="link">12</a></p>');
  });

  suite.test('mceInsertLink (link around existing links with different attrs)', function (editor) {
    editor.setContent('<p><a id="a" href="#1">1</a><a id="b" href="#2">2</a></p>');
    editor.execCommand('SelectAll');

    editor.execCommand('mceInsertLink', false, 'link');
    LegacyUnit.equal(editor.getContent(), '<p><a href="link">12</a></p>');
  });

  suite.test('mceInsertLink (link around existing complex contents with links)', function (editor) {
    editor.setContent(
      '<p><span id="s1"><strong><a id="a" href="#1"><em>1</em></a></strong></span><span id="s2">' +
      '<em><a id="b" href="#2"><strong>2</strong></a></em></span></p>'
    );
    editor.execCommand('SelectAll');

    editor.execCommand('mceInsertLink', false, 'link');
    LegacyUnit.equal(
      editor.getContent(),
      '<p><a href="link"><span id="s1"><strong><em>1</em>' +
        '</strong></span><span id="s2"><em><strong>2</strong></em></span></a></p>'
    );
  });

  suite.test('mceInsertLink (link text inside link)', function (editor) {
    editor.setContent('<p><a href="#">test</a></p>');
    LegacyUnit.setSelection(editor, 'p', 0, 'p', 1);
    editor.execCommand('SelectAll');

    editor.execCommand('mceInsertLink', false, 'link');
    LegacyUnit.equal(editor.getContent(), '<p><a href="link">test</a></p>');
  });

  suite.test('mceInsertLink bug #7331', function (editor) {
    editor.setContent('<table><tbody><tr><td>A</td></tr><tr><td>B</td></tr></tbody></table>');
    const rng = editor.dom.createRng();
    rng.setStart(editor.$('td')[1].firstChild, 0);
    rng.setEnd(editor.getBody(), 1);
    editor.selection.setRng(rng);
    editor.execCommand('mceInsertLink', false, { href: 'x' });
    LegacyUnit.equal(editor.getContent(), '<table><tbody><tr><td>A</td></tr><tr><td><a href=\"x\">B</a></td></tr></tbody></table>');
  });

  suite.test('unlink', function (editor) {
    editor.setContent('<p><a href="test">test</a> <a href="test">123</a></p>');
    editor.execCommand('SelectAll');
    editor.execCommand('unlink');
    LegacyUnit.equal(editor.getContent(), '<p>test 123</p>');
  });

  suite.test('unlink - unselected a[href] with childNodes', function (editor) {
    editor.setContent('<p><a href="test"><strong><em>test</em></strong></a></p>');
    LegacyUnit.setSelection(editor, 'em', 0);
    editor.execCommand('unlink');
    LegacyUnit.equal(editor.getContent(), '<p><strong><em>test</em></strong></p>');
  });

  suite.test('subscript/superscript', function (editor) {
    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('subscript');
    LegacyUnit.equal(editor.getContent(), '<p><sub>test 123</sub></p>');

    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('superscript');
    LegacyUnit.equal(editor.getContent(), '<p><sup>test 123</sup></p>');

    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('subscript');
    editor.execCommand('subscript');
    LegacyUnit.equal(editor.getContent(), '<p>test 123</p>');

    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('superscript');
    editor.execCommand('superscript');
    LegacyUnit.equal(editor.getContent(), '<p>test 123</p>');
  });

  suite.test('indent/outdent', function (editor) {
    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('Indent');
    LegacyUnit.equal(editor.getContent(), '<p style="padding-left: 30px;">test 123</p>');

    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('Indent');
    editor.execCommand('Indent');
    LegacyUnit.equal(editor.getContent(), '<p style="padding-left: 60px;">test 123</p>');

    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('Indent');
    editor.execCommand('Indent');
    editor.execCommand('Outdent');
    LegacyUnit.equal(editor.getContent(), '<p style="padding-left: 30px;">test 123</p>');

    editor.setContent('<p>test 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('Outdent');
    LegacyUnit.equal(editor.getContent(), '<p>test 123</p>');
  });

  suite.test('indent/outdent table always uses margin', function (editor) {
    editor.setContent('<table><tbody><tr><td>test</td></tr></tbody></table>');
    editor.execCommand('SelectAll');
    editor.execCommand('Indent');
    LegacyUnit.equal(editor.getContent(), '<table style="margin-left: 30px;"><tbody><tr><td>test</td></tr></tbody></table>');

    editor.setContent('<table><tbody><tr><td>test</td></tr></tbody></table>');
    editor.execCommand('SelectAll');
    editor.execCommand('Indent');
    editor.execCommand('Indent');
    LegacyUnit.equal(editor.getContent(), '<table style="margin-left: 60px;"><tbody><tr><td>test</td></tr></tbody></table>');

    editor.setContent('<table><tbody><tr><td>test</td></tr></tbody></table>');
    editor.execCommand('SelectAll');
    editor.execCommand('Indent');
    editor.execCommand('Indent');
    editor.execCommand('Outdent');
    LegacyUnit.equal(editor.getContent(), '<table style="margin-left: 30px;"><tbody><tr><td>test</td></tr></tbody></table>');

    editor.setContent('<table><tbody><tr><td>test</td></tr></tbody></table>');
    editor.execCommand('SelectAll');
    editor.execCommand('Outdent');
    LegacyUnit.equal(editor.getContent(), '<table><tbody><tr><td>test</td></tr></tbody></table>');
  });

  suite.test('RemoveFormat', function (editor) {
    editor.setContent('<p><em>test</em> <strong>123</strong> <a href="123">123</a> 123</p>');
    editor.execCommand('SelectAll');
    editor.execCommand('RemoveFormat');
    LegacyUnit.equal(editor.getContent(), '<p>test 123 <a href="123">123</a> 123</p>');

    editor.setContent('<p><em><em>test</em> <strong>123</strong> <a href="123">123</a> 123</em></p>');
    editor.execCommand('SelectAll');
    editor.execCommand('RemoveFormat');
    LegacyUnit.equal(editor.getContent(), '<p>test 123 <a href="123">123</a> 123</p>');

    editor.setContent('<p><em>test<span id="x">test <strong>123</strong></span><a href="123">123</a> 123</em></p>');
    editor.selection.select(editor.dom.get('x'));
    editor.execCommand('RemoveFormat');
    LegacyUnit.equal(editor.getContent(), '<p><em>test</em><span id="x">test 123</span><em><a href="123">123</a> 123</em></p>');

    editor.setContent(
      '<p><dfn>dfn tag </dfn> <code>code tag </code> <samp>samp tag</samp> ' +
      '<kbd> kbd tag</kbd> <var> var tag</var> <cite> cite tag</cite> <mark> mark tag</mark> <q> q tag</q></p>'
    );
    editor.execCommand('SelectAll');
    editor.execCommand('RemoveFormat');
    LegacyUnit.equal(editor.getContent(), '<p>dfn tag code tag samp tag kbd tag var tag cite tag mark tag q tag</p>');
  });

  TinyLoader.setup(function (editor, onSuccess, onFailure) {
    Pipeline.async({}, suite.toSteps(editor), onSuccess, onFailure);
  }, {
    add_unload_trigger: false,
    disable_nodechange: true,
    indent: false,
    entities: 'raw',
    convert_urls: false,
    valid_styles: {
      '*': 'color,font-size,font-family,background-color,font-weight,font-style,text-decoration,' +
        'float,margin,margin-top,margin-right,margin-bottom,margin-left,padding-left,text-align,display'
    },
    skin_url: '/project/js/tinymce/skins/lightgray'
  }, success, failure);
});
  suite.test('clone', function () {
    let root, node, clone;

    node = new Node('#text', 3);
    node.value = 'value';
    clone = node.clone();
    LegacyUnit.equal(clone.name, '#text');
    LegacyUnit.equal(clone.type, 3);
    LegacyUnit.equal(clone.value, 'value');
    LegacyUnit.equal(clone.parent, undefined);
    LegacyUnit.equal(clone.next, undefined);
    LegacyUnit.equal(clone.prev, undefined);

    root = new Node('#frag', 11);
    node = new Node('#text', 3);
    node.value = 'value';
    root.append(node);
    LegacyUnit.equal(clone.name, '#text');
    LegacyUnit.equal(clone.type, 3);
    LegacyUnit.equal(clone.value, 'value');
    LegacyUnit.equal(clone.parent, undefined);
    LegacyUnit.equal(clone.next, undefined);
    LegacyUnit.equal(clone.prev, undefined);

    node = new Node('b', 1);
    node.attr('id', 'id');
    node.attr('class', 'class');
    node.attr('title', 'title');
    clone = node.clone();
    LegacyUnit.equal(clone.name, 'b');
    LegacyUnit.equal(clone.type, 1);
    LegacyUnit.deepEqual(clone.attributes, [{ name: 'class', value: 'class' }, { name: 'title', value: 'title' }]);
    LegacyUnit.deepEqual(clone.attributes.map, { class: 'class', title: 'title' });
  });
Example #27
0
 suite.test('endsWithCaretContainer', function () {
   setupHtml('abc');
   const textNode = viewBlock.get().firstChild as Text;
   textNode.appendData(Zwsp.ZWSP);
   LegacyUnit.equal(CaretContainer.endsWithCaretContainer(getRoot().firstChild), true);
 });
UnitTest.asynctest('browser.tinymce.core.html.NodeTest', function () {
  const success = arguments[arguments.length - 2];
  const failure = arguments[arguments.length - 1];
  const suite = LegacyUnit.createSuite();

  const ok = function (value, label?) {
    return LegacyUnit.equal(value, true, label);
  };

  suite.test('construction', function () {
    let node;

    node = new Node('#text', 3);
    LegacyUnit.equal(node.name, '#text');
    LegacyUnit.equal(node.type, 3);

    node = new Node('#comment', 8);
    LegacyUnit.equal(node.name, '#comment');
    LegacyUnit.equal(node.type, 8);

    node = new Node('b', 1);
    LegacyUnit.equal(node.name, 'b');
    LegacyUnit.equal(node.type, 1);
    LegacyUnit.deepEqual(node.attributes, []);

    node = new Node('#pi', 7);
    LegacyUnit.equal(node.name, '#pi');
    LegacyUnit.equal(node.type, 7);

    node = new Node('#doctype', 10);
    LegacyUnit.equal(node.name, '#doctype');
    LegacyUnit.equal(node.type, 10);

    node = new Node('#cdata', 4);
    LegacyUnit.equal(node.name, '#cdata');
    LegacyUnit.equal(node.type, 4);

    node = new Node('#frag', 11);
    LegacyUnit.equal(node.name, '#frag');
    LegacyUnit.equal(node.type, 11);
  });

  suite.test('append inside empty node', function () {
    let root, node;

    root = new Node('#frag', 11);
    node = root.append(new Node('b', 1));
    LegacyUnit.equal(root.firstChild.parent === root, true);
    LegacyUnit.equal(root.firstChild.next, undefined);
    LegacyUnit.equal(root.firstChild.prev, undefined);
    LegacyUnit.equal(root.firstChild.firstChild, undefined);
    LegacyUnit.equal(root.firstChild.lastChild, undefined);
    LegacyUnit.equal(node.parent === root, true);
    LegacyUnit.equal(node.next, undefined);
    LegacyUnit.equal(node.prev, undefined);
    LegacyUnit.equal(node.firstChild, undefined);
    LegacyUnit.equal(node.lastChild, undefined);
  });

  suite.test('append node after node', function () {
    let root, node, node2;

    root = new Node('#frag', 11);
    node2 = root.append(new Node('a', 1));
    node = root.append(new Node('b', 1));
    ok(root.firstChild.parent === root, 'root.firstChild.parent === root');
    ok(root.firstChild === node2, 'root.firstChild');
    ok(root.lastChild === node, 'root.firstChild');
    ok(root.firstChild.next === node, 'root.firstChild.next');
    LegacyUnit.equal(root.firstChild.prev, undefined, 'root.firstChild.prev');
    LegacyUnit.equal(root.firstChild.firstChild, undefined, 'root.firstChild.firstChild');
    LegacyUnit.equal(root.firstChild.lastChild, undefined, 'root.firstChild.lastChild');
    ok(node2.parent === root, 'node2.parent === root');
    ok(node2.next === node, 'node2.next');
    LegacyUnit.equal(node2.prev, undefined, 'node2.prev');
    LegacyUnit.equal(node2.firstChild, undefined, 'node2.firstChild');
    LegacyUnit.equal(node2.lastChild, undefined, 'node2.lastChild');
    ok(node.parent === root, 'node.parent === root');
    LegacyUnit.equal(node.next, undefined, 'node.next');
    ok(node.prev === node2, 'node.prev');
    LegacyUnit.equal(node.firstChild, undefined, 'node.firstChild');
    LegacyUnit.equal(node.lastChild, undefined, 'node.lastChild');
  });

  suite.test('append existing node before other existing node', function () {
    let root, node, node2;

    root = new Node('#frag', 11);
    node = root.append(new Node('a', 1));
    node2 = root.append(new Node('b', 1));
    root.append(node);
    ok(root.firstChild === node2, 'root.firstChild');
    ok(root.lastChild === node, 'root.lastChild');
    LegacyUnit.equal(node.next, null, 'node.next');
    ok(node.prev === node2, 'node.prev');
    ok(node.parent === root, 'node.parent');
    ok(node2.parent === root, 'node2.parent');
    LegacyUnit.equal(node2.prev, undefined, 'node2.prev');
    ok(node2.next === node, 'node2.next');
  });

  suite.test('remove unattached node', function () {
    ok(!new Node('#text', 3).remove().parent);
  });

  suite.test('remove single child', function () {
    let root, node;

    root = new Node('#frag', 11);
    node = root.append(new Node('p', 1));
    node = root.firstChild.remove();
    LegacyUnit.equal(root.firstChild, undefined);
    LegacyUnit.equal(root.lastChild, undefined);
    LegacyUnit.equal(node.parent, null);
    LegacyUnit.equal(node.next, null);
    LegacyUnit.equal(node.prev, null);
    LegacyUnit.equal(node.name, 'p');
  });

  suite.test('remove middle node', function () {
    let root, node, node2, node3;

    root = new Node('#frag', 11);
    node = root.append(new Node('a', 1));
    node2 = root.append(new Node('b', 1));
    node3 = root.append(new Node('c', 1));
    node2.remove();
    LegacyUnit.equal(node2.parent, null);
    LegacyUnit.equal(node2.next, null);
    LegacyUnit.equal(node2.prev, null);
    ok(root.firstChild === node, 'root.firstChild');
    ok(root.lastChild === node3, 'root.lastChild');
    ok(node.next === node3, 'node.next');
    LegacyUnit.equal(node.prev, undefined, 'node.prev');
    LegacyUnit.equal(node3.prev === node, true, 'node3.prev');
    LegacyUnit.equal(node3.next, undefined, 'node3.next');
  });

  suite.test('insert after last', function () {
    let fragment, root, node, node2;

    fragment = new Node('#frag', 11);
    root = fragment.append(new Node('body', 1));
    node = root.append(new Node('a', 1));
    node2 = root.insert(new Node('x', 1), node);
    ok(root.firstChild === node, 'root.firstChild');
    ok(root.lastChild === node2, 'root.lastChild');
    ok(node.next === node2, 'node.next');
    ok(node2.prev === node, 'node2.prev');
    ok(node2.parent === root, 'node3.next');
  });

  suite.test('insert before first', function () {
    let fragment, root, node, node2;

    fragment = new Node('#frag', 11);
    root = fragment.append(new Node('body', 1));
    node = root.append(new Node('a', 1));
    node2 = root.insert(new Node('x', 1), node, true);
    ok(root.firstChild === node2, 'root.firstChild');
    ok(root.lastChild === node, 'root.lastChild');
    ok(node2.parent === root, 'node2.lastChild');
    ok(node2.next === node, 'node2.next');
    ok(node2.prev === undefined, 'node2.prev');
    ok(node.parent === root, 'node.lastChild');
    ok(node.next === undefined, 'node.next');
    ok(node.prev === node2, 'node.prev');
  });

  suite.test('insert before second', function () {
    let fragment, root, node, node2, node3;

    fragment = new Node('#frag', 11);
    root = fragment.append(new Node('body', 1));
    node = root.append(new Node('a', 1));
    node2 = root.append(new Node('b', 1));
    node3 = root.insert(new Node('x', 1), node2, true);
    ok(root.firstChild === node, 'root.firstChild');
    ok(root.lastChild === node2, 'root.lastChild');
    ok(node3.parent === root, 'node3.parent');
    ok(node3.next === node2, 'node3.next');
    ok(node3.prev === node, 'node3.prev');
  });

  suite.test('insert after and between two nodes', function () {
    let root, node, node2, node3, fragment;

    fragment = new Node('#frag', 11);
    root = fragment.append(new Node('body', 1));
    node = root.append(new Node('a', 1));
    node2 = root.append(new Node('b', 1));
    node3 = root.insert(new Node('x', 1), node);
    ok(root.firstChild === node, 'root.firstChild');
    ok(root.lastChild === node2, 'root.lastChild');
    ok(node.next === node3, 'node.next');
    ok(node2.prev === node3, 'node2.prev');
    ok(node3.parent === root, 'node3.next');
    ok(node3.next === node2, 'node3.next');
    ok(node3.prev === node, 'node3.prev');
  });

  suite.test('replace single child', function () {
    let root, node1, node2;

    root = new Node('#frag', 11);
    node1 = root.append(new Node('b', 1));
    node2 = root.append(new Node('em', 1));
    node1.replace(node2);
    ok(root.firstChild === node2, 'root.firstChild');
    ok(root.lastChild === node2, 'root.lastChild');
    ok(node2.parent === root, 'node2.parent');
    ok(!node2.next, 'node2.next');
    ok(!node2.prev, 'node2.prev');
  });

  suite.test('replace first child', function () {
    let root, node1, node2, node3;

    root = new Node('#frag', 11);
    node1 = root.append(new Node('b', 1));
    node2 = root.append(new Node('em', 1));
    node3 = root.append(new Node('b', 1));
    node1.replace(node2);
    ok(root.firstChild === node2, 'root.firstChild');
    ok(root.lastChild === node3, 'root.lastChild');
    ok(node2.parent === root, 'node2.parent');
    ok(node2.next === node3, 'node2.next');
    ok(!node2.prev, 'node2.prev');
  });

  suite.test('replace last child', function () {
    let root, node1, node2, node3;

    root = new Node('#frag', 11);
    node1 = root.append(new Node('b', 1));
    node3 = root.append(new Node('b', 1));
    node2 = root.append(new Node('em', 1));
    node3.replace(node2);
    ok(root.firstChild === node1, 'root.firstChild');
    ok(root.lastChild === node2, 'root.lastChild');
    ok(node2.parent === root, 'node2.parent');
    ok(!node2.next, 'node2.next');
    ok(node2.prev === node1, 'node2.prev');
  });

  suite.test('replace middle child', function () {
    let root, node1, node2, node3, node4;

    root = new Node('#frag', 11);
    node1 = root.append(new Node('b', 1));
    node2 = root.append(new Node('b', 1));
    node3 = root.append(new Node('b', 1));
    node4 = root.append(new Node('em', 1));
    node2.replace(node4);
    ok(root.firstChild === node1, 'root.firstChild');
    ok(root.lastChild === node3, 'root.lastChild');
    ok(node4.parent === root, 'node4.parent');
    ok(node4.next === node3, 'node4.next');
    ok(node4.prev === node1, 'node4.prev');
  });

  suite.test('attr', function () {
    let node;

    node = new Node('b', 1);
    LegacyUnit.deepEqual(node.attributes, []);
    node.attr('attr1', 'value1');
    LegacyUnit.equal(node.attr('attr1'), 'value1');
    LegacyUnit.equal(node.attr('attr2'), undefined);
    LegacyUnit.deepEqual(node.attributes, [{ name: 'attr1', value: 'value1' }]);
    LegacyUnit.deepEqual(node.attributes.map, { attr1: 'value1' });

    node = new Node('b', 1);
    LegacyUnit.deepEqual(node.attributes, []);
    node.attr('attr1', 'value1');
    node.attr('attr1', 'valueX');
    LegacyUnit.equal(node.attr('attr1'), 'valueX');
    LegacyUnit.deepEqual(node.attributes, [{ name: 'attr1', value: 'valueX' }]);
    LegacyUnit.deepEqual(node.attributes.map, { attr1: 'valueX' });

    node = new Node('b', 1);
    LegacyUnit.deepEqual(node.attributes, []);
    node.attr('attr1', 'value1');
    node.attr('attr2', 'value2');
    LegacyUnit.equal(node.attr('attr1'), 'value1');
    LegacyUnit.equal(node.attr('attr2'), 'value2');
    LegacyUnit.deepEqual(node.attributes, [{ name: 'attr1', value: 'value1' }, { name: 'attr2', value: 'value2' }]);
    LegacyUnit.deepEqual(node.attributes.map, { attr1: 'value1', attr2: 'value2' });

    node = new Node('b', 1);
    LegacyUnit.deepEqual(node.attributes, []);
    node.attr('attr1', 'value1');
    node.attr('attr1', null);
    LegacyUnit.equal(node.attr('attr1'), undefined);
    LegacyUnit.deepEqual(node.attributes, []);
    LegacyUnit.deepEqual(node.attributes.map, {});

    node = new Node('b', 1);
    node.attr({ a: '1', b: '2' });
    LegacyUnit.deepEqual(node.attributes, [{ name: 'a', value: '1' }, { name: 'b', value: '2' }]);
    LegacyUnit.deepEqual(node.attributes.map, { a: '1', b: '2' });

    node = new Node('b', 1);
    node.attr(null);
    LegacyUnit.deepEqual(node.attributes, []);
    LegacyUnit.deepEqual(node.attributes.map, {});
  });

  suite.test('clone', function () {
    let root, node, clone;

    node = new Node('#text', 3);
    node.value = 'value';
    clone = node.clone();
    LegacyUnit.equal(clone.name, '#text');
    LegacyUnit.equal(clone.type, 3);
    LegacyUnit.equal(clone.value, 'value');
    LegacyUnit.equal(clone.parent, undefined);
    LegacyUnit.equal(clone.next, undefined);
    LegacyUnit.equal(clone.prev, undefined);

    root = new Node('#frag', 11);
    node = new Node('#text', 3);
    node.value = 'value';
    root.append(node);
    LegacyUnit.equal(clone.name, '#text');
    LegacyUnit.equal(clone.type, 3);
    LegacyUnit.equal(clone.value, 'value');
    LegacyUnit.equal(clone.parent, undefined);
    LegacyUnit.equal(clone.next, undefined);
    LegacyUnit.equal(clone.prev, undefined);

    node = new Node('b', 1);
    node.attr('id', 'id');
    node.attr('class', 'class');
    node.attr('title', 'title');
    clone = node.clone();
    LegacyUnit.equal(clone.name, 'b');
    LegacyUnit.equal(clone.type, 1);
    LegacyUnit.deepEqual(clone.attributes, [{ name: 'class', value: 'class' }, { name: 'title', value: 'title' }]);
    LegacyUnit.deepEqual(clone.attributes.map, { class: 'class', title: 'title' });
  });

  suite.test('unwrap', function () {
    let root, node1, node2, node3;

    root = new Node('#frag', 11);
    node1 = root.append(new Node('b', 1));
    node2 = node1.append(new Node('em', 1));
    node1.unwrap();
    ok(root.firstChild === node2, 'root.firstChild');
    ok(root.lastChild === node2, 'root.lastChild');
    ok(node2.parent === root, 'node2.parent');

    root = new Node('#frag', 11);
    node1 = root.append(new Node('b', 1));
    node2 = node1.append(new Node('em', 1));
    node3 = node1.append(new Node('span', 1));
    node1.unwrap();
    ok(root.firstChild === node2, 'root.firstChild');
    ok(root.lastChild === node3, 'root.lastChild');
    ok(node2.parent === root, 'node2.parent');
    ok(node3.parent === root, 'node3.parent');
  });

  suite.test('empty', function () {
    let root, node1;

    root = new Node('#frag', 11);
    node1 = root.append(new Node('b', 1));
    node1.empty();
    ok(root.firstChild === node1, 'root.firstChild');
    ok(root.lastChild === node1, 'root.firstChild');
    ok(!node1.firstChild, 'node1.firstChild');
    ok(!node1.lastChild, 'node1.firstChild');
  });

  suite.test('isEmpty', function () {
    let root, node1, node2;

    root = new Node('#frag', 11);
    node1 = root.append(new Node('p', 1));
    node2 = node1.append(new Node('b', 1));
    ok(root.isEmpty({ img: 1 }), 'Is empty 1');
    ok(node1.isEmpty({ img: 1 }), 'Is empty 2');

    root = new Node('#frag', 11);
    node1 = root.append(new Node('p', 1));
    node2 = node1.append(new Node('img', 1));
    ok(!root.isEmpty({ img: 1 }), 'Is not empty 1');
    ok(!node1.isEmpty({ img: 1 }), 'Is not empty 2');

    root = new Node('#frag', 11);
    node1 = root.append(new Node('p', 1));
    node2 = node1.append(new Node('#text', 3));
    node2.value = 'X';
    ok(!root.isEmpty({ img: 1 }), 'Is not empty 3');
    ok(!node1.isEmpty({ img: 1 }), 'Is not empty 4');

    root = new Node('#frag', 11);
    node1 = root.append(new Node('p', 1));
    node2 = node1.append(new Node('#text', 3));
    node2.value = '';
    ok(root.isEmpty({ img: 1 }), 'Is empty 4');
    ok(node1.isEmpty({ img: 1 }), 'Is empty 5');

    root = new Node('#frag', 11);
    node1 = root.append(new Node('a', 1)).attr('name', 'x');
    ok(!root.isEmpty({ img: 1 }), 'Contains anchor with name attribute.');

    const isSpan = function (node) {
      return node.name === 'span';
    };

    root = new Node('#frag', 11);
    node1 = root.append(new Node('span', 1));
    LegacyUnit.equal(root.isEmpty({ img: 1 }, {}, isSpan), false, 'Should be false since the predicate says true.');

    root = new Node('#frag', 11);
    node1 = root.append(new Node('b', 1));
    LegacyUnit.equal(root.isEmpty({ img: 1 }, {}, isSpan), true, 'Should be true since the predicate says false.');
  });

  Pipeline.async({}, suite.toSteps({}), function () {
    success();
  }, failure);
});
Example #29
0
 suite.test('prependInline', function () {
   setupHtml('a');
   const caretContainerTextNode = CaretContainer.prependInline(getRoot().firstChild) as Text;
   LegacyUnit.equal(caretContainerTextNode.data, Zwsp.ZWSP + 'a');
 });
Example #30
0
  suite.test('getClientRects at last visible character', function () {
    setupHtml('<b>a  </b>');

    LegacyUnit.equal(CaretPosition(getRoot().firstChild.firstChild, 1).getClientRects().length, 1);
  });