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

callViewStore.spec.js « store « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3158c9f01530cc26ad835397c194613eaa6de4fa (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
import { createLocalVue } from '@vue/test-utils'
import storeConfig from './storeConfig'
import Vuex from 'vuex'
import { cloneDeep } from 'lodash'
import {
	CONVERSATION,
} from '../constants'

describe('callViewStore', () => {
	let localVue = null
	let store = null

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

		const testStoreConfig = cloneDeep(storeConfig)

		// remove participant store to avoid participant interaction
		testStoreConfig.modules.participantsStore = {}

		store = new Vuex.Store(testStoreConfig)

		// to fully reset the state between tests, clear the storage
		localStorage.clear()

		// and reset all mocks
		jest.clearAllMocks()
	})

	describe('raised hand', () => {
		test('get whether participants raised hands with single session id', () => {
			store.dispatch('setParticipantHandRaised', {
				sessionId: 'session-id-1',
				raisedHand: { state: true, timestamp: 1 },
			})
			store.dispatch('setParticipantHandRaised', {
				sessionId: 'session-id-2',
				raisedHand: { state: true, timestamp: 2 },
			})

			expect(store.getters.getParticipantRaisedHand(['session-id-1']))
				.toStrictEqual({ state: true, timestamp: 1 })

			expect(store.getters.getParticipantRaisedHand(['session-id-2']))
				.toStrictEqual({ state: true, timestamp: 2 })

			expect(store.getters.getParticipantRaisedHand(['session-id-another']))
				.toStrictEqual({ state: false, timestamp: null })
		})

		test('get raised hands after lowering', () => {
			store.dispatch('setParticipantHandRaised', {
				sessionId: 'session-id-2',
				raisedHand: { state: true, timestamp: 1 },
			})
			store.dispatch('setParticipantHandRaised', {
				sessionId: 'session-id-2',
				raisedHand: { state: false, timestamp: 3 },
			})

			expect(store.getters.getParticipantRaisedHand(['session-id-2']))
				.toStrictEqual({ state: false, timestamp: null })
		})

		test('clears raised hands state after leaving call', () => {
			store.dispatch('setParticipantHandRaised', {
				sessionId: 'session-id-2',
				raisedHand: { state: true, timestamp: 1 },
			})
			store.dispatch('leaveCall')

			expect(store.getters.getParticipantRaisedHand(['session-id-2']))
				.toStrictEqual({ state: false, timestamp: null })
		})

		test('get raised hands with multiple session ids only returns first found', () => {
			store.dispatch('setParticipantHandRaised', {
				sessionId: 'session-id-2',
				raisedHand: { state: true, timestamp: 1 },
			})
			store.dispatch('setParticipantHandRaised', {
				sessionId: 'session-id-3',
				raisedHand: { state: true, timestamp: 1 },
			})

			expect(store.getters.getParticipantRaisedHand(['session-id-1', 'session-id-2', 'session-id-3']))
				.toStrictEqual({ state: true, timestamp: 1 })
		})
	})

	describe('call view mode and presentation', () => {
		test('restores grid state when joining call (true)', () => {
			localStorage.getItem.mockReturnValueOnce('true')

			store.dispatch('joinCall', { token: 'XXTOKENXX' })

			expect(localStorage.getItem).toHaveBeenCalled()
			expect(localStorage.getItem.mock.calls[0][0]).toEqual(expect.stringMatching(/callprefs-XXTOKENXX-isgrid$/))

			expect(store.getters.isGrid).toBe(true)
			expect(store.getters.isStripeOpen).toBe(true)
		})

		test('restores grid state when joining call (false)', () => {
			localStorage.getItem.mockReturnValueOnce('false')

			store.dispatch('joinCall', { token: 'XXTOKENXX' })

			expect(localStorage.getItem).toHaveBeenCalled()
			expect(localStorage.getItem.mock.calls[0][0]).toEqual(expect.stringMatching(/callprefs-XXTOKENXX-isgrid$/))

			expect(store.getters.isGrid).toBe(false)
			expect(store.getters.isStripeOpen).toBe(true)
		})

		/**
		 * @param {number} conversationType The type of the conversation
		 * @param {boolean} state Whether or not the grid is shown
		 */
		function testDefaultGridState(conversationType, state) {
			localStorage.getItem.mockReturnValueOnce(null)

			// using commit instead of dispatch because the action
			// also processes participants
			store.commit('addConversation', {
				token: 'XXTOKENXX',
				type: conversationType,
			})
			store.dispatch('joinCall', { token: 'XXTOKENXX' })

			expect(localStorage.getItem).toHaveBeenCalled()
			expect(localStorage.getItem.mock.calls[0][0]).toEqual(expect.stringMatching(/callprefs-XXTOKENXX-isgrid$/))

			expect(store.getters.isGrid).toBe(state)
			expect(store.getters.isStripeOpen).toBe(true)
		}

		test('sets default grid state when joining call in group conversation', () => {
			testDefaultGridState(CONVERSATION.TYPE.GROUP, true)
		})

		test('sets default grid state when joining call in public conversation', () => {
			testDefaultGridState(CONVERSATION.TYPE.PUBLIC, true)
		})

		test('sets default grid state when joining call in one to one conversation', () => {
			testDefaultGridState(CONVERSATION.TYPE.ONE_TO_ONE, false)
		})

		test('switching call view mode saves in local storage', () => {
			store.dispatch('updateToken', 'XXTOKENXX')

			store.dispatch('setCallViewMode', {
				isGrid: true,
				isStripeOpen: false,
			})

			expect(store.getters.isGrid).toEqual(true)
			expect(store.getters.isStripeOpen).toEqual(false)

			expect(localStorage.setItem).toHaveBeenCalled()
			expect(localStorage.setItem.mock.calls[0][0]).toEqual(expect.stringMatching(/callprefs-XXTOKENXX-isgrid$/))
			expect(localStorage.setItem.mock.calls[0][1]).toBe(true)

			store.dispatch('setCallViewMode', {
				isGrid: false,
				isStripeOpen: true,
			})

			expect(store.getters.isGrid).toEqual(false)
			expect(store.getters.isStripeOpen).toEqual(true)

			expect(localStorage.setItem).toHaveBeenCalled()
			expect(localStorage.setItem.mock.calls[1][0]).toEqual(expect.stringMatching(/callprefs-XXTOKENXX-isgrid$/))
			expect(localStorage.setItem.mock.calls[1][1]).toBe(false)
		})

		test('start presentation switches off grid view and restores when it ends', () => {
			[{
				isGrid: true,
				isStripeOpen: true,
			}, {
				isGrid: false,
				isStripeOpen: false,
			}].forEach((testState) => {
				store.dispatch('setCallViewMode', testState)

				store.dispatch('startPresentation')

				expect(store.getters.isGrid).toEqual(false)
				expect(store.getters.isStripeOpen).toEqual(false)

				store.dispatch('stopPresentation')

				expect(store.getters.isGrid).toEqual(testState.isGrid)
				expect(store.getters.isStripeOpen).toEqual(testState.isStripeOpen)
			})
		})

		test('switching modes during presentation does not resets it after it ends', () => {
			store.dispatch('setCallViewMode', {
				isGrid: true,
				isStripeOpen: true,
			})

			store.dispatch('startPresentation')

			// switch during presentation
			store.dispatch('setCallViewMode', {
				isGrid: true,
				isStripeOpen: true,
			})

			store.dispatch('stopPresentation')

			// state kept, not restored
			expect(store.getters.isGrid).toEqual(true)
			expect(store.getters.isStripeOpen).toEqual(true)
		})

		test('starting presentation twice does not mess up remembered state', () => {
			store.dispatch('setCallViewMode', {
				isGrid: true,
				isStripeOpen: true,
			})

			expect(store.getters.presentationStarted).toBe(false)

			store.dispatch('startPresentation')

			expect(store.getters.presentationStarted).toBe(true)

			// switch during presentation
			store.dispatch('setCallViewMode', {
				isGrid: true,
				isStripeOpen: true,
			})

			store.dispatch('startPresentation')

			// state kept
			expect(store.getters.isGrid).toEqual(true)
			expect(store.getters.isStripeOpen).toEqual(true)

			expect(store.getters.presentationStarted).toBe(true)

			store.dispatch('stopPresentation')

			expect(store.getters.presentationStarted).toBe(false)

			// state kept, not restored
			expect(store.getters.isGrid).toEqual(true)
			expect(store.getters.isStripeOpen).toEqual(true)
		})

		test('stopping presentation twice does not mess up remembered state', () => {
			store.dispatch('setCallViewMode', {
				isGrid: true,
				isStripeOpen: true,
			})

			expect(store.getters.presentationStarted).toBe(false)

			store.dispatch('startPresentation')

			expect(store.getters.presentationStarted).toBe(true)

			store.dispatch('stopPresentation')

			expect(store.getters.presentationStarted).toBe(false)

			expect(store.getters.isGrid).toEqual(true)
			expect(store.getters.isStripeOpen).toEqual(true)

			store.dispatch('setCallViewMode', {
				isGrid: false,
				isStripeOpen: false,
			})

			store.dispatch('stopPresentation')

			expect(store.getters.presentationStarted).toBe(false)

			// state kept, not reset
			expect(store.getters.isGrid).toEqual(false)
			expect(store.getters.isStripeOpen).toEqual(false)
		})
	})
})