Skip to content

Commit

Permalink
(tests) Use cursorDidChange callback in activeSectionTagNames tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Jul 6, 2016
1 parent 7f07d44 commit e38d621
Showing 1 changed file with 52 additions and 27 deletions.
79 changes: 52 additions & 27 deletions tests/integration/components/mobiledoc-editor/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand All @@ -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}}
<div id='is-block-quote'>is block quote</div>
{{/if}}
Expand All @@ -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: [],
Expand All @@ -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}}
<div id='is-p'>is p</div>
{{else}}
Expand All @@ -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) {
Expand Down

0 comments on commit e38d621

Please sign in to comment.