mirror of
https://github.com/discourse/discourse.git
synced 2025-09-04 08:47:37 +08:00
Refactor code; add tests
This commit is contained in:
parent
42970e758e
commit
41f1e7430c
7 changed files with 89 additions and 11 deletions
|
@ -715,6 +715,26 @@ testCase(`list button with line sequence`, function(assert, textarea) {
|
|||
});
|
||||
});
|
||||
|
||||
componentTest('clicking the toggle-direction button toggles the direction', {
|
||||
template: '{{d-editor value=value}}',
|
||||
beforeEach() {
|
||||
this.siteSettings.support_mixed_text_direction = true;
|
||||
this.siteSettings.default_locale = "en";
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
const textarea = this.$('textarea.d-editor-input');
|
||||
click('button.toggle-direction');
|
||||
andThen(() => {
|
||||
assert.equal(textarea.attr('dir'), 'rtl');
|
||||
});
|
||||
click('button.toggle-direction');
|
||||
andThen(() => {
|
||||
assert.equal(textarea.attr('dir'), 'ltr');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
testCase(`doesn't jump to bottom with long text`, function(assert, textarea) {
|
||||
|
||||
let longText = 'hello world.';
|
||||
|
|
|
@ -22,3 +22,27 @@ componentTest("support a placeholder", {
|
|||
assert.equal(this.$('input').prop('placeholder'), 'placeholder.i18n.key');
|
||||
}
|
||||
});
|
||||
|
||||
componentTest("sets the dir attribute to ltr for Hebrew text", {
|
||||
template: `{{text-field value='זהו שם עברי עם מקום עברי'}}`,
|
||||
beforeEach() {
|
||||
this.siteSettings.support_mixed_text_direction = true;
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
assert.equal(this.$('input').attr('dir'), 'rtl');
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
assert.equal(this.$('input').attr('dir'), 'ltr');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -45,3 +45,28 @@ QUnit.test("allowUncategorized", assert => {
|
|||
assert.blank(categoryBadgeHTML(uncategorized), "it doesn't return HTML for uncategorized by default");
|
||||
assert.present(categoryBadgeHTML(uncategorized, {allowUncategorized: true}), "it returns HTML");
|
||||
});
|
||||
|
||||
QUnit.test("category names are wrapped in dir-spans", assert => {
|
||||
Discourse.SiteSettings.support_mixed_text_direction = true;
|
||||
const store = createStore();
|
||||
const rtlCategory = store.createRecord('category', {
|
||||
name: 'תכנות עם Ruby',
|
||||
id: 123,
|
||||
description_text: 'cool description',
|
||||
color: 'ff0',
|
||||
text_color: 'f00'
|
||||
});
|
||||
|
||||
const ltrCategory = store.createRecord('category', {
|
||||
name: 'Programming in Ruby',
|
||||
id: 234
|
||||
});
|
||||
|
||||
let tag = parseHTML(categoryBadgeHTML(rtlCategory))[0];
|
||||
let dirSpan = tag.children[1].children[0];
|
||||
assert.equal(dirSpan.attributes.dir, 'rtl');
|
||||
|
||||
tag = parseHTML(categoryBadgeHTML(ltrCategory))[0];
|
||||
dirSpan = tag.children[1].children[0];
|
||||
assert.equal(dirSpan.attributes.dir, 'ltr');
|
||||
});
|
||||
|
|
|
@ -98,6 +98,15 @@ QUnit.test('fancyTitle', assert => {
|
|||
"supports emojis");
|
||||
});
|
||||
|
||||
QUnit.test('fancyTitle direction', assert => {
|
||||
const rtlTopic = Topic.create({ fancy_title: "هذا اختبار" });
|
||||
const ltrTopic = Topic.create({ fancy_title: "This is a test"});
|
||||
|
||||
Discourse.SiteSettings.support_mixed_text_direction = true;
|
||||
assert.equal(rtlTopic.get('fancyTitle'), `<span dir="rtl">هذا اختبار</span>`, "sets the dir-span to rtl");
|
||||
assert.equal(ltrTopic.get('fancyTitle'), `<span dir="ltr">This is a test</span>`, "sets the dir-span to ltr");
|
||||
});
|
||||
|
||||
QUnit.test('excerpt', assert => {
|
||||
const topic = Topic.create({ excerpt: "This is a test topic :smile:", pinned: true });
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue