Skip to content

Commit

Permalink
Fix all failing tests on Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Sep 17, 2015
1 parent 243a465 commit e5b4763
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
22 changes: 7 additions & 15 deletions tests/acceptance/editor-sections-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,30 +314,22 @@ test('keystroke of delete when cursor is after only char in only marker of secti
test('keystroke of character in empty section adds character, moves cursor', (assert) => {
editor = new Editor({mobiledoc: mobileDocWithNoCharacter});
editor.render(editorElement);
const getTextNode = () => editor.element.
childNodes[0]. // section
childNodes[0]; // marker

let textNode = getTextNode();
assert.ok(!!textNode, 'precond - gets text node');
Helpers.dom.moveCursorTo(textNode, 0);
assert.hasElement('#editor p br', 'precond - br tag rendered for empty section');
let pNode = $('#editor p')[0];

// Firefox requires that the cursor be placed explicitly for this test to pass
Helpers.dom.moveCursorTo(pNode, 0);

const letter = 'M';
Helpers.dom.insertText(editor, letter);

assert.equal(getTextNode().textContent, letter, 'adds character');
assert.equal(getTextNode().textContent.length, 1);

assert.deepEqual(Helpers.dom.getCursorPosition(),
{node: getTextNode(), offset: 1},
`cursor moves to end of ${letter} text node`);
assert.hasElement(`#editor p:contains(${letter})`, 'adds char');

const otherLetter = 'X';
Helpers.dom.insertText(editor, otherLetter);

assert.equal(getTextNode().textContent, `${letter}${otherLetter}`,
'adds character in the correct spot');
assert.equal(getTextNode().textContent.length, letter.length + otherLetter.length);
assert.hasElement(`#editor p:contains(${letter}${otherLetter})`, 'adds char in correct spot');
});

test('keystroke of delete at start of section joins with previous section', (assert) => {
Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/editor-text-expansions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let editor, editorElement;

function insertText(text, cursorNode) {
if (!cursorNode) {
cursorNode = $('#editor p:eq(0)')[0].firstChild;
cursorNode = $('#editor p:eq(0)')[0];
}
Helpers.dom.moveCursorTo(cursorNode);
Helpers.dom.insertText(editor, text);
Expand Down Expand Up @@ -89,7 +89,7 @@ test('typing "* " inside of a list section does not create a new list section',

assert.hasElement('#editor ul > li', 'precond - has li');

const cursorNode = $('#editor li:eq(0)')[0].firstChild;
const cursorNode = $('#editor li:eq(0)')[0];
insertText('* ', cursorNode);

// note: the actual text is "* ", so only check that the "*" is there,
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/parsers/post-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ test('editor#reparse catches changes to section', (assert) => {
const p = $('#editor p:eq(0)')[0];
p.childNodes[0].textContent = 'the NEW marker';

// In Firefox, changing the text content changes the selection, so re-set it
Helpers.dom.moveCursorTo(p.childNodes[0]);

editor.reparse();

const section = editor.post.sections.head;
Expand All @@ -104,6 +107,9 @@ test('editor#reparse catches changes to list section', (assert) => {
const li = $('#editor li:eq(0)')[0];
li.childNodes[0].textContent = 'the NEW list item';

// In Firefox, changing the text content changes the selection, so re-set it
Helpers.dom.moveCursorTo(li.childNodes[0]);

editor.reparse();

const listItem = editor.post.sections.head.items.head;
Expand Down

0 comments on commit e5b4763

Please sign in to comment.