Skip to content

Commit c310f81

Browse files
committed
test: add qunit acceptance test for topic count tracking in custom nav links
1 parent 3c68250 commit c310f81

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
2+
import { visit } from "@ember/test-helpers";
3+
import { test } from "qunit";
4+
5+
acceptance("Custom Top Navigation Links | Topic Counts", function (needs) {
6+
needs.user();
7+
8+
let originalNavLinks;
9+
let originalShowCounts;
10+
11+
needs.hooks.beforeEach(function () {
12+
originalNavLinks = settings.nav_links;
13+
originalShowCounts = settings.Show_counts;
14+
15+
settings.nav_links = [
16+
{ display_name: "New Topics", title: "new topics", url: "/new" },
17+
{ display_name: "Unread Topics", title: "unread topics", url: "/unread" },
18+
];
19+
settings.Show_counts = true;
20+
});
21+
22+
needs.hooks.afterEach(function () {
23+
settings.nav_links = originalNavLinks;
24+
settings.Show_counts = originalShowCounts;
25+
});
26+
27+
test("shows new and unread counts in navigation items", async function (assert) {
28+
const topicTrackingState = this.owner.lookup("service:topic-tracking-state");
29+
topicTrackingState.countNew = () => 42;
30+
topicTrackingState.countUnread = () => 17;
31+
32+
await visit("/latest");
33+
34+
assert.ok(exists(".nav-item_custom_new-topics"), "custom navigation item for new topics is rendered");
35+
assert.dom(".nav-item_custom_new-topics a").hasText("New Topics (42)", "it shows the custom new topics count");
36+
37+
assert.ok(exists(".nav-item_custom_unread-topics"), "custom navigation item for unread topics is rendered");
38+
assert.dom(".nav-item_custom_unread-topics a").hasText("Unread Topics (17)", "it shows the custom unread topics count");
39+
});
40+
});

0 commit comments

Comments
 (0)