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

actorStore.spec.js « store « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c016b5b762d53a94e1d73573cf22367230da5e43 (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
import { createLocalVue } from '@vue/test-utils'
import actorStore from './actorStore.js'
import Vuex from 'vuex'
import { cloneDeep } from 'lodash'
import { PARTICIPANT } from '../constants.js'

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

	beforeEach(() => {
		localVue = createLocalVue()
		localVue.use(Vuex)
		// eslint-disable-next-line import/no-named-as-default-member
		store = new Vuex.Store(cloneDeep(actorStore))
	})

	test('setCurrentUser updates all relevant attributes', () => {
		store.dispatch('setCurrentUser', {
			uid: 'userId',
			displayName: 'display-name',
		})

		expect(store.getters.getUserId()).toBe('userId')
		expect(store.getters.getDisplayName()).toBe('display-name')
		expect(store.getters.getActorId()).toBe('userId')
		expect(store.getters.getActorType()).toBe('users')
	})

	test('setDisplayName updates all relevant attributes', () => {
		store.dispatch('setCurrentUser', {
			uid: 'userId',
			displayName: 'display-name',
		})

		store.dispatch('setDisplayName', 'new-display-name')

		expect(store.getters.getUserId()).toBe('userId')
		expect(store.getters.getDisplayName()).toBe('new-display-name')
	})

	describe('setCurrentParticipant', () => {
		test('setCurrentParticipant with type GUEST clears user id and updates all relevant attributes', () => {
			store.dispatch('setCurrentParticipant', {
				actorId: 'guestActorId',
				sessionId: 'XXSESSIONIDXX',
				participantType: PARTICIPANT.TYPE.GUEST,
			})

			expect(store.getters.getSessionId()).toBe('XXSESSIONIDXX')
			expect(store.getters.getUserId()).toBe(null)
			expect(store.getters.getDisplayName()).toBe('')
			expect(store.getters.getActorId()).toBe('guestActorId')
			expect(store.getters.getActorType()).toBe('guests')
		})

		test('setCurrentParticipant with type GUEST_MODERATOR clears user id and updates all relevant attributes', () => {
			store.dispatch('setCurrentParticipant', {
				actorId: 'guestActorId',
				sessionId: 'XXSESSIONIDXX',
				participantType: PARTICIPANT.TYPE.GUEST_MODERATOR,
			})

			expect(store.getters.getSessionId()).toBe('XXSESSIONIDXX')
			expect(store.getters.getUserId()).toBe(null)
			expect(store.getters.getDisplayName()).toBe('')
			expect(store.getters.getActorId()).toBe('guestActorId')
			expect(store.getters.getActorType()).toBe('guests')
		})

		test('setCurrentParticipant with type USER keeps user id and updates all relevant attributes', () => {
			store.dispatch('setCurrentUser', {
				uid: 'userId',
				displayName: 'display-name',
			})

			store.dispatch('setCurrentParticipant', {
				actorId: 'userActorId',
				sessionId: 'XXSESSIONIDXX',
				participantType: PARTICIPANT.TYPE.USER,
			})

			expect(store.getters.getSessionId()).toBe('XXSESSIONIDXX')

			// user values unchanged
			expect(store.getters.getUserId()).toBe('userId')
			expect(store.getters.getDisplayName()).toBe('display-name')
			expect(store.getters.getActorId()).toBe('userId')
			expect(store.getters.getActorType()).toBe('users')
		})
	})
})