当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Log.chains方法代码示例

本文整理汇总了TypeScript中@ephox/agar.Log.chains方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Log.chains方法的具体用法?TypeScript Log.chains怎么用?TypeScript Log.chains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@ephox/agar.Log的用法示例。


在下文中一共展示了Log.chains方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: Theme

UnitTest.asynctest('tinymce.plugins.paste.browser.PasteSettingsTest', (success, failure) => {
  Theme();
  Plugin();

  const cCreateInlineEditor = function (settings) {
    return Chain.control(
      McEditor.cFromSettings(Merger.merge(settings, {
        inline: true,
        base_url: '/project/tinymce/js/tinymce'
      })),
      Guard.addLogging('Create inline editor')
    );
  };

  const cRemoveEditor = Chain.control(
    McEditor.cRemove,
    Guard.addLogging('Remove editor')
  );

  Pipeline.async({}, [
    Chain.asStep({}, Log.chains('TBA', 'Paste: paste_as_text setting', [
      cCreateInlineEditor({
        paste_as_text: true,
        plugins: 'paste'
      }),
      Chain.op(function (editor) {
        Assertions.assertEq('Should be text format', 'text', editor.plugins.paste.clipboard.pasteFormat.get());
      }),
      cRemoveEditor
    ]))
  ], function () {
    success();
  }, failure);
});
开发者ID:tinymce,项目名称:tinymce,代码行数:34,代码来源:PasteSettingsTest.ts

