From 2a3e9a0fb06dd5de7ab246e6a32c1f659097e59b Mon Sep 17 00:00:00 2001 From: Cory Forsyth Date: Thu, 1 Sep 2016 11:20:56 -0400 Subject: [PATCH] test(atoms): test that atoms do not rerender when section changes (#105) This was fixed in mobiledoc v0.10.8: https://github.com/bustlelabs/mobiledoc-kit/releases/tag/v0.10.8 Fixes #90 --- .../mobiledoc-editor/component-test.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/integration/components/mobiledoc-editor/component-test.js b/tests/integration/components/mobiledoc-editor/component-test.js index abad9ee..6220772 100644 --- a/tests/integration/components/mobiledoc-editor/component-test.js +++ b/tests/integration/components/mobiledoc-editor/component-test.js @@ -951,3 +951,46 @@ test('calls `unknownAtomHandler` when it renders an unknown atom', function(asse {{/mobiledoc-editor}} `); }); + +// See https://github.com/bustlelabs/ember-mobiledoc-editor/issues/90 +test('does not rerender atoms when updating text in section', function(assert) { + let renderCount = 0; + this.registerAtomComponent('ember-atom', hbs`I AM AN ATOM`, Component.extend({ + tagName: 'span', + didRender() { + renderCount++; + } + })); + this.set('atoms', [createComponentAtom('ember-atom')]); + this.set('mobiledoc', { + version: MOBILEDOC_VERSION, + atoms: [ + ['ember-atom', 'value', {}] + ], + markups: [], + cards: [], + sections: [ + [1, 'P', [ + [1, [], 0, 0]] + ] + ] + }); + + let editor; + this.on('didCreateEditor', (_editor) => editor = _editor); + + this.render(hbs` + {{#mobiledoc-editor mobiledoc=mobiledoc + atoms=atoms + did-create-editor=(action 'didCreateEditor')as |editor|}} + {{/mobiledoc-editor}} + `); + + assert.equal(renderCount, 1, 'precond - initially renders atom'); + + return selectRangeWithEditor(editor, editor.post.tailPosition()).then(() => { + Ember.run(() => editor.insertText('abc')); + }).then(() => { + assert.equal(renderCount, 1, 'still only 1 render of the atom'); + }); +});