2020-05-14 22:04:08 +08:00
|
|
|
import I18n from "I18n";
|
2020-03-27 23:50:31 +08:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
2019-06-06 16:47:10 +08:00
|
|
|
import selectKit from "helpers/select-kit-helper";
|
2015-04-07 02:14:00 +08:00
|
|
|
import { acceptance } from "helpers/qunit-helpers";
|
2019-03-15 12:44:49 +08:00
|
|
|
import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
|
2018-08-16 20:06:56 +08:00
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
acceptance("Topic", {
|
|
|
|
loggedIn: true,
|
|
|
|
pretend(server, helper) {
|
|
|
|
server.put("/posts/398/wiki", () => {
|
|
|
|
return helper.response({});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2013-06-21 03:02:02 +08:00
|
|
|
|
2019-03-18 14:30:10 +08:00
|
|
|
QUnit.test("Reply as new topic", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click("button.share:eq(0)");
|
|
|
|
await click(".reply-as-new-topic a");
|
|
|
|
|
|
|
|
assert.ok(exists(".d-editor-input"), "the composer input is visible");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
find(".d-editor-input")
|
|
|
|
.val()
|
|
|
|
.trim(),
|
2019-06-26 23:09:52 +08:00
|
|
|
`Continuing the discussion from [Internationalization / localization](${window.location.origin}/t/internationalization-localization/280):`,
|
2019-03-18 14:30:10 +08:00
|
|
|
"it fills composer with the ring string"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
selectKit(".category-chooser")
|
|
|
|
.header()
|
|
|
|
.value(),
|
|
|
|
"2",
|
|
|
|
"it fills category selector with the right category"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test("Reply as new message", async assert => {
|
|
|
|
await visit("/t/pm-for-testing/12");
|
|
|
|
await click("button.share:eq(0)");
|
|
|
|
await click(".reply-as-new-topic a");
|
|
|
|
|
|
|
|
assert.ok(exists(".d-editor-input"), "the composer input is visible");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
find(".d-editor-input")
|
|
|
|
.val()
|
|
|
|
.trim(),
|
2019-06-26 23:09:52 +08:00
|
|
|
`Continuing the discussion from [PM for testing](${window.location.origin}/t/pm-for-testing/12):`,
|
2019-03-18 14:30:10 +08:00
|
|
|
"it fills composer with the ring string"
|
|
|
|
);
|
|
|
|
|
|
|
|
const targets = find(".item span", ".composer-fields");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
$(targets[0]).text(),
|
|
|
|
"someguy",
|
|
|
|
"it fills up the composer with the right user to start the PM to"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
$(targets[1]).text(),
|
|
|
|
"test",
|
|
|
|
"it fills up the composer with the right user to start the PM to"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
$(targets[2]).text(),
|
|
|
|
"Group",
|
|
|
|
"it fills up the composer with the right group to start the PM to"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-02-21 05:27:59 +08:00
|
|
|
QUnit.test("Share Modal", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click(".topic-post:first-child button.share");
|
2019-02-26 21:15:25 +08:00
|
|
|
|
|
|
|
assert.ok(exists("#share-link"), "it shows the share modal");
|
2019-02-21 05:27:59 +08:00
|
|
|
});
|
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
QUnit.test("Showing and hiding the edit controls", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
2015-04-17 01:53:30 +08:00
|
|
|
|
2019-01-22 19:02:02 +08:00
|
|
|
await click("#topic-title .d-icon-pencil-alt");
|
2015-04-17 01:53:30 +08:00
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
assert.ok(exists("#edit-title"), "it shows the editing controls");
|
|
|
|
assert.ok(
|
|
|
|
!exists(".title-wrapper .remove-featured-link"),
|
|
|
|
"link to remove featured link is not shown"
|
|
|
|
);
|
2015-04-17 01:53:30 +08:00
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
await fillIn("#edit-title", "this is the new title");
|
|
|
|
await click("#topic-title .cancel-edit");
|
|
|
|
assert.ok(!exists("#edit-title"), "it hides the editing controls");
|
2013-06-21 03:02:02 +08:00
|
|
|
});
|
2014-09-17 23:18:41 +08:00
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
QUnit.test("Updating the topic title and category", async assert => {
|
2017-12-22 20:08:12 +08:00
|
|
|
const categoryChooser = selectKit(".title-wrapper .category-chooser");
|
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
await visit("/t/internationalization-localization/280");
|
2017-01-25 14:33:16 +08:00
|
|
|
|
2019-01-22 19:02:02 +08:00
|
|
|
await click("#topic-title .d-icon-pencil-alt");
|
2018-07-26 18:16:32 +08:00
|
|
|
await fillIn("#edit-title", "this is the new title");
|
2018-07-30 04:51:32 +08:00
|
|
|
await categoryChooser.expand();
|
|
|
|
await categoryChooser.selectRowByValue(4);
|
2018-07-26 18:16:32 +08:00
|
|
|
await click("#topic-title .submit-edit");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
find("#topic-title .badge-category").text(),
|
|
|
|
"faq",
|
|
|
|
"it displays the new category"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
find(".fancy-title")
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
"this is the new title",
|
|
|
|
"it displays the new title"
|
|
|
|
);
|
|
|
|
});
|
2017-01-25 14:33:16 +08:00
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
QUnit.test("Marking a topic as wiki", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
2017-01-25 14:33:16 +08:00
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
assert.ok(find("a.wiki").length === 0, "it does not show the wiki icon");
|
2017-01-25 14:33:16 +08:00
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
await click(".topic-post:eq(0) button.show-more-actions");
|
|
|
|
await click(".topic-post:eq(0) button.show-post-admin-menu");
|
|
|
|
await click(".btn.wiki");
|
2017-01-25 14:33:16 +08:00
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
assert.ok(find("a.wiki").length === 1, "it shows the wiki icon");
|
2017-01-25 14:33:16 +08:00
|
|
|
});
|
2016-11-30 01:59:42 +08:00
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
QUnit.test("Visit topic routes", async assert => {
|
|
|
|
await visit("/t/12");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
find(".fancy-title")
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
"PM for testing",
|
|
|
|
"it routes to the right topic"
|
|
|
|
);
|
|
|
|
|
|
|
|
await visit("/t/280/20");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
find(".fancy-title")
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
"Internationalization / localization",
|
|
|
|
"it routes to the right topic"
|
|
|
|
);
|
2017-09-29 14:02:58 +08:00
|
|
|
});
|
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
QUnit.test("Updating the topic title with emojis", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
2019-01-22 19:02:02 +08:00
|
|
|
await click("#topic-title .d-icon-pencil-alt");
|
2017-06-05 20:06:23 +08:00
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
await fillIn("#edit-title", "emojis title :bike: :blonde_woman:t6:");
|
2017-06-05 20:06:23 +08:00
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
await click("#topic-title .submit-edit");
|
2017-06-05 20:06:23 +08:00
|
|
|
|
2018-07-26 18:16:32 +08:00
|
|
|
assert.equal(
|
|
|
|
find(".fancy-title")
|
|
|
|
.html()
|
|
|
|
.trim(),
|
2018-08-16 20:06:56 +08:00
|
|
|
`emojis title <img src="/images/emoji/emoji_one/bike.png?v=${v}" title="bike" alt="bike" class="emoji"> <img src="/images/emoji/emoji_one/blonde_woman/6.png?v=${v}" title="blonde_woman:t6" alt="blonde_woman:t6" class="emoji">`,
|
2018-07-26 18:16:32 +08:00
|
|
|
"it displays the new title with emojis"
|
|
|
|
);
|
2017-07-27 04:33:17 +08:00
|
|
|
});
|
2017-11-23 03:53:35 +08:00
|
|
|
|
2019-03-21 16:11:33 +08:00
|
|
|
QUnit.test("Updating the topic title with unicode emojis", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click("#topic-title .d-icon-pencil-alt");
|
|
|
|
|
2019-03-29 05:31:27 +08:00
|
|
|
await fillIn("#edit-title", "emojis title 👨🌾🙏");
|
2019-03-21 16:11:33 +08:00
|
|
|
|
|
|
|
await click("#topic-title .submit-edit");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
find(".fancy-title")
|
|
|
|
.html()
|
|
|
|
.trim(),
|
2019-03-29 05:31:27 +08:00
|
|
|
`emojis title <img src="/images/emoji/emoji_one/man_farmer.png?v=${v}" title="man_farmer" alt="man_farmer" class="emoji"><img src="/images/emoji/emoji_one/pray.png?v=${v}" title="pray" alt="pray" class="emoji">`,
|
2019-03-21 16:11:33 +08:00
|
|
|
"it displays the new title with escaped unicode emojis"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-12-04 00:32:33 +08:00
|
|
|
QUnit.test(
|
|
|
|
"Updating the topic title with unicode emojis without whitespaces",
|
|
|
|
async assert => {
|
|
|
|
Discourse.SiteSettings.enable_inline_emoji_translation = true;
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click("#topic-title .d-icon-pencil-alt");
|
|
|
|
|
|
|
|
await fillIn("#edit-title", "Test🙂Title");
|
|
|
|
|
|
|
|
await click("#topic-title .submit-edit");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
find(".fancy-title")
|
|
|
|
.html()
|
|
|
|
.trim(),
|
|
|
|
`Test<img src="/images/emoji/emoji_one/slightly_smiling_face.png?v=${v}" title="slightly_smiling_face" alt="slightly_smiling_face" class="emoji">Title`,
|
|
|
|
"it displays the new title with escaped unicode emojis"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-02-21 19:35:49 +08:00
|
|
|
QUnit.test("Suggested topics", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
find("#suggested-topics .suggested-topics-title")
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
I18n.t("suggested_topics.title")
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-01-16 03:28:03 +08:00
|
|
|
QUnit.skip("Deleting a topic", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click(".topic-post:eq(0) button.show-more-actions");
|
|
|
|
await click(".widget-button.delete");
|
|
|
|
|
|
|
|
assert.ok(exists(".widget-button.recover"), "it shows the recover button");
|
|
|
|
});
|
|
|
|
|
2017-11-23 03:53:35 +08:00
|
|
|
acceptance("Topic featured links", {
|
|
|
|
loggedIn: true,
|
|
|
|
settings: {
|
|
|
|
topic_featured_link_enabled: true,
|
|
|
|
max_topic_title_length: 80
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-01 17:09:34 +08:00
|
|
|
QUnit.skip("remove featured link", async assert => {
|
2019-07-03 19:45:03 +08:00
|
|
|
await visit("/t/-/299/1");
|
2018-07-26 18:16:32 +08:00
|
|
|
assert.ok(
|
|
|
|
exists(".title-wrapper .topic-featured-link"),
|
|
|
|
"link is shown with topic title"
|
|
|
|
);
|
|
|
|
|
|
|
|
await click(".title-wrapper .edit-topic");
|
|
|
|
assert.ok(
|
|
|
|
exists(".title-wrapper .remove-featured-link"),
|
|
|
|
"link to remove featured link"
|
|
|
|
);
|
2017-11-23 03:53:35 +08:00
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
await click(".title-wrapper .remove-featured-link");
|
|
|
|
await click(".title-wrapper .submit-edit");
|
|
|
|
assert.ok(!exists(".title-wrapper .topic-featured-link"), "link is gone");
|
2017-11-23 03:53:35 +08:00
|
|
|
});
|
2018-07-13 10:54:34 +08:00
|
|
|
|
2019-07-19 23:52:50 +08:00
|
|
|
QUnit.test("Converting to a public topic", async assert => {
|
|
|
|
await visit("/t/test-pm/34");
|
|
|
|
assert.ok(exists(".private_message"));
|
|
|
|
await click(".toggle-admin-menu");
|
|
|
|
await click(".topic-admin-convert button");
|
|
|
|
|
|
|
|
let categoryChooser = selectKit(".convert-to-public-topic .category-chooser");
|
|
|
|
await categoryChooser.expand();
|
|
|
|
await categoryChooser.selectRowByValue(21);
|
|
|
|
|
|
|
|
await click(".convert-to-public-topic .btn-primary");
|
|
|
|
assert.ok(!exists(".private_message"));
|
|
|
|
});
|
|
|
|
|
2018-09-13 02:52:24 +08:00
|
|
|
QUnit.test("Unpinning unlisted topic", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
|
|
|
|
await click(".toggle-admin-menu");
|
|
|
|
await click(".topic-admin-pin .btn");
|
|
|
|
await click(".btn-primary:last");
|
|
|
|
|
|
|
|
await click(".toggle-admin-menu");
|
|
|
|
await click(".topic-admin-visible .btn");
|
|
|
|
|
|
|
|
await click(".toggle-admin-menu");
|
2018-09-17 08:30:36 +08:00
|
|
|
assert.ok(exists(".topic-admin-pin"), "it should show the multi select menu");
|
2018-09-13 02:52:24 +08:00
|
|
|
});
|
|
|
|
|
2018-07-13 10:54:34 +08:00
|
|
|
QUnit.test("selecting posts", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click(".toggle-admin-menu");
|
|
|
|
await click(".topic-admin-multi-select .btn");
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
exists(".selected-posts:not(.hidden)"),
|
|
|
|
"it should show the multi select menu"
|
|
|
|
);
|
|
|
|
|
2018-07-13 11:12:35 +08:00
|
|
|
assert.ok(
|
|
|
|
exists(".select-all"),
|
|
|
|
"it should allow users to select all the posts"
|
|
|
|
);
|
2018-07-13 10:54:34 +08:00
|
|
|
});
|
2018-06-28 14:54:54 +08:00
|
|
|
|
|
|
|
QUnit.test("select below", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click(".toggle-admin-menu");
|
|
|
|
await click(".topic-admin-multi-select .btn");
|
|
|
|
await click("#post_3 .select-below");
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".selected-posts")
|
|
|
|
.html()
|
|
|
|
.includes(I18n.t("topic.multi_select.description", { count: 18 })),
|
|
|
|
"it should select the right number of posts"
|
|
|
|
);
|
|
|
|
|
|
|
|
await click("#post_2 .select-below");
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".selected-posts")
|
|
|
|
.html()
|
|
|
|
.includes(I18n.t("topic.multi_select.description", { count: 19 })),
|
|
|
|
"it should select the right number of posts"
|
|
|
|
);
|
|
|
|
});
|
2019-01-10 18:06:01 +08:00
|
|
|
|
|
|
|
QUnit.test("View Hidden Replies", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click(".gap");
|
|
|
|
|
|
|
|
assert.equal(find(".gap").length, 0, "it hides gap");
|
|
|
|
});
|
2020-01-22 22:10:23 +08:00
|
|
|
|
2020-04-08 22:28:23 +08:00
|
|
|
function selectText(selector) {
|
|
|
|
const range = document.createRange();
|
|
|
|
const node = document.querySelector(selector);
|
|
|
|
range.selectNodeContents(node);
|
2020-01-22 22:10:23 +08:00
|
|
|
|
|
|
|
const selection = window.getSelection();
|
|
|
|
selection.removeAllRanges();
|
|
|
|
selection.addRange(range);
|
2020-04-08 22:28:23 +08:00
|
|
|
}
|
2020-01-22 22:10:23 +08:00
|
|
|
|
2020-04-08 22:28:23 +08:00
|
|
|
QUnit.test("Quoting a quote keeps the original poster name", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
selectText("#post_5 blockquote");
|
2020-01-22 22:10:23 +08:00
|
|
|
await click(".quote-button");
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".d-editor-input")
|
|
|
|
.val()
|
|
|
|
.indexOf('quote="codinghorror said, post:3, topic:280"') !== -1
|
|
|
|
);
|
|
|
|
});
|
2020-02-13 14:26:02 +08:00
|
|
|
|
2020-04-08 22:28:23 +08:00
|
|
|
QUnit.test(
|
|
|
|
"Quoting a quote with the Reply button keeps the original poster name",
|
|
|
|
async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
selectText("#post_5 blockquote");
|
|
|
|
await click(".reply");
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".d-editor-input")
|
|
|
|
.val()
|
|
|
|
.indexOf('quote="codinghorror said, post:3, topic:280"') !== -1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
QUnit.test(
|
|
|
|
"Quoting a quote with replyAsNewTopic keeps the original poster name",
|
|
|
|
async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
selectText("#post_5 blockquote");
|
|
|
|
await keyEvent(document, "keypress", "j".charCodeAt(0));
|
|
|
|
await keyEvent(document, "keypress", "t".charCodeAt(0));
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".d-editor-input")
|
|
|
|
.val()
|
|
|
|
.indexOf('quote="codinghorror said, post:3, topic:280"') !== -1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
QUnit.test(
|
|
|
|
"Quoting by selecting text can mark the quote as full",
|
|
|
|
async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
selectText("#post_5 .cooked");
|
|
|
|
await click(".quote-button");
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".d-editor-input")
|
|
|
|
.val()
|
|
|
|
.indexOf('quote="pekka, post:5, topic:280, full:true"') !== -1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-03-27 23:50:31 +08:00
|
|
|
acceptance("Topic with title decorated", {
|
|
|
|
loggedIn: true,
|
|
|
|
beforeEach() {
|
|
|
|
withPluginApi("0.8.40", api => {
|
|
|
|
api.decorateTopicTitle((topic, node, topicTitleType) => {
|
|
|
|
node.innerText = `${node.innerText}-${topic.id}-${topicTitleType}`;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test("Decorate topic title", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".fancy-title")[0].innerText.endsWith("-280-topic-title"),
|
|
|
|
"it decorates topic title"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
find(".raw-topic-link:nth-child(1)")[0].innerText.endsWith(
|
|
|
|
"-27331-topic-list-item-title"
|
|
|
|
),
|
|
|
|
"it decorates topic list item title"
|
|
|
|
);
|
|
|
|
});
|