2015-10-15 15:03:26 +03:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {describe, it} from 'mocha';
|
|
|
|
import {expect} from 'chai';
|
2019-02-22 08:16:56 +03:00
|
|
|
import {find, render, settled} from '@ember/test-helpers';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {setupRenderingTest} from 'ember-mocha';
|
2017-04-18 10:20:38 +03:00
|
|
|
|
|
|
|
// NOTE: If the browser window is not focused/visible CodeMirror (or Chrome?) will
|
|
|
|
// take longer to respond to/fire events so it's possible that some of these tests
|
|
|
|
// will take 1-3 seconds
|
2015-10-15 15:03:26 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('Integration: Component: gh-cm-editor', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
setupRenderingTest();
|
2015-10-15 15:03:26 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('handles change event', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('text', '');
|
2015-10-15 15:03:26 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await render(hbs`{{gh-cm-editor text class="gh-input" update=(action (mut text))}}`);
|
2017-04-18 10:20:38 +03:00
|
|
|
// access CodeMirror directly as it doesn't pick up changes to the textarea
|
|
|
|
let cm = find('.gh-input .CodeMirror').CodeMirror;
|
|
|
|
cm.setValue('Testing');
|
2015-10-15 15:03:26 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await settled();
|
|
|
|
|
|
|
|
expect(this.get('text'), 'text value after CM editor change')
|
|
|
|
.to.equal('Testing');
|
2017-04-18 10:20:38 +03:00
|
|
|
});
|
2015-10-15 15:03:26 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('can autofocus', async function () {
|
2017-04-18 10:20:38 +03:00
|
|
|
// CodeMirror's events are triggered outside of anything we can watch for
|
|
|
|
// in the tests so let's run the class check when we know the event has
|
|
|
|
// been fired and timeout if it's not fired as we expect
|
2019-01-02 12:58:55 +03:00
|
|
|
let onFocus = async () => {
|
2017-04-18 10:20:38 +03:00
|
|
|
// wait for runloop to finish so that the new class has been rendered
|
2019-01-02 12:58:55 +03:00
|
|
|
await settled();
|
|
|
|
expect(find('.gh-input').classList.contains('focus'), 'has focused class on first render with autofocus')
|
|
|
|
.to.be.true;
|
2017-04-18 10:20:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
this.set('onFocus', onFocus);
|
|
|
|
this.set('text', '');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await render(hbs`{{gh-cm-editor text class="gh-input" update=(action (mut text)) autofocus=true focus-in=(action onFocus)}}`);
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|