Skip to content

Commit

Permalink
test(add-card): Test that adding a card to a blank post is allowed (#104
Browse files Browse the repository at this point in the history
)

Fixes #86
  • Loading branch information
bantic authored Aug 31, 2016
1 parent 52b3d52 commit 7cf04f7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
10 changes: 10 additions & 0 deletions tests/helpers/create-mobiledoc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { MOBILEDOC_VERSION } from 'mobiledoc-kit/renderers/mobiledoc';

export function blankMobiledoc() {
return {
version: MOBILEDOC_VERSION,
markups: [],
atoms: [],
cards: [],
sections: []
};
}

export function simpleMobileDoc(text) {
return {
version: MOBILEDOC_VERSION,
Expand Down
30 changes: 27 additions & 3 deletions tests/integration/components/mobiledoc-editor/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
WILL_CREATE_EDITOR_ACTION, DID_CREATE_EDITOR_ACTION
} from 'ember-mobiledoc-editor/components/mobiledoc-editor/component';
import {
simpleMobileDoc, linkMobileDoc, mobiledocWithCard
simpleMobileDoc, blankMobiledoc, linkMobileDoc, mobiledocWithCard
} from '../../../helpers/create-mobiledoc';

let { Component } = Ember;
Expand Down Expand Up @@ -468,7 +468,7 @@ test('it adds a card and removes an active blank section', function(assert) {

assert.equal(this.$('.mobiledoc-editor p').length, 1, 'blank section exists');
assert.equal(this.$('#demo-card').length, 0, 'no card section exists');
editor.selectRange(new MobiledocKit.Range(editor.post.headPosition()));
editor.selectRange(editor.post.headPosition());
this.$('button#add-card').click();

assert.equal(this.$('.mobiledoc-editor p').length, 0, 'no blank section');
Expand All @@ -491,7 +491,7 @@ test('it adds a card and focuses the cursor at the end of the card', function(as
{{/mobiledoc-editor}}
`);

return selectRangeWithEditor(editor, new MobiledocKit.Range(editor.post.tailPosition())).then(() => {
return selectRangeWithEditor(editor, editor.post.tailPosition()).then(() => {
assert.ok(editor && !editor.range.isBlank, 'range is not blank');
this.$('button#add-card').click();
assert.equal(this.$('#demo-card').length, 1, 'card section exists');
Expand All @@ -508,6 +508,30 @@ test('it adds a card and focuses the cursor at the end of the card', function(as
});
});

// See https://github.com/bustlelabs/ember-mobiledoc-editor/issues/86
test('can add a card to a blank post', function(assert) {
assert.expect(3);

let card = this.registerCardComponent('demo-card', hbs`<div id="demo-card">DEMO CARD</div>`);
this.set('cards', [card]);
let editor;
this.on('didCreateEditor', (_editor) => editor = _editor);
this.set('mobiledoc', blankMobiledoc());
this.render(hbs`
{{#mobiledoc-editor did-create-editor=(action 'didCreateEditor') mobiledoc=mobiledoc cards=cards as |editor|}}
{{/mobiledoc-editor}}
`);

let editorEl = this.$('.mobiledoc-editor__editor')[0];
return selectRange(editorEl, 0, editorEl, 0).then(() => {
assert.ok(editor.hasCursor(), 'precond - editor has cursor');
assert.ok(!this.$('#demo-card').length, 'precond - no card inserted');
return Ember.run(() => editor.insertCard('demo-card'));
}).then(() => {
assert.ok(this.$('#demo-card').length, 'inserts card');
});
});

test('it has `addCardInEditMode` action to add card in edit mode', function(assert) {
assert.expect(2);
this.registry.register('template:components/demo-card',
Expand Down

0 comments on commit 7cf04f7

Please sign in to comment.