Skip to content

Commit

Permalink
Remove active blank section when adding card
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Oct 20, 2015
1 parent 188ac0e commit 32c682a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion addon/components/content-kit-editor/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,16 @@ export default Component.extend({

_addCard(cardName, data, editMode=false) {
let editor = this.get('editor');
let section = editor.activeSection;
editor.run(postEditor => {
let card = editor.builder.createCardSection(cardName, data);
if (editMode) {
editor.editCard(card);
}
postEditor.insertSectionAtEnd(card);
postEditor.insertSectionBefore(editor.post.sections, card, section);
if (section && section.isBlank) {
postEditor.removeSection(section);
}
});
}

Expand Down
23 changes: 23 additions & 0 deletions tests/integration/components/content-kit-editor/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,29 @@ test('it adds a component in display mode to the content-kit editor', function(a
assert.ok(this.$(`#demo-card-editor`).length, 'Card changed to edit mode');
});

test('it adds a card and removes an active blank section', function(assert) {
assert.expect(4);
this.registry.register('template:components/demo-card', hbs`
<div id="demo-card"><button id='edit-card' {{action editCard}}></button></div>
`);
this.set('cards', [
createComponentCard('demo-card')
]);
this.set('mobiledoc', simpleMobileDoc(''));
this.render(hbs`
{{#content-kit-editor mobiledoc=mobiledoc cards=cards as |contentKit|}}
<button id='add-card' {{action contentKit.addCard 'demo-card'}}></button>
{{/content-kit-editor}}
`);

assert.equal(this.$('.content-kit-editor p').length, 1, 'blank section exists');
assert.equal(this.$('#demo-card').length, 0, 'no card section exists');
moveCursorTo(this, '.content-kit-editor p');
this.$('button#add-card').click();
assert.equal(this.$('.content-kit-editor p').length, 0, 'no blank section');
assert.equal(this.$('#demo-card').length, 1, 'card section exists');
});

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 32c682a

Please sign in to comment.