示例2: Cell

  TinyLoader.setup(function (editor, onSuccess, onFailure) {
    const lastEventArgs = Cell(null);

    editor.on('FullscreenStateChanged', function (e) {
      lastEventArgs.set(e);
    });

    const cAssertEditorAndLastEvent = (label, state) =>
      Chain.control(
        Chain.fromChains([
          Chain.op(() => Assertions.assertEq('Editor isFullscreen', state, editor.plugins.fullscreen.isFullscreen())),
          Chain.op(() => Assertions.assertEq('FullscreenStateChanged event', state, lastEventArgs.get().state))
        ]),
        Guard.addLogging(label)
      );

    const cAssertFullscreenClass = (label, shouldExist) => {
      const selector = shouldExist ? 'root:.tox-fullscreen' : 'root::not(.tox-fullscreen)';
      const label2 = `Body and Html should ${shouldExist ? '' : 'not '}have "tox-fullscreen" class`;
      return Chain.control(
        Chain.fromChains([
          Chain.inject(Body.body()),
          UiFinder.cFindIn(selector),
          Chain.inject(Element.fromDom(document.documentElement)),
          UiFinder.cFindIn(selector)
        ]),
        Guard.addLogging(`${label}: ${label2}`)
      );
    };

    const cCloseOnlyWindow =  Chain.control(
      Chain.op(() => {
        const dialogs = () => UiFinder.findAllIn(Body.body(), '[role="dialog"]');
        Assertions.assertEq('One window exists', 1, dialogs().length);
        editor.windowManager.close();
        Assertions.assertEq('No windows exist', 0, dialogs().length);
      }),
      Guard.addLogging('Close window')
    );

    Chain.pipeline(
      Log.chains('TBA', 'FullScreen: Toggle fullscreen on, open link dialog, insert link, close dialog and toggle fullscreen off', [
        cAssertFullscreenClass('Before fullscreen command', false),
        Chain.op(() => editor.execCommand('mceFullScreen', true)),
        cAssertEditorAndLastEvent('After fullscreen command', true),
        cAssertFullscreenClass('After fullscreen command', true),
        Chain.op(() => editor.execCommand('mceLink', true)),
        cWaitForDialog('Insert/Edit Link'),
        cCloseOnlyWindow,
        cAssertFullscreenClass('After window is closed', true),
        Chain.op(() => editor.execCommand('mceFullScreen')),
        cAssertEditorAndLastEvent('After fullscreen toggled', false),
        cAssertFullscreenClass('After fullscreen toggled', false),
      ])
    , onSuccess, onFailure);
  }, {
开发者ID:tinymce,项目名称:tinymce,代码行数:56,代码来源:FullScreenPluginTest.ts

示例3: cProcessPre

  TinyLoader.setup(function (editor, onSuccess, onFailure) {
    Pipeline.async({}, [
      Chain.asStep(editor, Log.chains('TBA', 'Paste: Paste pre process only', [
        cProcessPre('a', true, preProcessHandler),
        Assertions.cAssertEq('Should be preprocessed by adding a X', { content: 'aX', cancelled: false })
      ])),

      Chain.asStep(editor, Log.chains('TBA', 'Paste: Paste pre/post process passthough as is', [
        cProcessPrePost('a', true, Fun.noop, Fun.noop),
        Assertions.cAssertEq('Should be unchanged', { content: 'a', cancelled: false })
      ])),

      Chain.asStep(editor, Log.chains('TBA', 'Paste: Paste pre/post process assert internal false', [
        cProcessPrePost('a', false, assertInternal(false), assertInternal(false)),
        Assertions.cAssertEq('Should be unchanged', { content: 'a', cancelled: false })
      ])),

      Chain.asStep(editor, Log.chains('TBA', 'Paste: Paste pre/post process assert internal true', [
        cProcessPrePost('a', true, assertInternal(true), assertInternal(true)),
        Assertions.cAssertEq('Should be unchanged', { content: 'a', cancelled: false })
      ])),

      Chain.asStep(editor, Log.chains('TBA', 'Paste: Paste pre/post process alter on preprocess', [
        cProcessPrePost('a', true, preProcessHandler, Fun.noop),
        Assertions.cAssertEq('Should be preprocessed by adding a X', { content: 'aX', cancelled: false })
      ])),

      Chain.asStep(editor, Log.chains('TBA', 'Paste: Paste pre/post process alter on postprocess', [
        cProcessPrePost('a<b>b</b>c', true, Fun.noop, postProcessHandler(editor)),
        Assertions.cAssertEq('Should have all b elements removed', { content: 'abc', cancelled: false })
      ])),

      Chain.asStep(editor, Log.chains('TBA', 'Paste: Paste pre/post process alter on preprocess/postprocess', [
        cProcessPrePost('a<b>b</b>c', true, preProcessHandler, postProcessHandler(editor)),
        Assertions.cAssertEq('Should have all b elements removed and have a X added', { content: 'abcX', cancelled: false })
      ])),

      Chain.asStep(editor, Log.chains('TBA', 'Paste: Paste pre/post process prevent default on preProcess', [
        cProcessPrePost('a<b>b</b>c', true, preventHandler, postProcessHandler(editor)),
        Assertions.cAssertEq('Should have all b elements removed and be cancelled', { content: 'a<b>b</b>c', cancelled: true })
      ])),

      Chain.asStep(editor, Log.chains('TBA', 'Paste: Paste pre/post process prevent default on postProcess', [
        cProcessPrePost('a<b>b</b>c', true, preProcessHandler, preventHandler),
        Assertions.cAssertEq('Should have a X added and be cancelled', { content: 'a<b>b</b>cX', cancelled: true })
      ]))
    ], onSuccess, onFailure);
  }, {
开发者ID:tinymce,项目名称:tinymce,代码行数:48,代码来源:ProcessFiltersTest.ts

示例4: Theme

UnitTest.asynctest('tinymce.plugins.paste.browser.PasteBin', (success, failure) => {

  Theme();
  PastePlugin();

  const cases = [
    {
      label: 'TINY-1162: testing nested paste bins',
      content: '<div id="mcepastebin" contenteditable="true" data-mce-bogus="all" data-mce-style="position: absolute; top: 0.40000057220458984px;width: 10px; height: 10px; overflow: hidden; opacity: 0" style="position: absolute; top: 0.40000057220458984px;width: 10px; height: 10px; overflow: hidden; opacity: 0"><div id="mcepastebin" data-mce-bogus="all" data-mce-style="position: absolute; top: 0.40000057220458984px;width: 10px; height: 10px; overflow: hidden; opacity: 0" style="position: absolute; top: 0.40000057220458984px;width: 10px; height: 10px; overflow: hidden; opacity: 0">a</div><div id="mcepastebin" data-mce-bogus="all" data-mce-style="position: absolute; top: 0.40000057220458984px;width: 10px; height: 10px; overflow: hidden; opacity: 0" style="position: absolute; top: 0.40000057220458984px;width: 10px; height: 10px; overflow: hidden; opacity: 0">b</div></div>',
      result: '<div>a</div><div>b</div>'
    },
    {
      label: 'TINY-1162: testing adjacent paste bins',
      content: '<div id="mcepastebin" contenteditable="true" data-mce-bogus="all" data-mce-style="position: absolute; top: 0.40000057220458984px;width: 10px; height: 10px; overflow: hidden; opacity: 0" style="position: absolute; top: 0.40000057220458984px;width: 10px; height: 10px; overflow: hidden; opacity: 0"><p>a</p><p>b</p></div><div id="mcepastebin" contenteditable="true" data-mce-bogus="all" data-mce-style="position: absolute; top: 0.40000057220458984px;width: 10px; height: 10px; overflow: hidden; opacity: 0" style="position: absolute; top: 0.40000057220458984px;width: 10px; height: 10px; overflow: hidden; opacity: 0"><p>c</p></div>',
      result: '<p>a</p><p>b</p><p>c</p>'
    }
  ];

  const cCreateEditorFromSettings = function (settings?, html?) {
    return Chain.control(
      McEditor.cFromHtml(html, Merger.merge(settings || {}, {
        add_unload_trigger: false,
        indent: false,
        plugins: 'paste',
        base_url: '/project/tinymce/js/tinymce'
      })),
      Guard.addLogging(`Create editor using settings ${settings}`)
    );
  };

  const cCreateEditorFromHtml = function (html, settings) {
    return Chain.control(
      cCreateEditorFromSettings(settings, html),
      Guard.addLogging(`Create editor using ${html}`)
    );
  };

  const cRemoveEditor = function () {
    return Chain.control(
      McEditor.cRemove,
      Guard.addLogging('Remove Editor')
    );
  };

  const cAssertCases = function (cases) {
    return Chain.control(
      Chain.op(function (editor: any) {
        const pasteBin = PasteBin(editor);
        Obj.each(cases, function (c, i) {
          getPasteBinParent(editor).appendChild(editor.dom.createFragment(c.content));
          Assertions.assertEq(c.label || 'Asserting paste bin case ' + i, c.result, pasteBin.getHtml());
          pasteBin.remove();
        });
      }),
      Guard.addLogging('Assert cases')
    );
  };

  Pipeline.async({}, [
    Chain.asStep({}, Log.chains('TBA', 'Paste: Create editor from settings and test nested and adjacent paste bins', [
      cCreateEditorFromSettings(),
      cAssertCases(cases),
      cRemoveEditor()
    ])),

    // TINY-1208/TINY-1209: same cases, but for inline editor
    Chain.asStep({}, Log.chains('TBA', 'Paste: Create editor from html and test nested and adjacent paste bins', [
      cCreateEditorFromHtml('<div>some text</div>', { inline: true }),
      cAssertCases(cases),
      cRemoveEditor()
    ]))
  ], function () {
    success();
  }, failure);
});
开发者ID:tinymce,项目名称:tinymce,代码行数:75,代码来源:PasteBinTest.ts

示例5: Plugin


//.........这里部分代码省略.........
        editor.setContent(table);
        const bodyElem = TinyDom.fromDom(editor.getBody());
        const tableElem = UiFinder.findIn(bodyElem, 'table').getOr(bodyElem);
        SelectorFind.descendant(tableElem, 'td,th').each((cell) => {
          editor.selection.select(cell.dom(), true);
          editor.selection.collapse(true);
        });
        return tableElem;
      }),
      Guard.addLogging(`Insert ${label}`)
    );
  };

  const cUnmergeCellsMeasureTableWidth = (label, data) => {
    return Log.chain('TBA', 'Merge and unmerge cells, measure table widths', NamedChain.asChain(
       [
        NamedChain.direct(NamedChain.inputName(), Chain.identity, 'editor'),
        Chain.label('Insert table', NamedChain.direct('editor', cInsertTable(label, data.html), 'element')),
        Chain.label('Drag SE (-100, 0)', NamedChain.read('editor', TableTestUtils.cDragHandle('se', -100, 0))),
        Chain.label('Store width before merge', NamedChain.write('widthBefore', TableTestUtils.cGetWidth)),
        Chain.label('Merge table cells', NamedChain.read('editor', TableTestUtils.cMergeCells(data.select))),
        Chain.label('Split table cells', NamedChain.read('editor', TableTestUtils.cSplitCells)),
        Chain.label('Store width after merge/unmerge', NamedChain.write('widthAfter', TableTestUtils.cGetWidth)),
        NamedChain.merge(['widthBefore', 'widthAfter'], 'widths'),
        NamedChain.output('widths')
      ]
    ));
  };

  const cMergeResizeUnmergeMeasureWidth = (label, data) => {
    return Log.chain('TBA', 'Merge cells and resize table, unmerge cells and measure table widths', NamedChain.asChain(
      [
        NamedChain.direct(NamedChain.inputName(), Chain.identity, 'editor'),
        Chain.label('Insert table', NamedChain.direct('editor', cInsertTable(label, data.html), 'element')),
        Chain.label('Drag SE (-100, 0)', NamedChain.read('editor', TableTestUtils.cDragHandle('se', -100, 0))),
        Chain.label('Merge table cells', NamedChain.read('editor', TableTestUtils.cMergeCells(data.select))),
        Chain.label('Drag SE (-100, 0)', NamedChain.read('editor', TableTestUtils.cDragHandle('se', -100, 0))),
        Chain.label('Store width before split', NamedChain.write('widthBefore', TableTestUtils.cGetWidth)),
        Chain.label('Split table cells', NamedChain.read('editor', TableTestUtils.cSplitCells)),
        Chain.label('Store width after split', NamedChain.write('widthAfter', TableTestUtils.cGetWidth)),
        NamedChain.merge(['widthBefore', 'widthAfter'], 'widths'),
        NamedChain.output('widths')
      ]
    ));
  };

  const cAssertWidths = Chain.label(
    'Assert widths before and after unmerge are equal',
    Chain.op((input: any) => {
      Assertions.assertEq('table width should not change', input.widthBefore, input.widthAfter);
    })
  );

  const cAssertWidth = (label, data) => {
    return Chain.label(
      `Assert width of table ${label}`,
      NamedChain.asChain([
        NamedChain.direct(NamedChain.inputName(), Chain.identity, 'editor'),
        NamedChain.direct('editor', cUnmergeCellsMeasureTableWidth(label, data), 'widths'),
        NamedChain.read('widths', cAssertWidths)
      ])
    );
  };

  const cMergeResizeSplitAssertWidth = (label, data) => {
    return Chain.label(
      `Assert width of table ${label}`,
      NamedChain.asChain([
        NamedChain.direct(NamedChain.inputName(), Chain.identity, 'editor'),
        NamedChain.direct('editor', cMergeResizeUnmergeMeasureWidth(label, data), 'widths'),
        NamedChain.read('widths', cAssertWidths)
      ])
    );
  };

  NamedChain.pipeline(Log.chains('TBA', 'Table: Resize table, merge and split cells, assert the table width does not change', [
    NamedChain.write('editor', Editor.cFromSettings({
      plugins: 'table',
      width: 400,
      theme: 'silver',
      base_url: '/project/tinymce/js/tinymce'
    })),

    NamedChain.read('editor', cAssertWidth('which is empty', emptyTable)),
    NamedChain.read('editor', cAssertWidth('with contents in some cells', contentsInSomeCells)),
    NamedChain.read('editor', cAssertWidth('with contents in all cells', contentsInAllCells)),
    NamedChain.read('editor', cAssertWidth('with headings', tableWithHeadings)),
    NamedChain.read('editor', cAssertWidth('with caption', tableWithCaption)),
    NamedChain.read('editor', cAssertWidth('with nested tables', nestedTables)),

    NamedChain.read('editor', cAssertWidth('with an entire row merged and split', selectedRow)),
    NamedChain.read('editor', cAssertWidth('with one selected cell', singleCell)),
    NamedChain.read('editor', cAssertWidth('with whole table merged and split', mergeWholeTable)),
    NamedChain.read('editor', cMergeResizeSplitAssertWidth('resized after merge and then split', mergeResizeSplit)),

    NamedChain.read('editor', Editor.cRemove)
  ]), function () {
    success();
  }, failure, TestLogs.init());
});
开发者ID:tinymce,项目名称:tinymce,代码行数:101,代码来源:UnmergeCellTableResizeTest.ts

