2021-10-21 07:42:46 -04:00
|
|
|
import { click, currentURL, fillIn, visit } from "@ember/test-helpers";
|
|
|
|
import { test } from "qunit";
|
2023-10-10 14:38:59 -04:00
|
|
|
import User from "discourse/models/user";
|
2021-10-21 07:42:46 -04:00
|
|
|
import {
|
|
|
|
joinChannel,
|
|
|
|
leaveChannel,
|
|
|
|
presentUserIds,
|
|
|
|
} from "discourse/tests/helpers/presence-pretender";
|
2024-10-29 05:44:05 -04:00
|
|
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
2021-10-21 07:42:46 -04:00
|
|
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
|
|
|
|
|
|
|
acceptance("Discourse Presence Plugin", function (needs) {
|
2022-06-29 20:18:12 -04:00
|
|
|
needs.user({ whisperer: true });
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
test("Doesn't break topic creation", async function (assert) {
|
|
|
|
await visit("/");
|
|
|
|
await click("#create-topic");
|
2022-11-07 18:17:43 -05:00
|
|
|
const categoryChooser = selectKit(".category-chooser");
|
|
|
|
await categoryChooser.expand();
|
|
|
|
await categoryChooser.selectRowByValue(2);
|
2021-10-21 07:42:46 -04:00
|
|
|
await fillIn("#reply-title", "Internationalization Localization");
|
|
|
|
await fillIn(
|
|
|
|
".d-editor-input",
|
|
|
|
"this is the *content* of a new topic post"
|
|
|
|
);
|
|
|
|
await click("#reply-control button.create");
|
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
assert.strictEqual(
|
2021-10-21 07:42:46 -04:00
|
|
|
currentURL(),
|
|
|
|
"/t/internationalization-localization/280",
|
2024-10-29 05:44:05 -04:00
|
|
|
"transitions to the newly created topic URL"
|
2021-10-21 07:42:46 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Publishes own reply presence", async function (assert) {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
|
|
|
|
await click("#topic-footer-buttons .btn.create");
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(".d-editor-input").exists("the composer input is visible");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
presentUserIds("/discourse-presence/reply/280"),
|
|
|
|
[],
|
|
|
|
"does not publish presence for open composer"
|
|
|
|
);
|
|
|
|
|
|
|
|
await fillIn(".d-editor-input", "this is the content of my reply");
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
presentUserIds("/discourse-presence/reply/280"),
|
|
|
|
[User.current().id],
|
|
|
|
"publishes presence when typing"
|
|
|
|
);
|
|
|
|
|
|
|
|
await click("#reply-control button.create");
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
presentUserIds("/discourse-presence/reply/280"),
|
|
|
|
[],
|
|
|
|
"leaves channel when composer closes"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Uses whisper channel for whispers", async function (assert) {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
|
|
|
|
await click("#topic-footer-buttons .btn.create");
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(".d-editor-input").exists("the composer input is visible");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
await fillIn(".d-editor-input", "this is the content of my reply");
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
presentUserIds("/discourse-presence/reply/280"),
|
|
|
|
[User.current().id],
|
|
|
|
"publishes reply presence when typing"
|
|
|
|
);
|
|
|
|
|
|
|
|
const menu = selectKit(".toolbar-popup-menu-options");
|
|
|
|
await menu.expand();
|
2024-08-22 19:28:28 -04:00
|
|
|
await menu.selectRowByName("toggle-whisper");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
2024-10-29 05:44:05 -04:00
|
|
|
assert
|
|
|
|
.dom(".composer-actions svg.d-icon-far-eye-slash")
|
|
|
|
.exists("sets the post type to whisper");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
presentUserIds("/discourse-presence/reply/280"),
|
|
|
|
[],
|
|
|
|
"removes reply presence"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
presentUserIds("/discourse-presence/whisper/280"),
|
|
|
|
[User.current().id],
|
|
|
|
"adds whisper presence"
|
|
|
|
);
|
|
|
|
|
|
|
|
await click("#reply-control button.create");
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
presentUserIds("/discourse-presence/whisper/280"),
|
|
|
|
[],
|
|
|
|
"leaves whisper channel when composer closes"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Uses the edit channel for editing", async function (assert) {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
|
|
|
|
await click(".topic-post:nth-of-type(1) button.show-more-actions");
|
|
|
|
await click(".topic-post:nth-of-type(1) button.edit");
|
|
|
|
|
2024-10-29 05:44:05 -04:00
|
|
|
assert
|
|
|
|
.dom(".d-editor-input")
|
|
|
|
.hasValue(
|
|
|
|
document.querySelector(".topic-post:nth-of-type(1) .cooked > p")
|
|
|
|
.innerText,
|
|
|
|
"composer has contents of post to be edited"
|
|
|
|
);
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
presentUserIds("/discourse-presence/edit/398"),
|
|
|
|
[],
|
|
|
|
"is not present when composer first opened"
|
|
|
|
);
|
|
|
|
|
|
|
|
await fillIn(".d-editor-input", "some edited content");
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
presentUserIds("/discourse-presence/edit/398"),
|
|
|
|
[User.current().id],
|
|
|
|
"becomes present in the edit channel"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
presentUserIds("/discourse-presence/reply/280"),
|
|
|
|
[],
|
|
|
|
"is not made present in the reply channel"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
presentUserIds("/discourse-presence/whisper/280"),
|
|
|
|
[],
|
|
|
|
"is not made present in the whisper channel"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Displays replying and whispering presence at bottom of topic", async function (assert) {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
|
|
|
|
const avatarSelector =
|
|
|
|
".topic-above-footer-buttons-outlet.presence .presence-avatars .avatar";
|
2024-10-22 05:34:23 -04:00
|
|
|
assert
|
|
|
|
.dom(".topic-above-footer-buttons-outlet.presence")
|
|
|
|
.exists("includes the presence component");
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(avatarSelector).doesNotExist("no avatars displayed");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
await joinChannel("/discourse-presence/reply/280", {
|
|
|
|
id: 123,
|
2022-07-10 05:09:13 -04:00
|
|
|
avatar_template: "/images/avatar.png",
|
2022-07-10 04:52:02 -04:00
|
|
|
username: "my-username",
|
2021-10-21 07:42:46 -04:00
|
|
|
});
|
|
|
|
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(avatarSelector).exists({ count: 1 }, "avatar displayed");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
await joinChannel("/discourse-presence/whisper/280", {
|
|
|
|
id: 124,
|
2022-07-10 05:09:13 -04:00
|
|
|
avatar_template: "/images/avatar.png",
|
2022-07-10 04:52:02 -04:00
|
|
|
username: "my-username2",
|
2021-10-21 07:42:46 -04:00
|
|
|
});
|
|
|
|
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(avatarSelector).exists({ count: 2 }, "whisper avatar displayed");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
await leaveChannel("/discourse-presence/reply/280", {
|
|
|
|
id: 123,
|
|
|
|
});
|
|
|
|
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(avatarSelector).exists({ count: 1 }, "reply avatar removed");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
await leaveChannel("/discourse-presence/whisper/280", {
|
|
|
|
id: 124,
|
|
|
|
});
|
|
|
|
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(avatarSelector).doesNotExist("whisper avatar removed");
|
2021-10-21 07:42:46 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test("Displays replying and whispering presence in composer", async function (assert) {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click("#topic-footer-buttons .btn.create");
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(".d-editor-input").exists("the composer input is visible");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
2021-12-24 06:38:33 -05:00
|
|
|
const avatarSelector = ".reply-to .presence-avatars .avatar";
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(avatarSelector).doesNotExist("no avatars displayed");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
await joinChannel("/discourse-presence/reply/280", {
|
|
|
|
id: 123,
|
2022-07-10 05:09:13 -04:00
|
|
|
avatar_template: "/images/avatar.png",
|
2022-07-10 04:52:02 -04:00
|
|
|
username: "my-username",
|
2021-10-21 07:42:46 -04:00
|
|
|
});
|
|
|
|
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(avatarSelector).exists({ count: 1 }, "avatar displayed");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
await joinChannel("/discourse-presence/whisper/280", {
|
|
|
|
id: 124,
|
2022-07-10 05:09:13 -04:00
|
|
|
avatar_template: "/images/avatar.png",
|
2022-07-10 04:52:02 -04:00
|
|
|
username: "my-username2",
|
2021-10-21 07:42:46 -04:00
|
|
|
});
|
|
|
|
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(avatarSelector).exists({ count: 2 }, "whisper avatar displayed");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
await leaveChannel("/discourse-presence/reply/280", {
|
|
|
|
id: 123,
|
|
|
|
});
|
|
|
|
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(avatarSelector).exists({ count: 1 }, "reply avatar removed");
|
2021-10-21 07:42:46 -04:00
|
|
|
|
|
|
|
await leaveChannel("/discourse-presence/whisper/280", {
|
|
|
|
id: 124,
|
|
|
|
});
|
|
|
|
|
2024-10-29 05:44:05 -04:00
|
|
|
assert.dom(avatarSelector).doesNotExist("whisper avatar removed");
|
2021-10-21 07:42:46 -04:00
|
|
|
});
|
|
|
|
});
|