Skip to content

Commit 7898653

Browse files
committed
test: use defineProperty to enforce mock theme settings in acceptance test
1 parent b0c0e5d commit 7898653

1 file changed

Lines changed: 48 additions & 13 deletions

File tree

test/javascripts/acceptance/nav-bar-additions-test.js

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,48 @@ import { test } from "qunit";
44

55
acceptance("Custom Top Navigation Links | Topic Counts", function (needs) {
66
needs.user();
7-
needs.settings({
8-
nav_links: [
9-
{
10-
display_name: "New Topics",
11-
title: "new topics",
12-
url: "/new",
7+
8+
let originalSettings;
9+
10+
needs.hooks.beforeEach(() => {
11+
originalSettings = window.settings;
12+
13+
const mockSettings = {
14+
nav_links: [
15+
{
16+
display_name: "New Topics",
17+
title: "new topics",
18+
url: "/new",
19+
},
20+
{
21+
display_name: "Unread Topics",
22+
title: "unread topics",
23+
url: "/unread",
24+
},
25+
],
26+
Show_counts: true,
27+
};
28+
29+
// Use defineProperty to ensure window.settings returns our mock settings
30+
// regardless of when or how the framework boots/initializes it.
31+
Object.defineProperty(window, "settings", {
32+
configurable: true,
33+
enumerable: true,
34+
get() {
35+
return mockSettings;
1336
},
14-
{
15-
display_name: "Unread Topics",
16-
title: "unread topics",
17-
url: "/unread",
37+
set() {
38+
// Prevent framework from overwriting our mock settings during boot
1839
},
19-
],
20-
Show_counts: true,
40+
});
41+
});
42+
43+
needs.hooks.afterEach(() => {
44+
// Restore original window.settings
45+
delete window.settings;
46+
if (originalSettings) {
47+
window.settings = originalSettings;
48+
}
2149
});
2250

2351
test("shows new and unread counts in navigation items", async function (assert) {
@@ -27,7 +55,14 @@ acceptance("Custom Top Navigation Links | Topic Counts", function (needs) {
2755
topicTrackingState.countNew = () => 42;
2856
topicTrackingState.countUnread = () => 17;
2957

30-
await visit("/");
58+
await visit("/latest");
59+
60+
// Print navigation HTML to debug
61+
// eslint-disable-next-line no-console
62+
console.log(
63+
"NAVIGATION BAR HTML:",
64+
document.querySelector(".nav-pills")?.innerHTML || "NOT FOUND"
65+
);
3166

3267
assert.ok(
3368
exists(".nav-item_custom_new-topics"),

0 commit comments

Comments
 (0)