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)
This commit is contained in:
Jarek Radosz 2022-07-17 23:44:20 +02:00 committed by GitHub
parent 1ccabe62d6
commit 070b1cbed6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import Service, { inject as service } from "@ember/service"; import Service from "@ember/service";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { bind } from "discourse-common/utils/decorators"; import { bind } from "discourse-common/utils/decorators";
import { isTesting } from "discourse-common/config/environment"; import { isTesting } from "discourse-common/config/environment";
@ -17,8 +17,6 @@ const AJAX_FAILURE_DELAYS = [5000, 10000, 20000, 40000];
const ALLOWED_AJAX_FAILURES = [405, 429, 500, 501, 502, 503, 504]; const ALLOWED_AJAX_FAILURES = [405, 429, 500, 501, 502, 503, 504];
export default class ScreenTrack extends Service { export default class ScreenTrack extends Service {
@service appEvents;
_consolidatedTimings = []; _consolidatedTimings = [];
_lastTick = null; _lastTick = null;
_lastScrolled = null; _lastScrolled = null;
@ -174,7 +172,7 @@ export default class ScreenTrack extends Service {
this._inProgress = true; this._inProgress = true;
ajax("/topics/timings", { return ajax("/topics/timings", {
data, data,
type: "POST", type: "POST",
headers: { headers: {
@ -201,6 +199,7 @@ export default class ScreenTrack extends Service {
resetHighestReadCache(topicId); resetHighestReadCache(topicId);
} }
} }
this.appEvents.trigger("topic:timings-sent", data); this.appEvents.trigger("topic:timings-sent", data);
}) })
.catch((e) => { .catch((e) => {

View File

@ -1,4 +1,3 @@
import { settled } from "@ember/test-helpers";
import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit"; import { test } from "qunit";
@ -19,10 +18,7 @@ discourseModule("Unit | Service | screen-track", function () {
"expecting consolidated timings to match correctly" "expecting consolidated timings to match correctly"
); );
tracker.sendNextConsolidatedTiming(); await tracker.sendNextConsolidatedTiming();
// Wait for the requests to finish
await settled();
assert.equal( assert.equal(
tracker.highestReadFromCache(2), tracker.highestReadFromCache(2),