FIX: correctly check for disabled notifications, tab and is idle (#27127)

This commit reuses the existing codepath in desktop-notifications and make it available to use to chat.

primaryTab was too hard to test if not impossible in this service test, however isIdle and disabled notifications are correctly tested.
This commit is contained in:
Joffrey JAFFEUX
2024-05-22 10:08:05 +02:00
committed by GitHub
parent 322a20a9f4
commit 52125d849f
3 changed files with 66 additions and 18 deletions

View File

@@ -1,5 +1,11 @@
import { getOwner } from "@ember/application";
import { test } from "qunit";
import {
disable,
init,
resetIdle,
setLastAction,
} from "discourse/lib/desktop-notifications";
import {
acceptance,
updateCurrentUser,
@@ -44,6 +50,13 @@ acceptance(
});
updateCurrentUser({ chat_sound: "ding" });
init(
this.container.lookup("service:message-bus"),
this.container.lookup("service:app-events")
);
setLastAction(moment().subtract(1, "hour").valueOf());
});
needs.user();
@@ -115,5 +128,19 @@ acceptance(
assert.deepEqual(await this.subject.play(channel), false);
});
test("not idle", async function (assert) {
const channel = buildDirectMessageChannel(getOwner(this));
resetIdle();
assert.deepEqual(await this.subject.play(channel), false);
});
test("notifications disabled", async function (assert) {
const channel = buildDirectMessageChannel(getOwner(this));
disable();
assert.deepEqual(await this.subject.play(channel), false);
});
}
);