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.
This commit is contained in:
parent
4c2f08b6e2
commit
b16028bc79
|
@ -1,4 +1,4 @@
|
|||
import Service from "@ember/service";
|
||||
import Service, { inject as service } from "@ember/service";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { bind } from "discourse-common/utils/decorators";
|
||||
import { isTesting } from "discourse-common/config/environment";
|
||||
|
@ -18,6 +18,8 @@ const AJAX_FAILURE_DELAYS = [5000, 10000, 20000, 40000];
|
|||
const ALLOWED_AJAX_FAILURES = [405, 429, 500, 501, 502, 503, 504];
|
||||
|
||||
export default class ScreenTrack extends Service {
|
||||
@service appEvents;
|
||||
|
||||
_consolidatedTimings = [];
|
||||
_lastTick = null;
|
||||
_lastScrolled = null;
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { test } from "qunit";
|
||||
import { module, test } from "qunit";
|
||||
import { setupTest } from "ember-qunit";
|
||||
|
||||
module("Unit | Service | screen-track", function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
discourseModule("Unit | Service | screen-track", function () {
|
||||
test("consolidateTimings", async function (assert) {
|
||||
const tracker = this.container.lookup("service:screen-track");
|
||||
const tracker = this.owner.lookup("service:screen-track");
|
||||
|
||||
tracker.consolidateTimings({ 1: 10, 2: 5 }, 10, 1);
|
||||
tracker.consolidateTimings({ 1: 5, 3: 1 }, 3, 1);
|
||||
|
@ -26,4 +28,26 @@ discourseModule("Unit | Service | screen-track", function () {
|
|||
"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();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue