mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 00:11:49 +03:00
aa229973ec
closes https://github.com/TryGhost/Ghost/issues/9386 - remove usage of `{{one-way-checkbox}}` in favour of direct HTML+handlebars - add `{{gh-text-input}}` that inherits from Ember's built-in `TextInput` component along with our custom `TextInput` mixin - swap all uses of `{{gh-input}}` for `{{gh-text-input}} - remove `{{gh-input}}` component - update `{{gh-textarea}}` to inherit from Ember's `TextArea` component instead of `OneWayTextarea` and update all component uses accordingly - update `{{gh-trim-focus-input}}` to inherit from `{{gh-text-input}}` and update all component uses accordingly - standardize on using the `focus-out` action naming rather than `focusOut` for all text inputs, this is because the text input components (especially `{{gh-trim-focus-input}}`) have their own `focusOut` handler which gets overridden if consumers supply their own `focusOut` attr - drop `ember-one-way-controls` package - add `ember-one-way-select` package
67 lines
2.4 KiB
JavaScript
67 lines
2.4 KiB
JavaScript
import hbs from 'htmlbars-inline-precompile';
|
|
import {describe, it} from 'mocha';
|
|
import {expect} from 'chai';
|
|
import {run} from '@ember/runloop';
|
|
import {setupComponentTest} from 'ember-mocha';
|
|
|
|
describe('Integration: Component: gh-trim-focus-input', function () {
|
|
setupComponentTest('gh-trim-focus-input', {
|
|
integration: true
|
|
});
|
|
|
|
it('trims value on focusOut', function () {
|
|
this.set('text', 'some random stuff ');
|
|
this.render(hbs`{{gh-trim-focus-input value=(readonly text) input=(action (mut text) value="target.value")}}`);
|
|
|
|
run(() => {
|
|
this.$('.gh-input').trigger('focusout');
|
|
});
|
|
|
|
expect(this.get('text')).to.equal('some random stuff');
|
|
});
|
|
|
|
it('trims value on focusOut before calling custom focus-out', function () {
|
|
this.set('text', 'some random stuff ');
|
|
this.set('customFocusOut', function (value) {
|
|
expect(this.$('.gh-input').val(), 'input value').to.equal('some random stuff');
|
|
expect(value, 'value').to.equal('some random stuff');
|
|
});
|
|
|
|
this.render(hbs`{{gh-trim-focus-input
|
|
value=(readonly text)
|
|
input=(action (mut text) value="target.value")
|
|
focus-out=(action customFocusOut)
|
|
}}`);
|
|
|
|
run(() => {
|
|
this.$('.gh-input').trigger('focusout');
|
|
});
|
|
|
|
expect(this.get('text')).to.equal('some random stuff');
|
|
});
|
|
|
|
it('does not have the autofocus attribute if not set to focus', function () {
|
|
this.set('text', 'some text');
|
|
this.render(hbs`{{gh-trim-focus-input value=(readonly text) shouldFocus=false}}`);
|
|
expect(this.$('.gh-input').attr('autofocus')).to.not.be.ok;
|
|
});
|
|
|
|
it('has the autofocus attribute if set to focus', function () {
|
|
this.set('text', 'some text');
|
|
this.render(hbs`{{gh-trim-focus-input value=(readonly text) shouldFocus=true}}`);
|
|
expect(this.$('.gh-input').attr('autofocus')).to.be.ok;
|
|
});
|
|
|
|
it('handles undefined values', function () {
|
|
this.set('text', undefined);
|
|
this.render(hbs`{{gh-trim-focus-input value=(readonly text) shouldFocus=true}}`);
|
|
expect(this.$('.gh-input').attr('autofocus')).to.be.ok;
|
|
});
|
|
|
|
it('handles non-string values', function () {
|
|
this.set('text', 10);
|
|
this.render(hbs`{{gh-trim-focus-input value=(readonly text) shouldFocus=true}}`);
|
|
expect(this.$('.gh-input').val()).to.equal('10');
|
|
});
|
|
});
|