diff --git a/tests/acceptance/editor-copy-paste-test.js b/tests/acceptance/editor-copy-paste-test.js index 617f4b9ee..38bdad4b9 100644 --- a/tests/acceptance/editor-copy-paste-test.js +++ b/tests/acceptance/editor-copy-paste-test.js @@ -1,6 +1,7 @@ import { Editor } from 'mobiledoc-kit'; import Helpers from '../test-helpers'; import Range from 'mobiledoc-kit/utils/cursor/range'; +import { supportsStandardClipboardAPI } from '../helpers/browsers'; import { MIME_TEXT_PLAIN, MIME_TEXT_HTML @@ -83,9 +84,14 @@ test('paste plain text with line breaks', (assert) => { Helpers.dom.setCopyData(MIME_TEXT_PLAIN, ['abc', 'def'].join('\n')); Helpers.dom.triggerPasteEvent(editor); - assert.hasElement('#editor p:contains(abcabc)', 'pastes the text'); - assert.hasElement('#editor p:contains(def)', 'second section is pasted'); - assert.equal($('#editor p').length, 2, 'adds a second section'); + if (supportsStandardClipboardAPI()) { + assert.hasElement('#editor p:contains(abcabc)', 'pastes the text'); + assert.hasElement('#editor p:contains(def)', 'second section is pasted'); + assert.equal($('#editor p').length, 2, 'adds a second section'); + } else { + assert.hasElement('#editor p:contains(abcabc\ndef)', 'pastes the text'); + assert.equal($('#editor p').length, 1, 'adds a second section'); + } }); test('paste plain text with list items', (assert) => { @@ -103,8 +109,12 @@ test('paste plain text with list items', (assert) => { Helpers.dom.setCopyData(MIME_TEXT_PLAIN, ['* abc', '* def'].join('\n')); Helpers.dom.triggerPasteEvent(editor); - assert.hasElement('#editor p:contains(abcabc)', 'pastes the text'); - assert.hasElement('#editor ul li:contains(def)', 'list item is pasted'); + if (supportsStandardClipboardAPI()) { + assert.hasElement('#editor p:contains(abcabc)', 'pastes the text'); + assert.hasElement('#editor ul li:contains(def)', 'list item is pasted'); + } else { + assert.hasElement('#editor p:contains(abc* abc\n* def)', 'pastes the text'); + } }); test('can cut and then paste content', (assert) => { @@ -300,10 +310,12 @@ test('copy sets html & text for pasting externally', (assert) => { Helpers.dom.triggerCopyEvent(editor); - let text = Helpers.dom.getCopyData(MIME_TEXT_PLAIN); let html = Helpers.dom.getCopyData(MIME_TEXT_HTML); - assert.equal(text, ["heading", "h2 subheader", "The text" ].join('\n'), - 'gets plain text'); + if (supportsStandardClipboardAPI()) { + let text = Helpers.dom.getCopyData(MIME_TEXT_PLAIN); + assert.equal(text, ["heading", "h2 subheader", "The text" ].join('\n'), + 'gets plain text'); + } assert.ok(html.indexOf("

heading") !== -1, 'html has h1'); assert.ok(html.indexOf("

h2 subheader") !== -1, 'html has h2'); diff --git a/tests/helpers/browsers.js b/tests/helpers/browsers.js index bf06d4aa6..d8a6a5ac8 100644 --- a/tests/helpers/browsers.js +++ b/tests/helpers/browsers.js @@ -7,3 +7,9 @@ export function supportsSelectionExtend() { let selection = window.getSelection(); return !!selection.extend; } + +// See http://caniuse.com/#feat=clipboard +// This rules out the Internet Explorers. +export function supportsStandardClipboardAPI() { + return !window.clipboardData; +} diff --git a/tests/helpers/dom.js b/tests/helpers/dom.js index f345f6ad7..3700d1103 100644 --- a/tests/helpers/dom.js +++ b/tests/helpers/dom.js @@ -4,6 +4,7 @@ import KEY_CODES from 'mobiledoc-kit/utils/keycodes'; import { DIRECTION, MODIFIERS } from 'mobiledoc-kit/utils/key'; import { isTextNode } from 'mobiledoc-kit/utils/dom-utils'; import { merge } from 'mobiledoc-kit/utils/merge'; +import { supportsStandardClipboardAPI } from './browsers'; // walks DOWN the dom from node to childNodes, returning the element // for which `conditionFn(element)` is true @@ -270,11 +271,17 @@ function triggerLeftArrowKey(editor, modifier) { // Allows our fake copy and paste events to communicate with each other. const lastCopyData = {}; function triggerCopyEvent(editor) { - let event = createMockEvent('copy', editor.element, { - clipboardData: { - setData(type, value) { lastCopyData[type] = value; } - } - }); + let eventData = {}; + + if (supportsStandardClipboardAPI()) { + eventData = { + clipboardData: { + setData(type, value) { lastCopyData[type] = value; } + } + }; + } + + let event = createMockEvent('copy', editor.element, eventData); editor.triggerEvent(editor.element, 'copy', event); } @@ -288,20 +295,34 @@ function triggerCutEvent(editor) { } function triggerPasteEvent(editor) { - let event = createMockEvent('copy', editor.element, { - clipboardData: { - getData(type) { return lastCopyData[type]; } - } - }); + let eventData = {}; + + if (supportsStandardClipboardAPI()) { + eventData = { + clipboardData: { + getData(type) { return lastCopyData[type]; } + } + }; + } + + let event = createMockEvent('copy', editor.element, eventData); editor.triggerEvent(editor.element, 'paste', event); } function getCopyData(type) { - return lastCopyData[type]; + if (supportsStandardClipboardAPI()) { + return lastCopyData[type]; + } else { + return window.clipboardData.getData('Text'); + } } function setCopyData(type, value) { - lastCopyData[type] = value; + if (supportsStandardClipboardAPI()) { + lastCopyData[type] = value; + } else { + window.clipboardData.setData('Text', value); + } } function clearCopyData() {