示例6: Plugin


//.........这里部分代码省略.........
  const nestedTables = {
    html: '<table style = "width: 100%;">' +
            '<tbody>' +
              '<tr>' +
                '<td>a1' +
                  '<table style = "width: 100%;">' +
                  '<tbody>' +
                    '<tr>' +
                      '<td></td>' +
                      '<td></td>' +
                    '</tr>' +
                    '<tr>' +
                      '<td></td>' +
                      '<td></td>' +
                    '</tr>' +
                  '</tbody>' +
                  '</table>' +
                '</td>' +
                '<td>b1</td>' +
              '</tr>' +
              '<tr>' +
                '<td>a2</td>' +
                '<td>b2</td>' +
              '</tr>' +
            '</tbody>' +
          '</table>'
  };

  const cInsertTable = (label, table) => {
    return Chain.control(
      Chain.mapper((editor: any) => {
        editor.setContent(table);
        const bodyElem = TinyDom.fromDom(editor.getBody());
        const tableElem = UiFinder.findIn(bodyElem, 'table').getOr(bodyElem);
        SelectorFind.descendant(tableElem, 'td,th').each((cell) => {
          editor.selection.select(cell.dom(), true);
          editor.selection.collapse(true);
        });
        return tableElem;
      }),
      Guard.addLogging(`Insert ${label}`)
    );
  };

  const cInsertColumnMeasureWidth = (label, data) => {
    return Log.chain('TBA', 'Insert column before, insert column after, erase column and measure table widths', NamedChain.asChain(
      [
        NamedChain.direct(NamedChain.inputName(), Chain.identity, 'editor'),
        Chain.label('Insert table', NamedChain.direct('editor', cInsertTable(label, data.html), 'element')),
        Chain.label('Drag SE (-100, 0)', NamedChain.read('editor', TableTestUtils.cDragHandle('se', -100, 0))),
        Chain.label('Store width before split', NamedChain.write('widthBefore', TableTestUtils.cGetWidth)),
        Chain.label('Insert column before', NamedChain.read('editor', TableTestUtils.cInsertColumnBefore)),
        Chain.label('Insert column after', NamedChain.read('editor', TableTestUtils.cInsertColumnAfter)),
        Chain.label('Delete column', NamedChain.read('editor', TableTestUtils.cDeleteColumn)),
        Chain.label('Store width after split', NamedChain.write('widthAfter', TableTestUtils.cGetWidth)),
        NamedChain.merge(['widthBefore', 'widthAfter'], 'widths'),
        NamedChain.output('widths')
      ]
    ));
  };

  const cAssertWidths = Chain.label(
    'Assert widths before and after insert column are equal',
    Chain.op((input: any) => {
      Assertions.assertEq('table width should not change', input.widthBefore, input.widthAfter);
    })
  );

  const cAssertWidth = (label, data) => {
    return Chain.label(
      `Assert width of table ${label} after inserting column`,
      NamedChain.asChain([
        NamedChain.direct(NamedChain.inputName(), Chain.identity, 'editor'),
        NamedChain.direct('editor', cInsertColumnMeasureWidth(label, data), 'widths'),
        NamedChain.read('widths', cAssertWidths)
      ])
    );
  };

  NamedChain.pipeline(Log.chains('TBA', 'Table: Insert columns, erase column and assert the table width does not change', [
    NamedChain.write('editor', Editor.cFromSettings({
      plugins: 'table',
      width: 400,
      theme: 'silver',
      base_url: '/project/tinymce/js/tinymce'
    })),

    NamedChain.read('editor', cAssertWidth('which is empty', emptyTable)),
    NamedChain.read('editor', cAssertWidth('with contents in some cells', contentsInSomeCells)),
    NamedChain.read('editor', cAssertWidth('with contents in all cells', contentsInAllCells)),
    NamedChain.read('editor', cAssertWidth('with headings', tableWithHeadings)),
    NamedChain.read('editor', cAssertWidth('with caption', tableWithCaption)),
    NamedChain.read('editor', cAssertWidth('with nested tables', nestedTables)),

    NamedChain.read('editor', Editor.cRemove)
  ]),
   function () {
    success();
  }, failure, TestLogs.init());
});
开发者ID:tinymce,项目名称:tinymce,代码行数:101,代码来源:InsertColumnTableResizeTest.ts

