summaryrefslogtreecommitdiffstats
path: root/src/components/RightSidebar/Participants/ParticipantPermissionsEditor.spec.js
blob: a3b3589530247c782b7c7b7c7fc66758206dc81f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
 * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
import { createLocalVue, mount } from '@vue/test-utils'
import { cloneDeep } from 'lodash'
import Vuex from 'vuex'

import ParticipantPermissionsEditor from './ParticipantPermissionsEditor.vue'
import PermissionsEditor from '../../PermissionsEditor/PermissionsEditor.vue'

import { PARTICIPANT, ATTENDEE } from '../../../constants.js'
import storeConfig from '../../../store/storeConfig.js'

describe('ParticipantPermissionsEditor.vue', () => {
	let conversation
	let participant
	let store
	let localVue
	let testStoreConfig

	beforeEach(() => {
		localVue = createLocalVue()
		localVue.use(Vuex)

		participant = {
			displayName: 'Alice',
			inCall: PARTICIPANT.CALL_FLAG.DISCONNECTED,
			actorId: 'alice-actor-id',
			actorType: ATTENDEE.ACTOR_TYPE.USERS,
			participantType: PARTICIPANT.TYPE.USER,
			permissions: PARTICIPANT.PERMISSIONS.CALL_START
				| PARTICIPANT.PERMISSIONS.PUBLISH_AUDIO
				| PARTICIPANT.PERMISSIONS.PUBLISH_VIDEO
				| PARTICIPANT.PERMISSIONS.CUSTOM,
			attendeeId: 'alice-attendee-id',
			status: '',
			statusIcon: '🌧️',
			statusMessage: 'rainy',
			sessionIds: [
				'session-id-alice',
			],
		}

		const conversationGetterMock = jest.fn().mockReturnValue(conversation)

		testStoreConfig = cloneDeep(storeConfig)
		testStoreConfig.modules.tokenStore.getters.getToken = () => () => 'current-token'
		testStoreConfig.modules.conversationsStore.getters.conversation = () => conversationGetterMock
		// Add a mock function for the action and see if its called and with which arguments
		testStoreConfig.modules.participantsStore.actions.setPermissions = jest.fn()
		// eslint-disable-next-line import/no-named-as-default-member
		store = new Vuex.Store(testStoreConfig)

	})

	afterEach(() => {
		jest.clearAllMocks()
	})

	/**
	 * @param {object} participant Participant with optional user status data
	 */
	const mountParticipantPermissionsEditor = (participant) => {
		return mount(ParticipantPermissionsEditor, {
			localVue,
			store,
			propsData: {
				participant,
				token: 'fdslk033',
			},
		})
	}

	describe('Properly renders the checkboxes when mounted', () => {
		test('Properly renders the call start checkbox', async () => {
			const wrapper = await mountParticipantPermissionsEditor(participant)
			const callStartCheckbox = wrapper.findComponent(PermissionsEditor).findComponent({ ref: 'callStart' })
			expect(callStartCheckbox.vm.$options.propsData.checked).toBe(true)
		})

		test('Properly renders the lobby Ignore checkbox', async () => {
			const wrapper = await mountParticipantPermissionsEditor(participant)
			const lobbyIgnoreCheckbox = wrapper.findComponent(PermissionsEditor).findComponent({ ref: 'lobbyIgnore' })
			expect(lobbyIgnoreCheckbox.vm.$options.propsData.checked).toBe(false)
		})

		test('Properly renders the publish audio checkbox', async () => {
			const wrapper = await mountParticipantPermissionsEditor(participant)
			const publishAudioCheckbox = wrapper.findComponent(PermissionsEditor).findComponent({ ref: 'publishAudio' })
			expect(publishAudioCheckbox.vm.$options.propsData.checked).toBe(true)
		})

		test('Properly renders the publish video checkbox', async () => {
			const wrapper = await mountParticipantPermissionsEditor(participant)
			const publishVideoCheckbox = wrapper.findComponent(PermissionsEditor).findComponent({ ref: 'publishVideo' })
			expect(publishVideoCheckbox.vm.$options.propsData.checked).toBe(true)
		})

		test('Properly renders the publish screen checkbox', async () => {
			const wrapper = await mountParticipantPermissionsEditor(participant)
			const publishScreenCheckbox = wrapper.findComponent(PermissionsEditor).findComponent({ ref: 'publishScreen' })
			expect(publishScreenCheckbox.vm.$options.propsData.checked).toBe(false)
		})

		test('Properly renders the checkboxes with default permissions', async () => {
			participant.permissions = PARTICIPANT.PERMISSIONS.DEFAULT
			const wrapper = await mountParticipantPermissionsEditor(participant)
			const callStartCheckbox = wrapper.findComponent(PermissionsEditor).findComponent({ ref: 'callStart' })
			expect(callStartCheckbox.vm.$options.propsData.checked).toBe(true)
			const lobbyIgnoreCheckbox = wrapper.findComponent(PermissionsEditor).findComponent({ ref: 'lobbyIgnore' })
			expect(lobbyIgnoreCheckbox.vm.$options.propsData.checked).toBe(false)
			const