2016-06-17 01:27:14 -04:00
|
|
|
import { acceptance } from "helpers/qunit-helpers";
|
2017-12-22 07:08:12 -05:00
|
|
|
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
|
2016-06-17 01:27:14 -04:00
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
acceptance("Details Button", {
|
2017-12-22 07:08:12 -05:00
|
|
|
loggedIn: true,
|
|
|
|
beforeEach: function() {
|
|
|
|
clearPopupMenuOptionsCallback();
|
|
|
|
}
|
|
|
|
});
|
2016-06-17 01:27:14 -04:00
|
|
|
|
|
|
|
function findTextarea() {
|
|
|
|
return find(".d-editor-input")[0];
|
|
|
|
}
|
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
test("details button", assert => {
|
|
|
|
const popupMenu = selectKit(".toolbar-popup-menu-options");
|
2017-12-22 07:08:12 -05:00
|
|
|
|
2016-06-17 01:27:14 -04:00
|
|
|
visit("/");
|
2018-06-15 12:42:20 -04:00
|
|
|
click("#create-topic");
|
2017-12-22 07:08:12 -05:00
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
popupMenu.expand().selectRowByValue("insertDetails");
|
2016-06-17 01:27:14 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(
|
2016-06-17 01:27:14 -04:00
|
|
|
find(".d-editor-input").val(),
|
2018-06-15 12:42:20 -04:00
|
|
|
`\n[details="${I18n.t("composer.details_title")}"]\n${I18n.t(
|
|
|
|
"composer.details_text"
|
|
|
|
)}\n[/details]\n`,
|
|
|
|
"it should contain the right output"
|
2016-06-17 01:27:14 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
fillIn(".d-editor-input", "This is my title");
|
2016-06-17 01:27:14 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const textarea = findTextarea();
|
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = textarea.value.length;
|
|
|
|
});
|
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
popupMenu.expand().selectRowByValue("insertDetails");
|
2016-06-17 01:27:14 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(
|
2016-06-17 01:27:14 -04:00
|
|
|
find(".d-editor-input").val(),
|
2018-06-15 12:42:20 -04:00
|
|
|
`\n[details="${I18n.t(
|
|
|
|
"composer.details_title"
|
|
|
|
)}"]\nThis is my title\n[/details]\n`,
|
|
|
|
"it should contain the right selected output"
|
2016-06-17 01:27:14 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
const textarea = findTextarea();
|
2018-06-15 12:42:20 -04:00
|
|
|
assert.equal(
|
|
|
|
textarea.selectionStart,
|
|
|
|
21,
|
|
|
|
"it should start highlighting at the right position"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
textarea.selectionEnd,
|
|
|
|
37,
|
|
|
|
"it should end highlighting at the right position"
|
|
|
|
);
|
2016-06-17 01:27:14 -04:00
|
|
|
});
|
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
fillIn(".d-editor-input", "Before some text in between After");
|
2016-06-17 01:27:14 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const textarea = findTextarea();
|
|
|
|
textarea.selectionStart = 7;
|
|
|
|
textarea.selectionEnd = 28;
|
|
|
|
});
|
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
popupMenu.expand().selectRowByValue("insertDetails");
|
2016-06-17 01:27:14 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(
|
2016-06-17 01:27:14 -04:00
|
|
|
find(".d-editor-input").val(),
|
2018-06-15 12:42:20 -04:00
|
|
|
`Before \n[details="${I18n.t(
|
|
|
|
"composer.details_title"
|
|
|
|
)}"]\nsome text in between\n[/details]\n After`,
|
|
|
|
"it should contain the right output"
|
2016-06-17 01:27:14 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
const textarea = findTextarea();
|
2018-06-15 12:42:20 -04:00
|
|
|
assert.equal(
|
|
|
|
textarea.selectionStart,
|
|
|
|
28,
|
|
|
|
"it should start highlighting at the right position"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
textarea.selectionEnd,
|
|
|
|
48,
|
|
|
|
"it should end highlighting at the right position"
|
|
|
|
);
|
2016-06-17 01:27:14 -04:00
|
|
|
});
|
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
fillIn(".d-editor-input", "Before \nsome text in between\n After");
|
2016-06-17 01:27:14 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const textarea = findTextarea();
|
2017-07-11 17:43:33 -04:00
|
|
|
textarea.selectionStart = 8;
|
|
|
|
textarea.selectionEnd = 29;
|
2016-06-17 01:27:14 -04:00
|
|
|
});
|
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
popupMenu.expand().selectRowByValue("insertDetails");
|
2016-06-17 01:27:14 -04:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(
|
2016-06-17 01:27:14 -04:00
|
|
|
find(".d-editor-input").val(),
|
2018-06-15 12:42:20 -04:00
|
|
|
`Before \n\n[details="${I18n.t(
|
|
|
|
"composer.details_title"
|
|
|
|
)}"]\nsome text in between\n[/details]\n\n After`,
|
|
|
|
"it should contain the right output"
|
2016-06-17 01:27:14 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
const textarea = findTextarea();
|
2018-06-15 12:42:20 -04:00
|
|
|
assert.equal(
|
|
|
|
textarea.selectionStart,
|
|
|
|
29,
|
|
|
|
"it should start highlighting at the right position"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
textarea.selectionEnd,
|
|
|
|
49,
|
|
|
|
"it should end highlighting at the right position"
|
|
|
|
);
|
2016-06-17 01:27:14 -04:00
|
|
|
});
|
|
|
|
});
|
2017-11-06 02:03:52 -05:00
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
test("details button surrounds all selected text in a single details block", assert => {
|
|
|
|
const multilineInput = "first line\n\nsecond line\n\nthird line";
|
|
|
|
const popupMenu = selectKit(".toolbar-popup-menu-options");
|
2017-11-06 02:03:52 -05:00
|
|
|
|
|
|
|
visit("/");
|
2018-06-15 12:42:20 -04:00
|
|
|
click("#create-topic");
|
|
|
|
fillIn(".d-editor-input", multilineInput);
|
2017-11-06 02:03:52 -05:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const textarea = findTextarea();
|
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = textarea.value.length;
|
|
|
|
});
|
|
|
|
|
2018-06-15 12:42:20 -04:00
|
|
|
popupMenu.expand().selectRowByValue("insertDetails");
|
2017-11-06 02:03:52 -05:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
find(".d-editor-input").val(),
|
2018-06-15 12:42:20 -04:00
|
|
|
`\n[details="${I18n.t(
|
|
|
|
"composer.details_title"
|
|
|
|
)}"]\n${multilineInput}\n[/details]\n`,
|
|
|
|
"it should contain the right output"
|
2017-11-06 02:03:52 -05:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|