A platform for community discussion. Free, open, simple.
import Service from "@ember/service";
import { click, render } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { logIn } from "discourse/tests/helpers/qunit-helpers";
import LiveParticipantSidebarContextMenu from "discourse/plugins/live/discourse/components/live-participant-sidebar-context-menu";
class LiveWebrtcStub extends Service {
getParticipantVolume() {
return 1;
}
isParticipantMuted() {
return false;
}
}
module(
"Integration | Component | LiveParticipantSidebarContextMenu",
function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
logIn(this.owner);
this.owner.unregister("service:live-webrtc");
this.owner.register("service:live-webrtc", LiveWebrtcStub);
this.selectedParticipantId = null;
this.closed = false;
this.menuData = {
room: { id: 1, room_type: "open" },
participant: { id: 2, username: "bob" },
isCurrentUser: false,
onSpotlight: (participantId) => {
this.selectedParticipantId = participantId;
},
};
this.closeMenu = () => {
this.closed = true;
};
});
test("kicks a bot without an expulsion dialog", async function (assert) {
this.menuData.participant = {
id: -2,
username: "livekit_agent_bot",
external_agent: true,
};
this.menuData.canManageRoom = true;
let kicked = false;
pretender.delete("/live/rooms/1/kick", (request) => {
kicked = true;
assert.strictEqual(
request.requestBody,
"user_id=-2",
"sends only the bot ID"
);
return response(204);
});
await render(
<template>
<LiveParticipantSidebarContextMenu
@close={{this.closeMenu}}
@data={{this.menuData}}
/>
</template>
);
await click(".live-participant-sidebar-context-menu__kick-btn");
assert.true(kicked);
assert.true(this.closed);
assert.dom(".d-modal").doesNotExist();
});
test("spotlights the participant for the viewer", async function (assert) {
await render(
<template>
<LiveParticipantSidebarContextMenu
@close={{this.closeMenu}}
@data={{this.menuData}}
/>
</template>
);
assert
.dom(".live-participant-sidebar-context-menu__spotlight-btn")
.hasText("Spotlight for me", "offers the local spotlight action");
await click(".live-participant-sidebar-context-menu__spotlight-btn");
assert.strictEqual(
this.selectedParticipantId,
2,
"selects the menu's participant"
);
assert.true(this.closed, "closes the participant menu");
});
test("shows when the participant is already spotlighted", async function (assert) {
this.menuData.isSpotlighted = true;
await render(
<template>
<LiveParticipantSidebarContextMenu
@close={{this.closeMenu}}
@data={{this.menuData}}
/>
</template>
);
assert
.dom(".live-participant-sidebar-context-menu__spotlight-btn")
.hasText("Remove from spotlight", "offers to remove the spotlight")
.hasAttribute("aria-pressed", "true", "exposes the active state");
});
}
);