|
| 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( |
| 29 | + "service:topic-tracking-state" |
| 30 | + ); |
| 31 | + topicTrackingState.countNew = () => 42; |
| 32 | + topicTrackingState.countUnread = () => 17; |
| 33 | + |
| 34 | + await visit("/latest"); |
| 35 | + |
| 36 | + assert.ok( |
| 37 | + exists(".nav-item_custom_new-topics"), |
| 38 | + "custom navigation item for new topics is rendered" |
| 39 | + ); |
| 40 | + assert |
| 41 | + .dom(".nav-item_custom_new-topics a") |
| 42 | + .hasText("New Topics (42)", "it shows the custom new topics count"); |
| 43 | + |
| 44 | + assert.ok( |
| 45 | + exists(".nav-item_custom_unread-topics"), |
| 46 | + "custom navigation item for unread topics is rendered" |
| 47 | + ); |
| 48 | + assert |
| 49 | + .dom(".nav-item_custom_unread-topics a") |
| 50 | + .hasText("Unread Topics (17)", "it shows the custom unread topics count"); |
| 51 | + }); |
| 52 | +}); |
0 commit comments