DEV: Merge category and tag hashtags code paths (#10216)
Category and tag hashtags used to be handled differently even though most of the code was very similar. This design was the root cause of multiple issues related to hashtags. This commit reduces the number of requests (just one and debounced better), removes the use of CSS classes which marked resolved hashtags, simplifies a lot of the code as there is a single source of truth and previous race condition fixes are now useless. It also includes a very minor security fix which let unauthorized users to guess hidden tags.
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
import { acceptance } from "helpers/qunit-helpers";
|
||||
|
||||
acceptance("Category hashtag", { loggedIn: true });
|
||||
|
||||
QUnit.test("category hashtag is cooked properly", async assert => {
|
||||
await visit("/t/internationalization-localization/280");
|
||||
await click("#topic-footer-buttons .btn.create");
|
||||
|
||||
await fillIn(".d-editor-input", "this is a category hashtag #bug");
|
||||
|
||||
// TODO: Test that the autocomplete shows
|
||||
assert.equal(
|
||||
find(".d-editor-preview:visible")
|
||||
.html()
|
||||
.trim(),
|
||||
'<p>this is a category hashtag <a href="/c/bugs" class="hashtag" data-type="category">#<span>bug</span></a></p>'
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import { acceptance } from "helpers/qunit-helpers";
|
||||
|
||||
acceptance("Category and Tag Hashtags", {
|
||||
loggedIn: true,
|
||||
settings: { tagging_enabled: true },
|
||||
pretend(server, helper) {
|
||||
server.get("/hashtags", () => {
|
||||
return helper.response({
|
||||
categories: { bug: "/c/bugs" },
|
||||
tags: {
|
||||
monkey: "/tag/monkey",
|
||||
bug: "/tag/bug"
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test("hashtags are cooked properly", async assert => {
|
||||
await visit("/t/internationalization-localization/280");
|
||||
await click("#topic-footer-buttons .btn.create");
|
||||
|
||||
await fillIn(
|
||||
".d-editor-input",
|
||||
`this is a category hashtag #bug
|
||||
|
||||
this is a tag hashtag #monkey
|
||||
|
||||
category vs tag: #bug vs #bug::tag`
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
find(".d-editor-preview:visible")
|
||||
.html()
|
||||
.trim(),
|
||||
`<p>this is a category hashtag <a href="/c/bugs" class="hashtag">#<span>bug</span></a></p>
|
||||
<p>this is a tag hashtag <a href="/tag/monkey" class="hashtag">#<span>monkey</span></a></p>
|
||||
<p>category vs tag: <a href="/c/bugs" class="hashtag">#<span>bug</span></a> vs <a href="/tag/bug" class="hashtag">#<span>bug</span></a></p>`
|
||||
);
|
||||
});
|
||||
@@ -1,45 +0,0 @@
|
||||
import { acceptance } from "helpers/qunit-helpers";
|
||||
|
||||
acceptance("Tag Hashtag", {
|
||||
loggedIn: true,
|
||||
settings: { tagging_enabled: true },
|
||||
pretend(server, helper) {
|
||||
server.get("/tags/check", () => {
|
||||
return helper.response({
|
||||
valid: [
|
||||
{ value: "monkey", url: "/tag/monkey" },
|
||||
{ value: "bug", url: "/tag/bug" }
|
||||
]
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test("tag is cooked properly", async assert => {
|
||||
await visit("/t/internationalization-localization/280");
|
||||
await click("#topic-footer-buttons .btn.create");
|
||||
|
||||
await fillIn(".d-editor-input", "this is a tag hashtag #monkey");
|
||||
assert.equal(
|
||||
find(".d-editor-preview:visible")
|
||||
.html()
|
||||
.trim(),
|
||||
'<p>this is a tag hashtag <a href="/tag/monkey" class="hashtag">#<span>monkey</span></a></p>'
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"tags and categories with same name are cooked properly",
|
||||
async assert => {
|
||||
await visit("/t/internationalization-localization/280");
|
||||
await click("#topic-footer-buttons .btn.create");
|
||||
|
||||
await fillIn(".d-editor-input", "#bug vs #bug::tag");
|
||||
assert.equal(
|
||||
find(".d-editor-preview:visible")
|
||||
.html()
|
||||
.trim(),
|
||||
'<p><a href="/c/bugs" class="hashtag" data-type="category">#<span>bug</span></a> vs <a href="/tag/bug" class="hashtag" data-type="tag">#<span>bug</span></a></p>'
|
||||
);
|
||||
}
|
||||
);
|
||||
@@ -300,10 +300,6 @@ export function applyDefaultHandlers(pretender) {
|
||||
return response({ post_reply_histories: [{ id: 1234, cooked: "wat" }] });
|
||||
});
|
||||
|
||||
pretender.get("/category_hashtags/check", () => {
|
||||
return response({ valid: [{ slug: "bug", url: "/c/bugs" }] });
|
||||
});
|
||||
|
||||
pretender.get("/categories_and_latest", () =>
|
||||
response(fixturesByUrl["/categories_and_latest.json"])
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user