2017-05-29 21:50:03 +03:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {blur, find, render} from '@ember/test-helpers';
|
2016-11-24 01:50:57 +03:00
|
|
|
import {describe, it} from 'mocha';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {expect} from 'chai';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {setupRenderingTest} from 'ember-mocha';
|
2016-06-18 14:44:23 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('Integration: Component: gh-trim-focus-input', function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
setupRenderingTest();
|
2016-06-18 14:44:23 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('trims value on focusOut', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('text', 'some random stuff ');
|
2019-01-02 12:58:55 +03:00
|
|
|
await render(hbs`{{gh-trim-focus-input value=(readonly text) input=(action (mut text) value="target.value")}}`);
|
2018-02-28 14:44:03 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await blur('input');
|
2018-02-28 14:44:03 +03:00
|
|
|
|
|
|
|
expect(this.get('text')).to.equal('some random stuff');
|
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('trims value on focusOut before calling custom focus-out', async function () {
|
2018-02-28 14:44:03 +03:00
|
|
|
this.set('text', 'some random stuff ');
|
|
|
|
this.set('customFocusOut', function (value) {
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('.gh-input').value, 'input value').to.equal('some random stuff');
|
2018-02-28 14:44:03 +03:00
|
|
|
expect(value, 'value').to.equal('some random stuff');
|
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await render(hbs`{{gh-trim-focus-input
|
2018-02-28 14:44:03 +03:00
|
|
|
value=(readonly text)
|
|
|
|
input=(action (mut text) value="target.value")
|
|
|
|
focus-out=(action customFocusOut)
|
|
|
|
}}`);
|
2016-06-18 14:44:23 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await blur('input');
|
2016-06-18 14:44:23 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
expect(this.get('text')).to.equal('some random stuff');
|
|
|
|
});
|
2016-06-18 14:44:23 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('does not have the autofocus attribute if not set to focus', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('text', 'some text');
|
2019-01-02 12:58:55 +03:00
|
|
|
await render(hbs`{{gh-trim-focus-input value=(readonly text) shouldFocus=false}}`);
|
|
|
|
expect(find('input').autofocus).to.not.be.ok;
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('has the autofocus attribute if set to focus', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('text', 'some text');
|
2019-01-02 12:58:55 +03:00
|
|
|
await render(hbs`{{gh-trim-focus-input value=(readonly text) shouldFocus=true}}`);
|
|
|
|
expect(find('input').autofocus).to.be.ok;
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
2016-07-22 16:36:50 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('handles undefined values', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('text', undefined);
|
2019-01-02 12:58:55 +03:00
|
|
|
await render(hbs`{{gh-trim-focus-input value=(readonly text) shouldFocus=true}}`);
|
|
|
|
expect(find('input').autofocus).to.be.ok;
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('handles non-string values', async function () {
|
2016-11-24 01:50:57 +03:00
|
|
|
this.set('text', 10);
|
2019-01-02 12:58:55 +03:00
|
|
|
await render(hbs`{{gh-trim-focus-input value=(readonly text) shouldFocus=true}}`);
|
|
|
|
expect(find('input').value).to.equal('10');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|