2020-05-14 22:04:08 +08:00
|
|
|
import I18n from "I18n";
|
2016-11-09 02:40:35 +08:00
|
|
|
import componentTest from "helpers/component-test";
|
2013-12-20 02:29:15 +08:00
|
|
|
|
2016-11-09 02:40:35 +08:00
|
|
|
moduleForComponent("text-field", { integration: true });
|
|
|
|
|
|
|
|
componentTest("renders correctly with no properties set", {
|
|
|
|
template: `{{text-field}}`,
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
assert.ok(find("input[type=text]").length);
|
2016-11-09 02:40:35 +08:00
|
|
|
}
|
2013-12-20 02:29:15 +08:00
|
|
|
});
|
|
|
|
|
2016-11-09 02:40:35 +08:00
|
|
|
componentTest("support a placeholder", {
|
|
|
|
template: `{{text-field placeholderKey="placeholder.i18n.key"}}`,
|
2013-12-20 02:29:15 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
beforeEach() {
|
2016-11-09 02:40:35 +08:00
|
|
|
sandbox.stub(I18n, "t").returnsArg(0);
|
|
|
|
},
|
2013-12-20 02:29:15 +08:00
|
|
|
|
2016-11-09 02:40:35 +08:00
|
|
|
test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
assert.ok(find("input[type=text]").length);
|
|
|
|
assert.equal(find("input").prop("placeholder"), "placeholder.i18n.key");
|
2016-11-09 02:40:35 +08:00
|
|
|
}
|
2013-12-20 02:29:15 +08:00
|
|
|
});
|
2018-01-30 09:42:19 +08:00
|
|
|
|
|
|
|
componentTest("sets the dir attribute to ltr for Hebrew text", {
|
|
|
|
template: `{{text-field value='זהו שם עברי עם מקום עברי'}}`,
|
|
|
|
beforeEach() {
|
|
|
|
this.siteSettings.support_mixed_text_direction = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
assert.equal(find("input").attr("dir"), "rtl");
|
2018-01-30 09:42:19 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
componentTest("sets the dir attribute to ltr for English text", {
|
|
|
|
template: `{{text-field value='This is a ltr title'}}`,
|
|
|
|
beforeEach() {
|
|
|
|
this.siteSettings.support_mixed_text_direction = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 23:04:55 +08:00
|
|
|
assert.equal(find("input").attr("dir"), "ltr");
|
2018-01-30 09:42:19 +08:00
|
|
|
}
|
|
|
|
});
|
2020-04-07 23:41:21 +08:00
|
|
|
|
|
|
|
componentTest("supports onChange", {
|
|
|
|
template: `{{text-field class="tf-test" value=value onChange=changed}}`,
|
|
|
|
beforeEach() {
|
|
|
|
this.called = false;
|
|
|
|
this.newValue = null;
|
|
|
|
this.set("value", "hello");
|
|
|
|
this.set("changed", v => {
|
|
|
|
this.newValue = v;
|
|
|
|
this.called = true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
async test(assert) {
|
|
|
|
await fillIn(".tf-test", "hello");
|
|
|
|
assert.ok(!this.called);
|
|
|
|
await fillIn(".tf-test", "new text");
|
|
|
|
assert.ok(this.called);
|
|
|
|
assert.equal(this.newValue, "new text");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
componentTest("supports onChangeImmediate", {
|
|
|
|
template: `{{text-field class="tf-test" value=value onChangeImmediate=changed}}`,
|
|
|
|
beforeEach() {
|
|
|
|
this.called = false;
|
|
|
|
this.newValue = null;
|
|
|
|
this.set("value", "old");
|
|
|
|
this.set("changed", v => {
|
|
|
|
this.newValue = v;
|
|
|
|
this.called = true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
async test(assert) {
|
|
|
|
await fillIn(".tf-test", "old");
|
|
|
|
assert.ok(!this.called);
|
|
|
|
await fillIn(".tf-test", "no longer old");
|
|
|
|
assert.ok(this.called);
|
|
|
|
assert.equal(this.newValue, "no longer old");
|
|
|
|
}
|
|
|
|
});
|