From e38d621e7614b700eedc2ff14ec530f34ea5db7a Mon Sep 17 00:00:00 2001 From: Cory Forsyth Date: Wed, 6 Jul 2016 16:35:03 -0400 Subject: [PATCH] (tests) Use `cursorDidChange` callback in `activeSectionTagNames` tests --- .../mobiledoc-editor/component-test.js | 79 ++++++++++++------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/tests/integration/components/mobiledoc-editor/component-test.js b/tests/integration/components/mobiledoc-editor/component-test.js index ac0f6b0..f2c7452 100644 --- a/tests/integration/components/mobiledoc-editor/component-test.js +++ b/tests/integration/components/mobiledoc-editor/component-test.js @@ -707,8 +707,11 @@ test('calls `unknownCardHandler` when it renders an unknown card', function(asse }); test('#activeSectionTagNames is correct', function(assert) { + assert.expect(2); let done = assert.async(); + let editor; + this.set('mobiledoc', { version: MOBILEDOC_VERSION, markups: [], @@ -719,8 +722,11 @@ test('#activeSectionTagNames is correct', function(assert) { [1, 'blockquote', [[0, [], 0, "blockquote section"]]] ] }); + + this.on('didCreateEditor', _editor => editor = _editor); + this.render(hbs` - {{#mobiledoc-editor mobiledoc=mobiledoc as |editor|}} + {{#mobiledoc-editor mobiledoc=mobiledoc did-create-editor=(action 'didCreateEditor') autofocus=false as |editor|}} {{#if editor.activeSectionTagNames.isBlockquote}}
is block quote
{{/if}} @@ -730,25 +736,35 @@ test('#activeSectionTagNames is correct', function(assert) { {{/mobiledoc-editor}} `); - moveCursorTo(this, 'blockquote:contains(blockquote section)'); - simulateMouseup(); + let cursorChanges = 0; + editor.cursorDidChange(() => { + cursorChanges++; - setTimeout(() => { - assert.ok(this.$('#is-block-quote').length, 'is block quote'); - - moveCursorTo(this, 'p:contains(first paragraph)'); - simulateMouseup(); + if (cursorChanges === 1) { + Ember.run.next(() => { + assert.ok(this.$('#is-block-quote').length, 'is block quote'); + moveCursorTo(this, 'p:contains(first paragraph)'); + simulateMouseup(); + }); + } else if (cursorChanges === 2) { + Ember.run.next(() => { + assert.ok(this.$('#is-p').length, 'is p'); + done(); + }); + } else { + assert.ok(false, 'Invalid number of cursor changes: ' + cursorChanges); + } + }); - setTimeout(() => { - assert.ok(this.$('#is-p').length, 'is p'); - done(); - }, 10); - }, 10); + moveCursorTo(this, 'blockquote:contains(blockquote section)'); + simulateMouseup(); }); test('#activeSectionTagNames is correct when a card is selected', function(assert) { let done = assert.async(); + let editor; + this.set('mobiledoc', { version: MOBILEDOC_VERSION, markups: [], @@ -770,8 +786,10 @@ test('#activeSectionTagNames is correct when a card is selected', function(asser } }]); + this.on('didCreateEditor', _editor => editor = _editor); + this.render(hbs` - {{#mobiledoc-editor cards=cards mobiledoc=mobiledoc autofocus=false as |editor|}} + {{#mobiledoc-editor cards=cards mobiledoc=mobiledoc did-create-editor=(action 'didCreateEditor') autofocus=false as |editor|}} {{#if editor.activeSectionTagNames.isP}}
is p
{{else}} @@ -780,21 +798,28 @@ test('#activeSectionTagNames is correct when a card is selected', function(asser {{/mobiledoc-editor}} `); - moveCursorTo(this, '.mobiledoc-editor p'); - simulateMouseup(); - - setTimeout(() => { - assert.ok(this.$('#is-p').length, 'precond - is p'); - - moveCursorTo(this, '#card-test'); - simulateMouseup(); + let cursorChanges = 0; + editor.cursorDidChange(() => { + cursorChanges++; - setTimeout(() => { - assert.ok(this.$('#not-p').length, 'is not p'); - - done(); - }); + if (cursorChanges === 1) { + Ember.run.next(() => { + assert.ok(this.$('#is-p').length, 'precond - is p'); + moveCursorTo(this, '#card-test'); + simulateMouseup(); + }); + } else if (cursorChanges === 2 ){ + Ember.run.next(() => { + assert.ok(this.$('#not-p').length, 'is not p'); + done(); + }); + } else { + assert.ok(false, 'too many cursor changes: ' + cursorChanges); + } }); + + moveCursorTo(this, '.mobiledoc-editor p'); + simulateMouseup(); }); test('exposes `addAtom` action to add an atom', function(assert) {