From 109a059c9a3f1bcb4e4ecfbe16fcf449ae530967 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Fri, 25 Oct 2024 20:29:49 +0200 Subject: [PATCH] fix: show guest badge for e-mail guests - refactor tests Signed-off-by: Maksim Sukharev --- .../Participants/Participant.spec.js | 80 +++++++++++-------- .../RightSidebar/Participants/Participant.vue | 10 +-- 2 files changed, 50 insertions(+), 40 deletions(-) diff --git a/src/components/RightSidebar/Participants/Participant.spec.js b/src/components/RightSidebar/Participants/Participant.spec.js index 5e0cb04a5aa..c89f053179e 100644 --- a/src/components/RightSidebar/Participants/Participant.spec.js +++ b/src/components/RightSidebar/Participants/Participant.spec.js @@ -25,7 +25,7 @@ import NcTextArea from '@nextcloud/vue/dist/Components/NcTextArea.js' import Participant from './Participant.vue' import AvatarWrapper from '../../AvatarWrapper/AvatarWrapper.vue' -import { ATTENDEE, PARTICIPANT } from '../../../constants.js' +import { ATTENDEE, PARTICIPANT, WEBINAR } from '../../../constants.js' import storeConfig from '../../../store/storeConfig.js' import { findNcActionButton, findNcButton } from '../../../test-helpers.js' @@ -62,6 +62,7 @@ describe('Participant.vue', () => { conversation = { token: 'current-token', participantType: PARTICIPANT.TYPE.USER, + lobbyState: WEBINAR.LOBBY.NONE, } const conversationGetterMock = jest.fn().mockReturnValue(conversation) @@ -139,7 +140,7 @@ describe('Participant.vue', () => { test('renders avatar with guest name when empty', () => { participant.displayName = '' - participant.participantType = PARTICIPANT.TYPE.GUEST + participant.actorType = ATTENDEE.ACTOR_TYPE.GUESTS const wrapper = mountParticipant(participant) const avatarEl = wrapper.findComponent(AvatarWrapper) expect(avatarEl.exists()).toBe(true) @@ -167,11 +168,6 @@ describe('Participant.vue', () => { }) describe('user name', () => { - beforeEach(() => { - participant.statusIcon = '' - participant.statusMessage = '' - }) - /** * Check which text is currently rendered as a name * @param {object} participant participant object @@ -179,34 +175,52 @@ describe('Participant.vue', () => { */ function checkUserNameRendered(participant, regexp) { const wrapper = mountParticipant(participant) - expect(wrapper.find('.participant__user').exists()).toBeTruthy() - expect(wrapper.find('.participant__user').text()).toMatch(regexp) + const username = wrapper.find('.participant__user') + expect(username.exists()).toBeTruthy() + expect(username.text()).toMatch(regexp) } - test('renders plain user name for regular user', async () => { - checkUserNameRendered(participant, /^Alice$/) - }) - - test('renders guest suffix for guests', async () => { - participant.participantType = PARTICIPANT.TYPE.GUEST - checkUserNameRendered(participant, /^Alice\s+\(guest\)$/) - }) - - test('renders moderator suffix for moderators', async () => { - participant.participantType = PARTICIPANT.TYPE.MODERATOR - checkUserNameRendered(participant, /^Alice\s+\(moderator\)$/) - }) - - test('renders guest moderator suffix for guest moderators', async () => { - participant.participantType = PARTICIPANT.TYPE.GUEST_MODERATOR - checkUserNameRendered(participant, /^Alice\s+\(moderator\)\s+\(guest\)$/) - }) - - test('renders bot suffix for bots', async () => { - participant.actorType = ATTENDEE.ACTOR_TYPE.USERS - participant.actorId = ATTENDEE.BRIDGE_BOT_ID - checkUserNameRendered(participant, /^Alice\s+\(bot\)$/) - }) + const testCases = [ + ['Alice', 'alice', ATTENDEE.ACTOR_TYPE.USERS, PARTICIPANT.TYPE.USER, /^Alice$/], + ['Alice', 'guest-id', ATTENDEE.ACTOR_TYPE.GUESTS, PARTICIPANT.TYPE.GUEST, /^Alice\s+\(guest\)$/], + ['Alice', 'guest-id', ATTENDEE.ACTOR_TYPE.EMAILS, PARTICIPANT.TYPE.GUEST, /^Alice\s+\(guest\)$/], + ['', 'guest-id', ATTENDEE.ACTOR_TYPE.GUESTS, PARTICIPANT.TYPE.GUEST, /^Guest\s+\(guest\)$/], + ['Alice', 'alice', ATTENDEE.ACTOR_TYPE.USERS, PARTICIPANT.TYPE.MODERATOR, /^Alice\s+\(moderator\)$/], + ['Alice', 'guest-id', ATTENDEE.ACTOR_TYPE.GUESTS, PARTICIPANT.TYPE.GUEST_MODERATOR, /^Alice\s+\(moderator\)\s+\(guest\)$/], + ['Bot', ATTENDEE.BRIDGE_BOT_ID, ATTENDEE.ACTOR_TYPE.USERS, PARTICIPANT.TYPE.USER, /^Bot\s+\(bot\)$/], + ] + + const testLobbyCases = [ + ['Alice', 'alice', ATTENDEE.ACTOR_TYPE.USERS, PARTICIPANT.TYPE.USER, /^Alice\s+\(in the lobby\)$/], + ['Alice', 'guest-id', ATTENDEE.ACTOR_TYPE.GUESTS, PARTICIPANT.TYPE.GUEST, /^Alice\s+\(guest\)\s+\(in the lobby\)$/], + ['Alice', 'guest-id', ATTENDEE.ACTOR_TYPE.EMAILS, PARTICIPANT.TYPE.GUEST, /^Alice\s+\(guest\)\s+\(in the lobby\)$/], + ['', 'guest-id', ATTENDEE.ACTOR_TYPE.GUESTS, PARTICIPANT.TYPE.GUEST, /^Guest\s+\(guest\)\s+\(in the lobby\)$/], + ['Alice', 'alice', ATTENDEE.ACTOR_TYPE.USERS, PARTICIPANT.TYPE.MODERATOR, /^Alice\s+\(moderator\)$/], + ['Alice', 'guest-id', ATTENDEE.ACTOR_TYPE.GUESTS, PARTICIPANT.TYPE.GUEST_MODERATOR, /^Alice\s+\(moderator\)\s+\(guest\)$/], + ] + + it.each(testCases)('renders name and badges for participant \'%s\' - \'%s\' - \'%s\' - \'%d\'', + (displayName, actorId, actorType, participantType, regexp) => { + checkUserNameRendered({ + ...participant, + actorId, + actorType, + participantType, + displayName, + }, regexp) + }) + + it.each(testLobbyCases)('renders name and badges for participant \'%s\' - \'%s\' - \'%s\' - \'%d\' with lobby enabled', + (displayName, actorId, actorType, participantType, regexp) => { + conversation.lobbyState = WEBINAR.LOBBY.NON_MODERATORS + checkUserNameRendered({ + ...participant, + actorId, + actorType, + participantType, + displayName, + }, regexp) + }) }) describe('user status', () => { diff --git a/src/components/RightSidebar/Participants/Participant.vue b/src/components/RightSidebar/Participants/Participant.vue index 2cd95e69ba2..b1ae97a57b2 100644 --- a/src/components/RightSidebar/Participants/Participant.vue +++ b/src/components/RightSidebar/Participants/Participant.vue @@ -32,7 +32,7 @@ {{ computedName }} ({{ t('spreed', 'moderator') }}) ({{ t('spreed', 'bot') }}) - ({{ t('spreed', 'guest') }}) + ({{ t('spreed', 'guest') }}) ({{ t('spreed', 'in the lobby') }}) @@ -454,7 +454,7 @@ export default { if (this.isBridgeBotUser) { text += ' (' + t('spreed', 'bot') + ')' } - if (this.isGuest) { + if (this.isGuestActor || this.isEmailActor) { text += ' (' + t('spreed', 'guest') + ')' } return text @@ -547,7 +547,7 @@ export default { computedName() { const displayName = this.participant.displayName.trim() - if (displayName === '' && this.isGuest) { + if (displayName === '' && (this.isGuestActor || this.isEmailActor)) { return t('spreed', 'Guest') } @@ -646,10 +646,6 @@ export default { && (hasTalkFeature(this.token, 'federation-v2') || !hasTalkFeature(this.token, 'federation-v1') || (!this.conversation.remoteServer && !this.isFederatedActor)) }, - isGuest() { - return [PARTICIPANT.TYPE.GUEST, PARTICIPANT.TYPE.GUEST_MODERATOR].includes(this.participantType) - }, - isModerator() { return this.participantTypeIsModerator(this.participantType) },