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/unit/services/screen-track-test.js
Sérgio Saquetim b16028bc79
FIX: Inject appEvents in ScreenTrack (#17751)
This commit reverts partially https://github.com/discourse/discourse/pull/17543.

Service appEvents was not being injected in ScreenTrack. This causes
`this.appEvents.trigger("topic:timings-sent", data);` to fail and the error is
swallowed by the `catch` on the promise.

This caused a regression on plugins that rely on this event to implement other
behaviors.
2022-08-02 16:22:17 -03:00

54 lines
1.6 KiB
JavaScript

import { module, test } from "qunit";
import { setupTest } from "ember-qunit";
module("Unit | Service | screen-track", function (hooks) {
setupTest(hooks);
test("consolidateTimings", async function (assert) {
const tracker = this.owner.lookup("service:screen-track");
tracker.consolidateTimings({ 1: 10, 2: 5 }, 10, 1);
tracker.consolidateTimings({ 1: 5, 3: 1 }, 3, 1);
const consolidated = tracker.consolidateTimings({ 1: 5, 3: 1, 4: 5 }, 3, 2);
assert.deepEqual(
consolidated,
[
{ timings: { 1: 15, 2: 5, 3: 1 }, topicTime: 13, topicId: 1 },
{ timings: { 1: 5, 3: 1, 4: 5 }, topicTime: 3, topicId: 2 },
],
"expecting consolidated timings to match correctly"
);
await tracker.sendNextConsolidatedTiming();
assert.equal(
tracker.highestReadFromCache(2),
4,
"caches highest read post number for second topic"
);
});
test("ScreenTrack has appEvents", async function (assert) {
const tracker = this.owner.lookup("service:screen-track");
assert.ok(tracker.appEvents);
});
test("appEvent topic:timings-sent is triggered after posting consolidated timings", async function (assert) {
assert.timeout(1000);
const tracker = this.owner.lookup("service:screen-track");
const appEvents = this.owner.lookup("service:app-events");
const done = assert.async();
appEvents.on("topic:timings-sent", () => {
assert.ok(true);
done();
});
tracker.consolidateTimings({ 1: 10, 2: 5 }, 10, 1);
await tracker.sendNextConsolidatedTiming();
});
});