Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-21 17:00:29 +01:00
REFACTOR: Improve test for category chooser when there is a create_topic_wizard customfield
Dieser Commit ist enthalten in:
Ursprung
0eb6fb1ae0
Commit
3d104406fd
1 geänderte Dateien mit 64 neuen und 3 gelöschten Zeilen
|
@ -3,19 +3,80 @@ import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
|||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||
import { test } from "qunit";
|
||||
|
||||
acceptance("CategoryChooser", function (needs) {
|
||||
acceptance("Category Chooser Initializer", function (needs) {
|
||||
needs.user();
|
||||
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("does not display category with custom_wizard_hide_from_composer set to 't'", async function (assert) {
|
||||
test("does not display category with create_topic_wizard custom field", 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,
|
||||
3,
|
||||
"Correct number of categories are displayed"
|
||||
);
|
||||
const categoryNames = ["General", "Category 1", "Category 2"];
|
||||
|
||||
assert.ok(categoryChooser.rowByIndex(4).name() !== "Custom Categories");
|
||||
categoryNames.forEach((categoryName) => {
|
||||
assert.ok(
|
||||
categories.some(
|
||||
(category) => category.getAttribute("data-name") === categoryName
|
||||
),
|
||||
`Category '${categoryName}' is displayed`
|
||||
);
|
||||
});
|
||||
|
||||
const categoryNameWithCustomField = "Category with custom field";
|
||||
assert.notOk(
|
||||
categories.some(
|
||||
(category) =>
|
||||
category.getAttribute("data-name") === categoryNameWithCustomField
|
||||
),
|
||||
`Category '${categoryNameWithCustomField}' is not displayed`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Laden …
In neuem Issue referenzieren