2016-06-17 13:27:14 +08:00
|
|
|
import { acceptance } from "helpers/qunit-helpers";
|
|
|
|
|
2016-06-17 16:30:55 +08:00
|
|
|
acceptance('Details Button', { loggedIn: true });
|
2016-06-17 13:27:14 +08:00
|
|
|
|
|
|
|
function findTextarea() {
|
|
|
|
return find(".d-editor-input")[0];
|
|
|
|
}
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
test('details button', (assert) => {
|
2016-06-17 13:27:14 +08:00
|
|
|
visit("/");
|
|
|
|
|
|
|
|
click('#create-topic');
|
|
|
|
click('button.options');
|
|
|
|
click('.popup-menu .fa-caret-right');
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(
|
2016-06-17 13:27:14 +08:00
|
|
|
find(".d-editor-input").val(),
|
|
|
|
`[details=${I18n.t("composer.details_title")}]${I18n.t("composer.details_text")}[/details]`,
|
|
|
|
'it should contain the right output'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('.d-editor-input', "This is my title");
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const textarea = findTextarea();
|
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = textarea.value.length;
|
|
|
|
});
|
|
|
|
|
|
|
|
click('button.options');
|
|
|
|
click('.popup-menu .fa-caret-right');
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(
|
2016-06-17 13:27:14 +08:00
|
|
|
find(".d-editor-input").val(),
|
2016-06-20 08:43:12 +08:00
|
|
|
`[details=${I18n.t("composer.details_title")}]This is my title[/details]`,
|
2016-12-20 00:19:10 +08:00
|
|
|
'it should contain the right selected output'
|
2016-06-17 13:27:14 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
const textarea = findTextarea();
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(textarea.selectionStart, 17, 'it should start highlighting at the right position');
|
|
|
|
assert.equal(textarea.selectionEnd, 33, 'it should end highlighting at the right position');
|
2016-06-17 13:27:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('.d-editor-input', "Before some text in between After");
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const textarea = findTextarea();
|
|
|
|
textarea.selectionStart = 7;
|
|
|
|
textarea.selectionEnd = 28;
|
|
|
|
});
|
|
|
|
|
|
|
|
click('button.options');
|
|
|
|
click('.popup-menu .fa-caret-right');
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(
|
2016-06-17 13:27:14 +08:00
|
|
|
find(".d-editor-input").val(),
|
2016-06-20 08:43:12 +08:00
|
|
|
`Before [details=${I18n.t("composer.details_title")}]some text in between[/details] After`,
|
2016-06-17 13:27:14 +08:00
|
|
|
'it should contain the right output'
|
|
|
|
);
|
|
|
|
|
|
|
|
const textarea = findTextarea();
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(textarea.selectionStart, 24, 'it should start highlighting at the right position');
|
|
|
|
assert.equal(textarea.selectionEnd, 44, 'it should end highlighting at the right position');
|
2016-06-17 13:27:14 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
fillIn('.d-editor-input', "Before\nsome text in between\nAfter");
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const textarea = findTextarea();
|
|
|
|
textarea.selectionStart = 7;
|
|
|
|
textarea.selectionEnd = 28;
|
|
|
|
});
|
|
|
|
|
|
|
|
click('button.options');
|
|
|
|
click('.popup-menu .fa-caret-right');
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(
|
2016-06-17 13:27:14 +08:00
|
|
|
find(".d-editor-input").val(),
|
2016-06-20 08:43:12 +08:00
|
|
|
`Before\n[details=${I18n.t("composer.details_title")}]some text in between[/details]\nAfter`,
|
2016-06-17 13:27:14 +08:00
|
|
|
'it should contain the right output'
|
|
|
|
);
|
|
|
|
|
|
|
|
const textarea = findTextarea();
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(textarea.selectionStart, 24, 'it should start highlighting at the right position');
|
|
|
|
assert.equal(textarea.selectionEnd, 44, 'it should end highlighting at the right position');
|
2016-06-17 13:27:14 +08:00
|
|
|
});
|
|
|
|
});
|