Skip to content

Commit

Permalink
fix: show guest badge for e-mail guests
Browse files Browse the repository at this point in the history
- refactor tests
  • Loading branch information
Antreesy committed Oct 25, 2024
1 parent 09cdeb6 commit dbb3aea
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 40 deletions.
80 changes: 47 additions & 33 deletions src/components/RightSidebar/Participants/Participant.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -167,46 +168,59 @@ 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
* @param {RegExp} regexp regex pattern which expected to be rendered
*/
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', () => {
Expand Down
10 changes: 3 additions & 7 deletions src/components/RightSidebar/Participants/Participant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<span class="participant__user-name">{{ computedName }}</span>
<span v-if="showModeratorLabel" class="participant__user-badge">({{ t('spreed', 'moderator') }})</span>
<span v-if="isBridgeBotUser" class="participant__user-badge">({{ t('spreed', 'bot') }})</span>
<span v-if="isGuest" class="participant__user-badge">({{ t('spreed', 'guest') }})</span>
<span v-if="isGuestActor || isEmailActor" class="participant__user-badge">({{ t('spreed', 'guest') }})</span>
<span v-if="!isSelf && isLobbyEnabled && !canSkipLobby" class="participant__user-badge">({{ t('spreed', 'in the lobby') }})</span>
</span>
</template>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
}
Expand Down Expand Up @@ -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)
},
Expand Down

0 comments on commit dbb3aea

Please sign in to comment.