Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-24 18:30:27 +01:00
merge in of main
Dieser Commit ist enthalten in:
Commit
8dc04bda4c
2 geänderte Dateien mit 155 neuen und 8 gelöschten Zeilen
|
@ -87,10 +87,13 @@ export default {
|
||||||
api.modifyClass("component:category-chooser", {
|
api.modifyClass("component:category-chooser", {
|
||||||
categoriesByScope(options = {}) {
|
categoriesByScope(options = {}) {
|
||||||
let categories = this._super(options);
|
let categories = this._super(options);
|
||||||
|
const currentUser = this.currentUser;
|
||||||
return categories.filter((category) => {
|
if (!currentUser?.staff) {
|
||||||
|
categories = categories.filter((category) => {
|
||||||
return !category.custom_fields?.create_topic_wizard;
|
return !category.custom_fields?.create_topic_wizard;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
return categories;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,8 +3,8 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
|
|
||||||
acceptance("Category Chooser Initializer", function (needs) {
|
acceptance("Category Chooser Initializer for regular users", function (needs) {
|
||||||
needs.user();
|
needs.user({ admin: false, moderator: false });
|
||||||
needs.settings({
|
needs.settings({
|
||||||
allow_uncategorized_topics: false,
|
allow_uncategorized_topics: false,
|
||||||
});
|
});
|
||||||
|
@ -45,9 +45,8 @@ acceptance("Category Chooser Initializer", function (needs) {
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
test("does not display category with create_topic_wizard custom field", async function (assert) {
|
test("does not display category with create_topic_wizard for regular users", async function (assert) {
|
||||||
const categoryChooser = selectKit(".category-chooser");
|
const categoryChooser = selectKit(".category-chooser");
|
||||||
|
|
||||||
await visit("/");
|
await visit("/");
|
||||||
await click("#create-topic");
|
await click("#create-topic");
|
||||||
await categoryChooser.expand();
|
await categoryChooser.expand();
|
||||||
|
@ -80,3 +79,148 @@ acceptance("Category Chooser Initializer", function (needs) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
acceptance("Category Chooser Initializer for Admins", function (needs) {
|
||||||
|
needs.user({ admin: true });
|
||||||
|
needs.settings({
|
||||||
|
allow_uncategorized_topics: false,
|
||||||
|
});
|
||||||
|
needs.site({
|
||||||
|
can_tag_topics: true,
|
||||||
|
categories: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: "General",
|
||||||
|
slug: "general",
|
||||||
|
permission: 1,
|
||||||
|
topic_template: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: "Category with custom field",
|
||||||
|
slug: "category-custom-field",
|
||||||
|
permission: 1,
|
||||||
|
topic_template: "",
|
||||||
|
custom_fields: {
|
||||||
|
create_topic_wizard: "21",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
name: "Category 1",
|
||||||
|
slug: "category-1",
|
||||||
|
permission: 1,
|
||||||
|
topic_template: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
name: "Category 2",
|
||||||
|
slug: "category-2",
|
||||||
|
permission: 1,
|
||||||
|
topic_template: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
test("displays all categories", async function (assert) {
|
||||||
|
const categoryChooser = selectKit(".category-chooser");
|
||||||
|
await visit("/");
|
||||||
|
await click("#create-topic");
|
||||||
|
await categoryChooser.expand();
|
||||||
|
let categories = Array.from(
|
||||||
|
document.querySelectorAll(".category-chooser .category-row")
|
||||||
|
).filter((category) => category.getAttribute("data-name")); // Filter elements with a data-name attribute
|
||||||
|
assert.equal(
|
||||||
|
categories.length,
|
||||||
|
4,
|
||||||
|
"Correct number of categories are displayed"
|
||||||
|
);
|
||||||
|
const categoryNames = [
|
||||||
|
"General",
|
||||||
|
"Category 1",
|
||||||
|
"Category 2",
|
||||||
|
"Category with custom field",
|
||||||
|
];
|
||||||
|
|
||||||
|
categoryNames.forEach((categoryName) => {
|
||||||
|
assert.ok(
|
||||||
|
categories.some(
|
||||||
|
(category) => category.getAttribute("data-name") === categoryName
|
||||||
|
),
|
||||||
|
`Category '${categoryName}' is displayed`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
acceptance("Category Chooser Initializer for Staff", function (needs) {
|
||||||
|
needs.user({ staff: true });
|
||||||
|
needs.settings({
|
||||||
|
allow_uncategorized_topics: false,
|
||||||
|
});
|
||||||
|
needs.site({
|
||||||
|
can_tag_topics: true,
|
||||||
|
categories: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: "General",
|
||||||
|
slug: "general",
|
||||||
|
permission: 1,
|
||||||
|
topic_template: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: "Category with custom field",
|
||||||
|
slug: "category-custom-field",
|
||||||
|
permission: 1,
|
||||||
|
topic_template: "",
|
||||||
|
custom_fields: {
|
||||||
|
create_topic_wizard: "21",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
name: "Category 1",
|
||||||
|
slug: "category-1",
|
||||||
|
permission: 1,
|
||||||
|
topic_template: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
name: "Category 2",
|
||||||
|
slug: "category-2",
|
||||||
|
permission: 1,
|
||||||
|
topic_template: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
test("displays all categories", async function (assert) {
|
||||||
|
const categoryChooser = selectKit(".category-chooser");
|
||||||
|
await visit("/");
|
||||||
|
await click("#create-topic");
|
||||||
|
await categoryChooser.expand();
|
||||||
|
let categories = Array.from(
|
||||||
|
document.querySelectorAll(".category-chooser .category-row")
|
||||||
|
).filter((category) => category.getAttribute("data-name")); // Filter elements with a data-name attribute
|
||||||
|
assert.equal(
|
||||||
|
categories.length,
|
||||||
|
4,
|
||||||
|
"Correct number of categories are displayed"
|
||||||
|
);
|
||||||
|
const categoryNames = [
|
||||||
|
"General",
|
||||||
|
"Category 1",
|
||||||
|
"Category 2",
|
||||||
|
"Category with custom field",
|
||||||
|
];
|
||||||
|
|
||||||
|
categoryNames.forEach((categoryName) => {
|
||||||
|
assert.ok(
|
||||||
|
categories.some(
|
||||||
|
(category) => category.getAttribute("data-name") === categoryName
|
||||||
|
),
|
||||||
|
`Category '${categoryName}' is displayed`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Laden …
In neuem Issue referenzieren