2023-10-10 13:38:59 -05:00
|
|
|
import { click, fillIn, visit } from "@ember/test-helpers";
|
|
|
|
import { test } from "qunit";
|
2022-07-13 12:29:19 -05:00
|
|
|
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
|
2019-06-06 03:47:10 -05:00
|
|
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
2024-11-19 14:45:18 -06:00
|
|
|
import { i18n } from 'discourse-i18n';
|
2016-06-17 00:27:14 -05:00
|
|
|
|
2020-10-20 12:56:52 -05:00
|
|
|
acceptance("Details Button", function (needs) {
|
|
|
|
needs.user();
|
|
|
|
|
2020-10-30 11:37:32 -05:00
|
|
|
test("details button", async function (assert) {
|
2020-10-20 12:56:52 -05:00
|
|
|
const popupMenu = selectKit(".toolbar-popup-menu-options");
|
|
|
|
|
|
|
|
await visit("/");
|
|
|
|
await click("#create-topic");
|
2022-11-07 17:17:43 -06:00
|
|
|
const categoryChooser = selectKit(".category-chooser");
|
|
|
|
await categoryChooser.expand();
|
|
|
|
await categoryChooser.selectRowByValue(2);
|
2020-10-20 12:56:52 -05:00
|
|
|
|
|
|
|
await popupMenu.expand();
|
2024-11-19 14:45:18 -06:00
|
|
|
await popupMenu.selectRowByName(i18n("details.title"));
|
2020-10-20 12:56:52 -05:00
|
|
|
|
2021-11-08 03:26:28 -06:00
|
|
|
assert.strictEqual(
|
2022-07-13 12:29:19 -05:00
|
|
|
query(".d-editor-input").value,
|
2024-11-19 14:45:18 -06:00
|
|
|
`\n[details="${i18n("composer.details_title")}"]\n${i18n(
|
2020-10-20 12:56:52 -05:00
|
|
|
"composer.details_text"
|
|
|
|
)}\n[/details]\n`,
|
|
|
|
"it should contain the right output"
|
|
|
|
);
|
|
|
|
|
|
|
|
await fillIn(".d-editor-input", "This is my title");
|
|
|
|
|
2021-06-08 10:54:12 -05:00
|
|
|
const textarea = query(".d-editor-input");
|
2020-10-20 12:56:52 -05:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = textarea.value.length;
|
|
|
|
|
|
|
|
await popupMenu.expand();
|
2024-11-19 14:45:18 -06:00
|
|
|
await popupMenu.selectRowByName(i18n("details.title"));
|
2020-10-20 12:56:52 -05:00
|
|
|
|
2021-11-08 03:26:28 -06:00
|
|
|
assert.strictEqual(
|
2022-07-13 12:29:19 -05:00
|
|
|
query(".d-editor-input").value,
|
2024-11-19 14:45:18 -06:00
|
|
|
`\n[details="${i18n(
|
2020-10-20 12:56:52 -05:00
|
|
|
"composer.details_title"
|
|
|
|
)}"]\nThis is my title\n[/details]\n`,
|
|
|
|
"it should contain the right selected output"
|
|
|
|
);
|
|
|
|
|
2021-11-08 03:26:28 -06:00
|
|
|
assert.strictEqual(
|
2020-10-20 12:56:52 -05:00
|
|
|
textarea.selectionStart,
|
|
|
|
21,
|
|
|
|
"it should start highlighting at the right position"
|
|
|
|
);
|
2021-11-08 03:26:28 -06:00
|
|
|
assert.strictEqual(
|
2020-10-20 12:56:52 -05:00
|
|
|
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();
|
2024-11-19 14:45:18 -06:00
|
|
|
await popupMenu.selectRowByName(i18n("details.title"));
|
2020-10-20 12:56:52 -05:00
|
|
|
|
2021-11-08 03:26:28 -06:00
|
|
|
assert.strictEqual(
|
2022-07-13 12:29:19 -05:00
|
|
|
query(".d-editor-input").value,
|
2024-11-19 14:45:18 -06:00
|
|
|
`Before \n[details="${i18n(
|
2020-10-20 12:56:52 -05:00
|
|
|
"composer.details_title"
|
|
|
|
)}"]\nsome text in between\n[/details]\n After`,
|
|
|
|
"it should contain the right output"
|
|
|
|
);
|
|
|
|
|
2021-11-08 03:26:28 -06:00
|
|
|
assert.strictEqual(
|
2020-10-20 12:56:52 -05:00
|
|
|
textarea.selectionStart,
|
|
|
|
28,
|
|
|
|
"it should start highlighting at the right position"
|
|
|
|
);
|
2021-11-08 03:26:28 -06:00
|
|
|
assert.strictEqual(
|
2020-10-20 12:56:52 -05:00
|
|
|
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();
|
2024-11-19 14:45:18 -06:00
|
|
|
await popupMenu.selectRowByName(i18n("details.title"));
|
2020-10-20 12:56:52 -05:00
|
|
|
|
2021-11-08 03:26:28 -06:00
|
|
|
assert.strictEqual(
|
2022-07-13 12:29:19 -05:00
|
|
|
query(".d-editor-input").value,
|
2024-11-19 14:45:18 -06:00
|
|
|
`Before \n\n[details="${i18n(
|
2020-10-20 12:56:52 -05:00
|
|
|
"composer.details_title"
|
|
|
|
)}"]\nsome text in between\n[/details]\n\n After`,
|
|
|
|
"it should contain the right output"
|
|
|
|
);
|
|
|
|
|
2021-11-08 03:26:28 -06:00
|
|
|
assert.strictEqual(
|
2020-10-20 12:56:52 -05:00
|
|
|
textarea.selectionStart,
|
|
|
|
29,
|
|
|
|
"it should start highlighting at the right position"
|
|
|
|
);
|
2021-11-08 03:26:28 -06:00
|
|
|
assert.strictEqual(
|
2020-10-20 12:56:52 -05:00
|
|
|
textarea.selectionEnd,
|
|
|
|
49,
|
|
|
|
"it should end highlighting at the right position"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-10-30 11:37:32 -05:00
|
|
|
test("details button surrounds all selected text in a single details block", async function (assert) {
|
2020-10-20 12:56:52 -05:00
|
|
|
const multilineInput = "first line\n\nsecond line\n\nthird line";
|
|
|
|
const popupMenu = selectKit(".toolbar-popup-menu-options");
|
|
|
|
|
|
|
|
await visit("/");
|
|
|
|
await click("#create-topic");
|
2022-11-07 17:17:43 -06:00
|
|
|
const categoryChooser = selectKit(".category-chooser");
|
|
|
|
await categoryChooser.expand();
|
|
|
|
await categoryChooser.selectRowByValue(2);
|
2020-10-20 12:56:52 -05:00
|
|
|
await fillIn(".d-editor-input", multilineInput);
|
|
|
|
|
2021-06-08 10:54:12 -05:00
|
|
|
const textarea = query(".d-editor-input");
|
2020-10-20 12:56:52 -05:00
|
|
|
textarea.selectionStart = 0;
|
|
|
|
textarea.selectionEnd = textarea.value.length;
|
|
|
|
|
|
|
|
await popupMenu.expand();
|
2024-11-19 14:45:18 -06:00
|
|
|
await popupMenu.selectRowByName(i18n("details.title"));
|
2020-10-20 12:56:52 -05:00
|
|
|
|
2021-11-08 03:26:28 -06:00
|
|
|
assert.strictEqual(
|
2022-07-13 12:29:19 -05:00
|
|
|
query(".d-editor-input").value,
|
2024-11-19 14:45:18 -06:00
|
|
|
`\n[details="${i18n(
|
2020-10-20 12:56:52 -05:00
|
|
|
"composer.details_title"
|
|
|
|
)}"]\n${multilineInput}\n[/details]\n`,
|
|
|
|
"it should contain the right output"
|
|
|
|
);
|
|
|
|
});
|
2017-11-06 01:03:52 -06:00
|
|
|
});
|