示例7: read

UnitTest.asynctest('browser.tinymce.plugins.image.core.ImageDataTest', (success, failure) => {
  const cSetHtml = (html) => {
    return Chain.control(
      Chain.op(function (elm: Element) {
        Html.set(elm, html);
      }),
      Guard.addLogging('Set html')
    );
  };

  const normalizeCss = (cssText: string) => {
    const css = DOMUtils.DOM.styles.parse(cssText);
    const newCss = {};

    Arr.each(Obj.keys(css).sort(), (key) => {
      newCss[key] = css[key];
    });

    return DOMUtils.DOM.styles.serialize(newCss);
  };

  const cCreate = (data) => {
    return Chain.control(
      Chain.inject(Element.fromDom(create(normalizeCss, data))),
      Guard.addLogging(`Create ${data}`)
    );
  };
  const cReadFromImage = Chain.control(
    Chain.mapper(function (elm: Element) {
      const img = Node.name(elm) === 'img' ? elm : SelectorFind.descendant(elm, 'img').getOrDie('failed to find image');
      return { model: read(normalizeCss, img.dom()), image: img, parent: elm };
    }),
    Guard.addLogging('Read from image')
  );

  const cWriteToImage = Chain.control(
    Chain.op(function (data: any) {
      write(normalizeCss, data.model, data.image.dom());
    }),
    Guard.addLogging('Write to image')
  );

  const cUpdateModel = (props) => {
    return Chain.control(
      Chain.mapper(function (data: any) {
        return { model: Merger.merge(data.model, props), image: data.image, parent: data.parent };
      }),
      Guard.addLogging('Update data model')
    );
  };

  const cAssertModel = (model) => {
    return Chain.control(
      Chain.op(function (data: any) {
        RawAssertions.assertEq('', model, data.model);
      }),
      Guard.addLogging('Assert model')
    );
  };

  const cAssertStructure = (structure) => {
    return Chain.control(
        Chain.op(function (data: any) {
        Assertions.assertStructure('', structure, data.parent);
      }),
      Guard.addLogging('Assert structure')
    );
  };

  const cAssertImage = Chain.control(
    Chain.op(function (data: any) {
      RawAssertions.assertEq('Should be an image', true, isImage(data.image.dom()));
    }),
    Guard.addLogging('Assert image')
  );

  const cAssertFigure = Chain.op(function (data: any) {
    RawAssertions.assertEq('Parent should be a figure', true, isFigure(data.image.dom().parentNode));
  });

  Pipeline.async({}, [
    Log.step('TBA', 'Image: getStyleValue from image data', Step.sync(() => {
      RawAssertions.assertEq('Should not produce any styles', '', getStyleValue(normalizeCss, defaultData()));
      RawAssertions.assertEq('Should produce border width', 'border-width: 1px;', getStyleValue(normalizeCss, Merger.merge(defaultData(), { border: '1' })));
      RawAssertions.assertEq('Should produce style', 'border-style: solid;', getStyleValue(normalizeCss, Merger.merge(defaultData(), { borderStyle: 'solid' })));
      RawAssertions.assertEq('Should produce style & border', 'border-style: solid; border-width: 1px;', getStyleValue(normalizeCss, Merger.merge(defaultData(), { border: '1', borderStyle: 'solid' })));
      RawAssertions.assertEq('Should produce compact border', 'border: 2px dotted red;', getStyleValue(normalizeCss, Merger.merge(defaultData(), { style: 'border: 1px solid red', border: '2', borderStyle: 'dotted' })));
    })),
    Log.chainsAsStep('TBA', 'Image: Create image from data', [
      cCreate({
        src: 'some.gif',
        alt: 'alt',
        title: 'title',
        width: '100',
        height: '200',
        class: 'class',
        style: 'border: 1px solid red',
        caption: false,
        hspace: '2',
        vspace: '3',
//.........这里部分代码省略.........
开发者ID:tinymce,项目名称:tinymce,代码行数:101,代码来源:ImageDataTest.ts

示例8: Theme

UnitTest.asynctest('tinymce.plugins.paste.browser.PlainTextPaste', (success, failure) => {
  Theme();
  PastePlugin();

  const cCreateEditorFromSettings = function (settings, html?) {
    return Chain.control(
      McEditor.cFromSettings(Merger.merge(settings, {
        base_url: '/project/tinymce/js/tinymce',
        indent: false
      })),
      Guard.addLogging(`Create editor from ${settings}`)
    );
  };

  const cRemoveEditor = function () {
    return Chain.control(
      McEditor.cRemove,
      Guard.addLogging('Remove editor')
    );
  };

  const cClearEditor = function () {
    return Chain.control(
      Chain.async(function (editor: any, next, die) {
        editor.setContent('');
        next(editor);
      }),
      Guard.addLogging('Clear editor')
    );
  };

  const cFireFakePasteEvent = function (data) {
    return Chain.control(
      Chain.async(function (editor: any, next, die) {
        editor.fire('paste', { clipboardData: MockDataTransfer.create(data) });
        next(editor);
      }),
      Guard.addLogging(`Fire fake paste event ${data}`)
    );
  };

  const cAssertEditorContent = function (label, expected) {
    return Chain.control(
      Chain.async(function (editor: any, next, die) {
        Assertions.assertHtml(label || 'Asserting editors content', expected, editor.getContent());
        next(editor);
      }),
      Guard.addLogging(`Assert editor content ${expected}`)
    );
  };

  const cAssertClipboardPaste = function (expected, data) {
    const chains = [];

    Obj.each(data, function (data, label) {
      chains.push(
        cFireFakePasteEvent(data),
        Chain.control(
          cAssertEditorContent(label, expected),
          Guard.tryUntil('Wait for paste to succeed.', 100, 1000)
        ),
        cClearEditor()
      );
    });

    return Chain.control(
      Chain.fromChains(chains),
      Guard.addLogging(`Assert clipboard paste ${expected}`)
    );
  };

  const srcText = 'one\r\ntwo\r\n\r\nthree\r\n\r\n\r\nfour\r\n\r\n\r\n\r\n.';

  const pasteData = {
    Firefox: {
      'text/plain': srcText,
      'text/html': 'one<br>two<br><br>three<br><br><br>four<br><br><br><br>.'
    },
    Chrome: {
      'text/plain': srcText,
      'text/html': '<div>one</div><div>two</div><div><br></div><div>three</div><div><br></div><div><br></div><div>four</div><div><br></div><div><br></div><div><br></div><div>.'
    },
    Edge: {
      'text/plain': srcText,
      'text/html': '<div>one<br>two</div><div>three</div><div><br>four</div><div><br></div><div>.</div>'
    },
    IE: {
      'text/plain': srcText,
      'text/html': '<p>one<br>two</p><p>three</p><p><br>four</p><p><br></p><p>.</p>'
    }
  };

  const expectedWithRootBlock = '<p>one<br />two</p><p>three</p><p><br />four</p><p>&nbsp;</p><p>.</p>';
  const expectedWithRootBlockAndAttrs = '<p class="attr">one<br />two</p><p class="attr">three</p><p class="attr"><br />four</p><p class="attr">&nbsp;</p><p class="attr">.</p>';
  const expectedWithoutRootBlock = 'one<br />two<br /><br />three<br /><br /><br />four<br /><br /><br /><br />.';

  Pipeline.async({}, [
    Chain.asStep({}, Log.chains('TBA', 'Paste: Assert forced_root_block <p></p> is added to the pasted data', [
      cCreateEditorFromSettings({
        plugins: 'paste',
//.........这里部分代码省略.........
开发者ID:tinymce,项目名称:tinymce,代码行数:101,代码来源:PlainTextPasteTest.ts


注:本文中的@ephox/agar.Log.chains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。