Fix more qunit tests

This commit is contained in:
Sérgio Saquetim 2024-10-03 02:10:34 -03:00
parent b3d66daed4
commit bb0439d47d
No known key found for this signature in database
GPG Key ID: B4E3D7F11E793062
3 changed files with 144 additions and 117 deletions

View File

@ -5,10 +5,22 @@ import PostBookmarkManager from "discourse/lib/post-bookmark-manager";
export default class PostMenuBookmarkButton extends Component {
static shouldRender(args) {
return !!args.context.currentUser;
return !!args.post.canBookmark;
}
bookmarkManager = new PostBookmarkManager(getOwner(this), this.args.post);
#bookmarkManager;
get bookmarkManager() {
// lazy instantiate the bookmark manager only if the component is rendered
if (!this.#bookmarkManager) {
this.#bookmarkManager = new PostBookmarkManager(
getOwner(this),
this.args.post
);
}
return this.#bookmarkManager;
}
<template>
{{#if @shouldRender}}

View File

@ -204,8 +204,8 @@ export default class Post extends RestModel {
return fancyTitle(title, this.siteSettings.support_mixed_text_direction);
}
get canEditStaffNotes() {
return !!this.topic.details.can_edit_staff_notes;
get canBookmark() {
return !!this.currentUser;
}
get canDelete() {
@ -221,6 +221,10 @@ export default class Post extends RestModel {
return this.firstPost && !this.deleted && this.topic.details.can_delete;
}
get canEditStaffNotes() {
return !!this.topic.details.can_edit_staff_notes;
}
get canFlag() {
return !this.get("topic.deleted") && !isEmpty(this.get("flagsAvailable"));
}

View File

@ -367,14 +367,9 @@ module(
});
test(`delete topic button - can't delete when topic author without permission`, async function (assert) {
this.post.topic.details.can_delete = false;
this.post.yours = false;
this.set("args", {
canDeleteTopic: false,
showFlagDelete: true,
canFlag: true,
});
this.post.can_delete = false;
this.post.yours = true;
this.post.actionByName.off_topic = { can_act: true };
await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
@ -389,7 +384,9 @@ module(
});
test("recover topic button", async function (assert) {
this.set("args", { canRecoverTopic: true });
this.post.topic.deleted_at = new Date().toISOString();
this.post.topic.details.can_recover = true;
this.set("recoverPost", () => (this.recovered = true));
await render(
@ -402,7 +399,8 @@ module(
});
test(`recover topic button - can't recover`, async function (assert) {
this.set("args", { canRecoverTopic: false });
this.post.topic.deleted_at = new Date().toISOString();
this.post.topic.details.can_recover = false;
await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
@ -411,7 +409,8 @@ module(
});
test("delete post button", async function (assert) {
this.set("args", { canDelete: true, canFlag: true });
this.post.can_delete = true;
this.set("deletePost", () => (this.deletePostCalled = true));
await render(
@ -424,7 +423,7 @@ module(
});
test(`delete post button - can't delete`, async function (assert) {
this.set("args", { canDelete: false });
this.post.can_delete = false;
await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
@ -433,11 +432,8 @@ module(
});
test(`delete post button - can't delete, can't flag`, async function (assert) {
this.set("args", {
canDeleteTopic: false,
showFlagDelete: false,
canFlag: false,
});
this.post.can_delete = false;
this.post.actionByName = {};
await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
@ -447,7 +443,9 @@ module(
});
test("recover post button", async function (assert) {
this.set("args", { canRecover: true });
this.post.deleted_at = new Date().toISOString();
this.post.can_recover = true;
this.set("recoverPost", () => (this.recovered = true));
await render(
@ -460,7 +458,8 @@ module(
});
test(`recover post button - can't recover`, async function (assert) {
this.set("args", { canRecover: false });
this.post.deleted_at = new Date().toISOString();
this.post.can_recover = false;
await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
@ -469,7 +468,8 @@ module(
});
test(`flagging`, async function (assert) {
this.set("args", { canFlag: true });
this.post.actionByName.off_topic = { can_act: true };
this.set("showFlags", () => (this.flagsShown = true));
await render(
@ -493,7 +493,7 @@ module(
});
test(`flagging: can't flag when post is hidden`, async function (assert) {
this.set("args", { canFlag: true, hidden: true });
this.post.actionByName.off_topic = { can_act: false };
await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
@ -593,9 +593,7 @@ module(
});
test("expand first post", async function (assert) {
const store = getOwner(this).lookup("service:store");
this.set("args", { expandablePost: true });
this.set("post", store.createRecord("post", { id: 1234 }));
await render(
hbs`
@ -607,10 +605,20 @@ module(
});
test("can't bookmark", async function (assert) {
this.set("args", { canBookmark: false });
this.owner.unregister("service:current-user");
const store = getOwner(this).lookup("service:store");
const topic = store.createRecord("topic", { id: 123 });
this.post = store.createRecord("post", {
id: 1,
post_number: 1,
topic,
like_count: 3,
actions_summary: [{ id: 2, count: 1, hidden: false, can_act: true }],
});
await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);
// await pauseTest();
assert.ok(!exists("button.bookmark"));
assert.ok(!exists("button.bookmarked"));
@ -624,7 +632,8 @@ module(
await render(
hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} @toggleBookmark={{this.toggleBookmark}} />`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}}
@toggleBookmark={{this.toggleBookmark}} />`
);
assert.strictEqual(count(".post-menu-area .bookmark"), 1);
@ -641,7 +650,7 @@ module(
});
test("show admin menu", async function (assert) {
this.set("args", { canManage: true });
this.currentUser.admin = true;
await render(
hbs`
@ -886,7 +895,9 @@ module(
test("replies - multiple replies", async function (assert) {
this.siteSettings.suppress_reply_directly_below = true;
this.set("args", { replyCount: 2, replyDirectlyBelow: true });
this.post.reply_count = 2;
this.set("args", { replyDirectlyBelow: true });
await render(hbs`
<MountWidget @widget="post" @model={{this.post}} @args={{this.args}} />`);