FIX: Add missing string for reviewables in user menu when reviewable post is deleted (#18295)

This commit is contained in:
Osama Sayegh 2022-09-21 02:05:08 +03:00 committed by GitHub
parent ea27079ffa
commit 3d2de7ca03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import ReviewableTypeBase from "discourse/lib/reviewable-types/base";
import { htmlSafe } from "@ember/template";
import I18n from "I18n";
import { emojiUnescape } from "discourse/lib/text";
export default class extends ReviewableTypeBase {
get description() {
@ -10,11 +11,11 @@ export default class extends ReviewableTypeBase {
return htmlSafe(
I18n.t("user_menu.reviewable.post_number_with_topic_title", {
post_number: postNumber,
title,
title: emojiUnescape(title),
})
);
} else {
return I18n.t("user_menu.reviewable.delete_post");
return I18n.t("user_menu.reviewable.deleted_post");
}
}
}

View File

@ -0,0 +1,54 @@
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { createRenderDirector } from "discourse/tests/helpers/reviewable-types-helper";
import { htmlSafe } from "@ember/template";
import { emojiUnescape } from "discourse/lib/text";
import UserMenuReviewable from "discourse/models/user-menu-reviewable";
import I18n from "I18n";
function getReviewable(overrides = {}) {
return UserMenuReviewable.create(
Object.assign(
{
flagger_username: "sayo2",
id: 17,
pending: false,
type: "ReviewableFlaggedPost",
topic_fancy_title: "anything hello world",
post_number: 1,
},
overrides
)
);
}
discourseModule("Unit | Reviewable Items | flagged-post", function () {
test("description", function (assert) {
const reviewable = getReviewable({
topic_fancy_title: "This is safe title <a> :heart:",
});
const director = createRenderDirector(
reviewable,
"ReviewableFlaggedPost",
this.siteSettings
);
assert.deepEqual(
director.description,
htmlSafe(
I18n.t("user_menu.reviewable.post_number_with_topic_title", {
title: `This is safe title <a> ${emojiUnescape(":heart:")}`,
post_number: 1,
})
),
"contains the fancy title without escaping because it's already safe"
);
delete reviewable.topic_fancy_title;
delete reviewable.post_number;
assert.deepEqual(
director.description,
I18n.t("user_menu.reviewable.deleted_post"),
"falls back to generic string when the post/topic is deleted"
);
});
});

View File

@ -2610,6 +2610,7 @@ en:
view_all: "view all review items"
queue: "Queue"
deleted_user: "(deleted user)"
deleted_post: "(deleted post)"
post_number_with_topic_title: "post #%{post_number} - %{title}"
new_post_in_topic: "new post in %{title}"
user_requires_approval: "%{username} requires approval"