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 ');
|
2023-01-04 12:39:32 +03:00
|
|
|
this.set('onInput', (event) => {
|
|
|
|
this.set('text', event.target.value);
|
|
|
|
});
|
|
|
|
await render(hbs`
|
|
|
|
{{!-- template-lint-disable no-passed-in-event-handlers --}}
|
|
|
|
<GhTrimFocusInput
|
|
|
|
@value={{readonly this.text}}
|
|
|
|
@input={{this.onInput}}
|
|
|
|
/>
|
|
|
|
`);
|
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
|
|
|
|
2022-01-21 22:25:47 +03:00
|
|
|
expect(this.text).to.equal('some random stuff');
|
2018-02-28 14:44:03 +03:00
|
|
|
});
|
|
|
|
|
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 ');
|
2023-01-04 12:39:32 +03:00
|
|
|
this.set('onInput', (event) => {
|
|
|
|
this.set('text', event.target.value);
|
|
|
|
});
|
2018-02-28 14:44:03 +03:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2023-01-04 12:39:32 +03:00
|
|
|
await render(hbs`
|
|
|
|
{{!-- template-lint-disable no-passed-in-event-handlers --}}
|
|
|
|
<GhTrimFocusInput
|
|
|
|
@value={{readonly this.text}}
|
|
|
|
@input={{this.onInput}}
|
|
|
|
@focus-out={{this.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
|
|
|
|
2022-01-21 22:25:47 +03:00
|
|
|
expect(this.text).to.equal('some random stuff');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
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');
|
2023-01-04 12:39:32 +03:00
|
|
|
await render(hbs`<GhTrimFocusInput @value={{readonly this.text}} @shouldFocus={{false}} />`);
|
2019-01-02 12:58:55 +03:00
|
|
|
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');
|
2023-01-04 12:39:32 +03:00
|
|
|
await render(hbs`<GhTrimFocusInput @value={{readonly this.text}} @shouldFocus={{true}} />`);
|
2019-01-02 12:58:55 +03:00
|
|
|
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);
|
2023-01-04 12:39:32 +03:00
|
|
|
await render(hbs`<GhTrimFocusInput @value={{readonly this.text}} @shouldFocus={{true}} />`);
|
2019-01-02 12:58:55 +03:00
|
|
|
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);
|
2023-01-04 12:39:32 +03:00
|
|
|
await render(hbs`<GhTrimFocusInput @value={{readonly this.text}} @shouldFocus={{true}} />`);
|
2019-01-02 12:58:55 +03:00
|
|
|
expect(find('input').value).to.equal('10');
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|