Skip to content

Commit

Permalink
Fix embed-intent
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Aug 3, 2015
1 parent 058155a commit b89d4fe
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/js/utils/element-utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { UNPRINTABLE_CHARACTER } from 'content-kit-editor/renderers/editor-dom';
import { dasherize } from 'content-kit-editor/utils/string-utils';

function createDiv(className) {
Expand Down Expand Up @@ -32,9 +33,11 @@ function getEventTargetMatchingTag(tag, target, container) {
}

function elementContentIsEmpty(element) {
var content = element && element.innerHTML;
if (content) {
return content === '' || content === '<br>';
if (!element.firstChild) {
return true;
} else if (element.childNodes.length === 1 &&
element.firstChild.textContent === UNPRINTABLE_CHARACTER) {
return true;
}
return false;
}
Expand Down
45 changes: 45 additions & 0 deletions tests/acceptance/embed-intent-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Editor } from 'content-kit-editor';
import Helpers from '../test-helpers';
import { MOBILEDOC_VERSION } from 'content-kit-editor/renderers/mobiledoc';

const { module } = QUnit;

let fixture, editor, editorElement;
const mobileDocWith1Section = {
version: MOBILEDOC_VERSION,
sections: [
[],
[
[1, "P", [
[[], 0, "only section"]
]]
]
]
};

module('Acceptance: Embed intent', {
beforeEach() {
fixture = document.getElementById('qunit-fixture');
editorElement = document.createElement('div');
editorElement.setAttribute('id', 'editor');
fixture.appendChild(editorElement);
},

afterEach() {
if (editor) {
editor.destroy();
}
}
});

Helpers.skipInPhantom('typing inserts section', (assert) => {
editor = new Editor(editorElement, {mobiledoc: mobileDocWith1Section});
assert.equal($('#editor p').length, 1, 'has 1 paragraph to start');

Helpers.dom.moveCursorTo(editorElement.childNodes[0].childNodes[0], 12);
Helpers.dom.triggerKeyEvent(editorElement, 'keydown', Helpers.dom.KEY_CODES.ENTER);
Helpers.dom.triggerKeyEvent(editorElement, 'keyup', Helpers.dom.KEY_CODES.ENTER);

assert.ok($('.ck-embed-intent').is(':visible'), 'embed intent appears');
});

0 comments on commit b89d4fe

Please sign in to comment.