2020-10-28 16:36:01 -04:00
|
|
|
import { acceptance, queryAll } from "discourse/tests/helpers/qunit-helpers";
|
2020-09-04 14:01:14 -04:00
|
|
|
import I18n from "I18n";
|
2017-12-22 07:08:12 -05:00
|
|
|
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
|
2019-06-06 04:47:10 -04:00
|
|
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
2016-06-17 01:27:14 -04:00
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
acceptance("Details Button", function (needs) {
|
|
|
|
needs.user();
|
|
|
|
needs.hooks.beforeEach(() => clearPopupMenuOptionsCallback());
|
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
test("details button", async function (assert) {
|
2020-10-20 13:56:52 -04:00
|
|
|
const popupMenu = selectKit(".toolbar-popup-menu-options");
|
|
|
|
|
|
|
|
await visit("/");
|
|
|
|
await click("#create-topic");
|
|
|
|
|
|
|
|
await popupMenu.expand();
|
|
|
|
await popupMenu.selectRowByValue("insertDetails");
|
|
|
|
|
|
|
|
assert.equal(
|
2020-10-28 16:36:01 -04:00
|
|
|
queryAll(".d-editor-input").val(),
|
2020-10-20 13:56:52 -04:00
|
|
|
`\n[details="${I18n.t("composer.details_title")}"]\n${I18n.t(
|
|
|
|
"composer.details_text"
|
|
|
|
)}\n[/details]\n`,
|
|
|
|
"it should contain the right output"
|
|
|
|
);
|
|
|
|
|
|
|
|
await fillIn(".d-editor-input", "This is my title");
|
|
|
|
|
2020-10-28 16:36:01 -04:00
|
|
|
const textarea = queryAll(".d-editor-input")[0];
|
2020-10-20 13:56:52 -04:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = textarea.value.length;
|
|
|
|
|
|
|
|
await popupMenu.expand();
|
|
|
|
await popupMenu.selectRowByValue("insertDetails");
|
|
|
|
|
|
|
|
assert.equal(
|
2020-10-28 16:36:01 -04:00
|
|
|
queryAll(".d-editor-input").val(),
|
2020-10-20 13:56:52 -04:00
|
|
|
`\n[details="${I18n.t(
|
|
|
|
"composer.details_title"
|
|
|
|
)}"]\nThis is my title\n[/details]\n`,
|
|
|
|
"it should contain the right selected output"
|
|
|
|
);
|
|
|
|
|
|
|
|
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"
|
|
|
|
);
|
|
|
|
|
|
|
|
await fillIn(".d-editor-input", "Before some text in between After");
|
|
|
|
|
|
|
|
textarea.selectionStart = 7;
|
|
|
|
textarea.selectionEnd = 28;
|
|
|
|
|
|
|
|
await popupMenu.expand();
|
|
|
|
await popupMenu.selectRowByValue("insertDetails");
|
|
|
|
|
|
|
|
assert.equal(
|
2020-10-28 16:36:01 -04:00
|
|
|
queryAll(".d-editor-input").val(),
|
2020-10-20 13:56:52 -04:00
|
|
|
`Before \n[details="${I18n.t(
|
|
|
|
"composer.details_title"
|
|
|
|
)}"]\nsome text in between\n[/details]\n After`,
|
|
|
|
"it should contain the right output"
|
|
|
|
);
|
|
|
|
|
|
|
|
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"
|
|
|
|
);
|
|
|
|
|
|
|
|
await fillIn(".d-editor-input", "Before \nsome text in between\n After");
|
|
|
|
|
|
|
|
textarea.selectionStart = 8;
|
|
|
|
textarea.selectionEnd = 29;
|
|
|
|
|
|
|
|
await popupMenu.expand();
|
|
|
|
await popupMenu.selectRowByValue("insertDetails");
|
|
|
|
|
|
|
|
assert.equal(
|
2020-10-28 16:36:01 -04:00
|
|
|
queryAll(".d-editor-input").val(),
|
2020-10-20 13:56:52 -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"
|
|
|
|
);
|
|
|
|
|
|
|
|
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"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
test("details button surrounds all selected text in a single details block", async function (assert) {
|
2020-10-20 13:56:52 -04:00
|
|
|
const multilineInput = "first line\n\nsecond line\n\nthird line";
|
|
|
|
const popupMenu = selectKit(".toolbar-popup-menu-options");
|
|
|
|
|
|
|
|
await visit("/");
|
|
|
|
await click("#create-topic");
|
|
|
|
await fillIn(".d-editor-input", multilineInput);
|
|
|
|
|
2020-10-28 16:36:01 -04:00
|
|
|
const textarea = queryAll(".d-editor-input")[0];
|
2020-10-20 13:56:52 -04:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = textarea.value.length;
|
|
|
|
|
|
|
|
await popupMenu.expand();
|
|
|
|
await popupMenu.selectRowByValue("insertDetails");
|
|
|
|
|
|
|
|
assert.equal(
|
2020-10-28 16:36:01 -04:00
|
|
|
queryAll(".d-editor-input").val(),
|
2020-10-20 13:56:52 -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
|
|
|
});
|