Skip to content

Commit

Permalink
Change test to ensure editor reference is maintained
Browse files Browse the repository at this point in the history
Counting `willRender` calls of the component in the yielded block
doesn't test exactly what we want -- it's possible to rerender the
yielded block multiple times without recreating the editor.
  • Loading branch information
bantic committed Jan 11, 2016
1 parent cd1d8b0 commit 640a8fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
],
"dependencies": {
"broccoli-funnel": "^0.2.8",
"mobiledoc-kit": "^0.7.3",
"mobiledoc-kit": "^0.8.0-beta.2",
"ember-cli-babel": "^5.1.3",
"ember-cli-htmlbars": "^1.0.0",
"ember-wormhole": "^0.3.4"
},
"ember-addon": {
"configPath": "tests/dummy/config"
}
}
}
13 changes: 8 additions & 5 deletions tests/integration/components/mobiledoc-editor/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,19 @@ test('it boots mobiledoc editor with mobiledoc', function(assert) {
);
});

test('it does not update the editor when the same mobiledoc is set', function(assert) {
test('it does not create a new editor when the same mobiledoc is set', function(assert) {
assert.expect(2);
let mobiledoc = simpleMobileDoc('Howdy');
let editor;
let createdEditors = 0;
let editors = [];

this.set('mobiledoc', mobiledoc);
this.register('component:gather-editor', Ember.Component.extend({
didRender() {
createdEditors++;
// Will be rendered 2x: once initially, again after `|editor|` hash
// changes. Save each editor reference into `editors` for later comparison
editor = this.get('editor');
editors.push(editor);
}
}));
this.render(hbs`
Expand All @@ -86,13 +88,14 @@ test('it does not update the editor when the same mobiledoc is set', function(as
{{/mobiledoc-editor}}
`);

assert.equal(createdEditors, 1, 'initial editor created');
assert.equal(editors.length, 1, 'initial editor created');

editor.run((postEditor) => {
postEditor.insertText(editor.range.tail, 'Friend');
});

assert.equal(createdEditors, 1, 'editor maintained');
assert.ok(editors.length === 2 && editors[0] === editors[1],
'editor is same reference');
});

test('it updates the editor when the mobiledoc changes', function(assert) {
Expand Down

0 comments on commit 640a8fa

Please sign in to comment.