This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/acceptance/topic-list-tracker-test.js
2022-07-15 16:51:15 +10:00

89 lines
2.4 KiB
JavaScript

import {
nextTopicUrl,
previousTopicUrl,
setTopicId,
} from "discourse/lib/topic-list-tracker";
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { click, visit } from "@ember/test-helpers";
import topicFixtures from "discourse/tests/fixtures/topic";
import discoveryFixtures from "discourse/tests/fixtures/discovery-fixtures";
import { cloneJSON } from "discourse-common/lib/object";
import { NotificationLevels } from "discourse/lib/notification-levels";
acceptance("Topic list tracking", function (needs) {
let notificationLevel;
needs.hooks.afterEach(() => {
notificationLevel = null;
});
needs.user();
needs.pretender((server, helper) => {
server.get("/latest.json", () => {
const fixture = cloneJSON(discoveryFixtures["/latest.json"]);
if (notificationLevel) {
fixture["topic_list"]["topics"].find((t) => {
if (t.id === 11557) {
t.notification_level = notificationLevel;
}
});
}
return helper.response(cloneJSON(fixture));
});
server.get("/t/11557.json", () => {
const topicFixture = cloneJSON(topicFixtures["/t/130.json"]);
topicFixture.id = 11557;
return helper.response(topicFixture);
});
});
test("Navigation", async function (assert) {
await visit("/");
let url = await nextTopicUrl();
assert.strictEqual(url, "/t/error-after-upgrade-to-0-9-7-9/11557");
setTopicId(11557);
url = await nextTopicUrl();
assert.strictEqual(url, "/t/welcome-to-meta-discourse-org/1");
url = await previousTopicUrl();
assert.strictEqual(url, "/t/error-after-upgrade-to-0-9-7-9/11557");
});
test("unread count is set on topic that user is tracking", async function (assert) {
notificationLevel = NotificationLevels.TRACKING;
await visit("/");
await click(".raw-topic-link[data-topic-id='11557']");
await visit("/");
assert.ok(
exists("tr[data-topic-id='11557'] .unread-posts"),
"unread count for topic is shown"
);
});
test("unread count is not set on topic that user is not tracking", async function (assert) {
notificationLevel = NotificationLevels.REGULAR;
await visit("/");
await click(".raw-topic-link[data-topic-id='11557']");
await visit("/");
assert.notOk(
exists("tr[data-topic-id='11557'] .unread-posts"),
"unread count for topic is not shown"
);
});
});