discourse-category-experts/test/javascripts/acceptance/category-experts-post-test.js
Jarek Radosz d06ad1ae73
DEV: Update linting (#225)
* DEV: Update linting

* fixup?

* more cleanup

* fix
2026-03-13 12:30:57 +00:00

126 lines
4.4 KiB
JavaScript

import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { cloneJSON } from "discourse/lib/object";
import topicFixtures from "discourse/tests/fixtures/topic";
import userFixtures from "discourse/tests/fixtures/user-fixtures";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
const groupName = "some-group";
acceptance(
"Discourse Category Experts - Posts - Auto-approved",
function (needs) {
needs.user();
needs.settings({
enable_category_experts: true,
category_experts_posts_require_approval: false,
});
needs.pretender((server, helper) => {
const topicResponse = cloneJSON(topicFixtures["/t/2480/1.json"]);
topicResponse.post_stream.posts[2].category_expert_approved_group =
groupName;
server.get("/t/2480.json", () => helper.response(topicResponse));
const cardResponse = JSON.parse(
JSON.stringify(userFixtures["/u/charlie/card.json"])
);
cardResponse.user.username = "normal_user";
cardResponse.user.category_expert_endorsements = [];
cardResponse.user.topic_post_count = { 2480: 2 };
server.get("/u/normal_user/card.json", () =>
helper.response(cardResponse)
);
});
test("Posts with category_expert_approved have the correct classes", async function (assert) {
await visit("/t/topic-for-group-moderators/2480");
const articles = [
...document.querySelectorAll(".topic-post article.onscreen-post"),
];
const lastArticle = articles.at(-1);
assert.dom(lastArticle).hasClass("category-expert-post");
assert.dom(lastArticle).hasClass(`category-expert-${groupName}`);
await click(lastArticle.querySelector("button.show-more-actions"));
assert
.dom(".post-controls .unapprove-category-expert-post")
.doesNotExist();
});
test("Filter posts by user works", async function (assert) {
await visit("/t/topic-for-group-moderators/2480");
await click("article#post_2 .trigger-user-card a");
await click(".usercard-controls .btn-default");
assert.dom(".topic-post").exists({ count: 3 });
});
}
);
acceptance(
"Discourse Category Experts - Posts - Need approved",
function (needs) {
needs.user();
needs.settings({
enable_category_experts: true,
category_experts_posts_require_approval: true,
});
needs.pretender((server, helper) => {
const topicResponse = cloneJSON(topicFixtures["/t/2480/1.json"]);
topicResponse.post_stream.posts[1].needs_category_expert_approval = true;
topicResponse.post_stream.posts[1].can_manage_category_expert_posts = true;
topicResponse.post_stream.posts[2].category_expert_approved_group =
groupName;
topicResponse.post_stream.posts[2].can_manage_category_expert_posts = true;
server.get("/t/2480.json", () => helper.response(topicResponse));
server.post("/category-experts/unapprove", () => helper.response({}));
server.post("/category-experts/approve", () =>
helper.response({
group_name: groupName,
})
);
});
test("The unapprove button is present and works for approved posts", async function (assert) {
await visit("/t/topic-for-group-moderators/2480");
const articles = [
...document.querySelectorAll(".topic-post article.onscreen-post"),
];
const lastArticle = articles.at(-1);
assert.dom(lastArticle).hasClass("category-expert-post");
assert.dom(lastArticle).hasClass(`category-expert-${groupName}`);
await click(lastArticle.querySelector("button.show-more-actions"));
await click(".post-controls .unapprove-category-expert-post");
assert.dom(lastArticle).doesNotHaveClass("category-expert-post");
});
test("The approve button is present and works for unapproved posts by category experts", async function (assert) {
await visit("/t/topic-for-group-moderators/2480");
const articles = [
...document.querySelectorAll(".topic-post article.onscreen-post"),
];
const article = articles.at(-2);
assert.dom(article).doesNotHaveClass("category-expert-post");
assert.dom(article).doesNotHaveClass(`category-expert-${groupName}`);
await click(
article.querySelector(".post-controls .approve-category-expert-post")
);
assert.dom(article).hasClass("category-expert-post");
assert.dom(article).hasClass(`category-expert-${groupName}`);
});
}
);