Skip to content

Commit 192dcb6

Browse files
committed
Make text selection test asynchronous 🔥
This gives the SelectionChangeObserver an opportunity to fire
1 parent 2e2d60a commit 192dcb6

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

tests/acceptance/editor-selections-test.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Editor } from 'mobiledoc-kit';
2+
import { clearSelection } from 'mobiledoc-kit/utils/selection-utils';
23
import Helpers from '../test-helpers';
34
import { MOBILEDOC_VERSION } from 'mobiledoc-kit/renderers/mobiledoc/0-2';
45

@@ -166,6 +167,8 @@ test('selecting text across markers and deleting joins markers', (assert) => {
166167
});
167168

168169
test('select text and apply markup multiple times', (assert) => {
170+
const done = assert.async();
171+
169172
editor = new Editor({mobiledoc: mobileDocWith2Sections});
170173
editor.render(editorElement);
171174

@@ -174,15 +177,22 @@ test('select text and apply markup multiple times', (assert) => {
174177

175178
editor.run(postEditor => postEditor.toggleMarkup('strong'));
176179

177-
Helpers.dom.selectText(editor ,'fir', editorElement);
178-
editor.run(postEditor => postEditor.toggleMarkup('strong'));
179-
Helpers.dom.triggerEvent(document, 'mouseup');
180+
setTimeout(() => {
181+
Helpers.dom.selectText(editor ,'fir', editorElement);
182+
editor.run(postEditor => postEditor.toggleMarkup('strong'));
183+
clearSelection();
184+
Helpers.dom.triggerEvent(document, 'mouseup');
180185

181-
editor.run(postEditor => postEditor.toggleMarkup('strong'));
186+
setTimeout(() => {
187+
editor.run(postEditor => postEditor.toggleMarkup('strong'));
188+
189+
assert.hasElement('p:contains(first section)', 'correct first section');
190+
assert.hasElement('strong:contains(fir)', 'strong "fir"');
191+
assert.hasElement('strong:contains(t sect)', 'strong "t sect"');
182192

183-
assert.hasElement('p:contains(first section)', 'correct first section');
184-
assert.hasElement('strong:contains(fir)', 'strong "fir"');
185-
assert.hasElement('strong:contains(t sect)', 'strong "t sect"');
193+
done();
194+
}, 10);
195+
}, 10);
186196
});
187197

188198
test('selecting text across markers deletes intermediary markers', (assert) => {

0 commit comments

Comments
 (0)