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
Jarek Radosz 070b1cbed6
DEV: Don't double inject in screen-track (#17543)
1. Injecting `appEvents` service into `screen-track` was unnecessary as it's already injected into all services (and was causing an assertion error)
2. Return a promise from `sendNextConsolidatedTiming()` (no need for `await settled()` then)
2022-07-17 23:44:20 +02:00

30 lines
936 B
JavaScript

import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
discourseModule("Unit | Service | screen-track", function () {
test("consolidateTimings", async function (assert) {
const tracker = this.container.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"
);
});
});