DEV: Update tests (#30)

avoid Site singleton, use qunit-dom
This commit is contained in:
Jarek Radosz 2024-05-10 20:03:00 +02:00 committed by GitHub
parent ad64ea25f0
commit cf46a4cc8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 58 additions and 53 deletions

View File

@ -1,82 +1,87 @@
import { getOwner } from "@ember/owner";
import { visit } from "@ember/test-helpers"; import { visit } from "@ember/test-helpers";
import { test } from "qunit"; import { test } from "qunit";
import Site from "discourse/models/site";
import { import {
acceptance, acceptance,
exists,
query,
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
acceptance("Sidebar - Category icons", function (needs) { acceptance("Sidebar - Category icons", function (needs) {
needs.user(); needs.user();
let category1; needs.site({
let category2; categories: [
{
needs.hooks.beforeEach(() => { id: 1,
const categories = Site.current().categories; name: "Category 1",
category1 = categories[0]; slug: "category-1",
category2 = categories[1]; color: "111111",
},
{
id: 2,
name: "Category 2",
slug: "category-2",
color: "000000",
},
],
});
needs.hooks.beforeEach(function () {
settings.category_lock_icon = "wrench"; settings.category_lock_icon = "wrench";
settings.category_icon_list = `${category1.slug},wrench,#FF0000|${category2.slug},question-circle,categoryColor`; settings.category_icon_list = `category-1,wrench,#FF0000|category-2,question-circle,categoryColor`;
}); });
test("Icon for category when `category_icon_list` theme setting has been configured", async function (assert) { test("Icon for category when `category_icon_list` theme setting has been configured", async function (assert) {
category2.color = "000000"; updateCurrentUser({ sidebar_category_ids: [1, 2] });
updateCurrentUser({
sidebar_category_ids: [category1.id, category2.id],
});
await visit("/"); await visit("/");
assert.ok( assert
exists( .dom(
`.sidebar-section-link-wrapper[data-category-id="${category1.id}"] .prefix-icon.d-icon-wrench` `.sidebar-section-link-wrapper[data-category-id="1"] .prefix-icon.d-icon-wrench`
), )
`wrench icon is displayed for ${category1.slug} section link's prefix icon` .exists(
); "wrench icon is displayed for category-1 section link's prefix icon"
);
assert.strictEqual( assert
query( .dom(
`.sidebar-section-link-wrapper[data-category-id="${category1.id}"] .sidebar-section-link-prefix` `.sidebar-section-link-wrapper[data-category-id="1"] .sidebar-section-link-prefix`
).style.color, )
"rgb(255, 0, 0)", .hasStyle(
`${category1.slug} section link's prefix icon has the right color` { color: "rgb(255, 0, 0)" },
); "category-1 section link's prefix icon has the right color"
);
assert.ok( assert
exists( .dom(
`.sidebar-section-link-wrapper[data-category-id="${category2.id}"] .prefix-icon.d-icon-question-circle` `.sidebar-section-link-wrapper[data-category-id="2"] .prefix-icon.d-icon-question-circle`
), )
`question-circle icon is displayed for ${category2.slug} section link's prefix icon` .exists(
); "question-circle icon is displayed for category-2 section link's prefix icon"
);
assert.strictEqual( assert
query( .dom(
`.sidebar-section-link-wrapper[data-category-id="${category2.id}"] .sidebar-section-link-prefix` `.sidebar-section-link-wrapper[data-category-id="2"] .sidebar-section-link-prefix`
).style.color, )
"rgb(0, 0, 0)", .hasStyle(
`${category2.slug} section link's prefix icon has the right color` { color: "rgb(0, 0, 0)" },
); "category-2 section link's prefix icon has the right color"
);
}); });
test("Prefix badge icon for read restricted categories when `category_lock_icon` theme setting is set", async function (assert) { test("Prefix badge icon for read restricted categories when `category_lock_icon` theme setting is set", async function (assert) {
category1.read_restricted = true; const site = getOwner(this).lookup("service:site");
site.categories[0].read_restricted = true;
updateCurrentUser({ updateCurrentUser({ sidebar_category_ids: [1] });
sidebar_category_ids: [category1.id],
});
await visit("/"); await visit("/");
assert.ok( assert
exists( .dom(
`.sidebar-section-link-wrapper[data-category-id="${category1.id}"] .prefix-badge.d-icon-wrench` `.sidebar-section-link-wrapper[data-category-id="1"] .prefix-badge.d-icon-wrench`
), )
"wrench icon is displayed for the section link's prefix badge" .exists("wrench icon is displayed for the section link's prefix badge");
);
}); });
}); });