Skip to content

Commit

Permalink
Merge pull request #242 from mixonic/ie-edge
Browse files Browse the repository at this point in the history
IE Edge fixes
  • Loading branch information
mixonic committed Nov 19, 2015
2 parents 2d1b59f + 49bc53d commit d4105e8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
65 changes: 36 additions & 29 deletions tests/acceptance/editor-key-commands-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Editor } from 'mobiledoc-kit';
import { MODIFIERS } from 'mobiledoc-kit/utils/key';
import Helpers from '../test-helpers';
import { detectIE } from '../helpers/browsers';

const { module, test } = Helpers;

Expand Down Expand Up @@ -37,36 +38,42 @@ function testStatefulCommand({modifier, key, command, markupName}) {
`text wrapped in ${markupName}`);
});

test(`${command} applies ${markupName} to next entered text`, (assert) => {
let initialText = 'something';
const mobiledoc = Helpers.mobiledoc.build(
({post, markupSection, marker}) => post([
markupSection('p', [marker(initialText)])
]));

editor = new Editor({mobiledoc});
editor.render(editorElement);

assert.hasNoElement(`#editor ${markupName}`, `precond - no ${markupName} text`);
Helpers.dom.moveCursorTo(
editor.post.sections.head.markers.head.renderNode.element,
initialText.length);
Helpers.dom.triggerKeyCommand(editor, key, modifier);
Helpers.dom.insertText(editor, 'z');

let changedMobiledoc = editor.serialize();
let expectedMobiledoc = Helpers.mobiledoc.build(
({post, markupSection, marker, markup: buildMarkup}) => {
let markup = buildMarkup(markupName);
return post([
markupSection('p', [
marker(initialText),
marker('z', [markup])
])
]);
if (!detectIE()) {
// FIXME: IE does not respect the current typing styles (such as an
// `execCommand('bold', false, null)`) when calling the `insertText`
// command. Skip these tests in IE until we can implement non-parsing
// text entry.
test(`${command} applies ${markupName} to next entered text`, (assert) => {
let initialText = 'something';
const mobiledoc = Helpers.mobiledoc.build(
({post, markupSection, marker}) => post([
markupSection('p', [marker(initialText)])
]));

editor = new Editor({mobiledoc});
editor.render(editorElement);

assert.hasNoElement(`#editor ${markupName}`, `precond - no ${markupName} text`);
Helpers.dom.moveCursorTo(
editor.post.sections.head.markers.head.renderNode.element,
initialText.length);
Helpers.dom.triggerKeyCommand(editor, key, modifier);
Helpers.dom.insertText(editor, 'z');

let changedMobiledoc = editor.serialize();
let expectedMobiledoc = Helpers.mobiledoc.build(
({post, markupSection, marker, markup: buildMarkup}) => {
let markup = buildMarkup(markupName);
return post([
markupSection('p', [
marker(initialText),
marker('z', [markup])
])
]);
});
assert.deepEqual(changedMobiledoc, expectedMobiledoc);
});
assert.deepEqual(changedMobiledoc, expectedMobiledoc);
});
}
}

testStatefulCommand({
Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/editor-sections-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ test('deleting when after deletion there is a trailing space positions cursor at
Helpers.dom.insertText(editor, text);

setTimeout(() => {
assert.equal($('#editor p:eq(0)').text(), `first ${text}`, 'character is placed after space');
assert.equal(editor.post.sections.head.text, `first ${text}`, 'character is placed after space');

done();
});
Expand All @@ -504,7 +504,7 @@ test('deleting when after deletion there is a leading space positions cursor at
Helpers.dom.insertText(editor, text);

setTimeout(() => {
assert.equal($('#editor p:eq(1)').text(), `${text} section`, 'correct text after insertion');
assert.equal(editor.post.sections.tail.text, `${text} section`, 'correct text after insertion');
done();
});
});
Expand Down
8 changes: 4 additions & 4 deletions tests/acceptance/editor-selections-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,12 @@ test('selecting text bounded by space and typing replaces it', (assert) => {
Helpers.dom.selectText('trick', editorElement);
Helpers.dom.insertText(editor, 'X');

assert.hasElement('#editor p:contains(one X pony)',
'new text present');
assert.equal(editor.post.sections.head.text, 'one X pony',
'new text present');

Helpers.dom.insertText(editor, 'Y');
assert.hasElement('#editor p:contains(one XY pony)',
'cursor positioned correctly');
assert.equal(editor.post.sections.head.text, 'one XY pony',
'further new text present');
});

test('selecting all text across sections and hitting enter deletes and moves cursor to empty section', (assert) => {
Expand Down
4 changes: 4 additions & 0 deletions tests/helpers/browsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function detectIE() {
let userAgent = navigator.userAgent;
return userAgent.indexOf("MSIE ") !== -1 || userAgent.indexOf("Trident/") !== -1 || userAgent.indexOf('Edge/') !== -1;
}

0 comments on commit d4105e8

Please sign in to comment.