Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ParticipantPermissionsEditor.spec.js « ParticipantPermissionsEditor « Participant « ParticipantsList « Participants « RightSidebar « components « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b1f6f9de5bd4606538a431539a2790a5b6a81338 (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
import Vuex from 'vuex'
import { createLocalVue, mount } from '@vue/test-utils'
import { cloneDeep } from 'lodash'
import storeConfig from '../../../../../../store/storeConfig.js'
import { PARTICIPANT, ATTENDEE } from '../../../../../../constants.js'

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

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 publishAudioCheckbox = wrapper.findComponent(PermissionsEditor).findComponent({ ref: 'publishAudio' })
			expect(publishAudioCheckbox.vm.$options.propsData.checked).toBe(true)
			const publishVideoCheckbox = wrapper.findComponent(PermissionsEditor).findComponent({ ref: 'publishVideo' })
			expect(publishVideoCheckbox.vm.$options.propsData.checked).toBe(true)
			const publishScreenCheckbox = wrapper.findComponent(PermissionsEditor).findComponent({ ref: 'publishScreen' })
			expect(publishScreenCheckbox.vm.$options.propsData.checked).toBe(true)
		})
	})

	describe('Dispatches the action to set the right permissions', async () => {

		test('Dispatches setPermissions with the correct permissions value when a permission is added', async () => {
			const wrapper = await mountParticipantPermissionsEditor(participant)

			// Add a permission
			await wrapper.findComponent(PermissionsEditor).setData({ lobbyIgnore: true })

			// Click the submit button
			await wrapper.findComponent(PermissionsEditor).findComponent({ ref: 'submit' }).trigger('click')

			expect(testStoreConfig.modules.participantsStore.actions.setPermissions).toHaveBeenCalledWith(
				// The first argument is the context object
				expect.anything(),
				expect.objectContaining({
					permissions: PARTICIPANT.PERMISSIONS.CALL_START
						| PARTICIPANT.PERMISSIONS.LOBBY_IGNORE
						| PARTICIPANT.PERMISSIONS.PUBLISH_AUDIO
						| PARTICIPANT.PERMISSIONS.PUBLISH_VIDEO
						| PARTICIPANT.PERMISSIONS.CUSTOM,
				})
			)
		})

		test('Dispatches setPermissions with the correct permissions value when a permission is substracted', async () => {
			const wrapper = mountParticipantPermissionsEditor(participant)

			// Remove a permission
			await wrapper.findComponent(PermissionsEditor).setData({ publishAudio: false })

			// Click the submit button
			await wrapper.findComponent(PermissionsEditor).findComponent({ ref: 'submit' }).trigger('click')

			expect(testStoreConfig.modules.participantsStore.actions.setPermissions).toHaveBeenCalledWith(
				// The first argument is the context object
				expect.anything(),
				expect.objectContaining({
					permissions: PARTICIPANT.PERMISSIONS.CALL_START
						| PARTICIPANT.PERMISSIONS.PUBLISH_VIDEO
						| PARTICIPANT.PERMISSIONS.CUSTOM,
				})
			)
		})
	})
})