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

MessagesGroup.spec.js « MessagesGroup « MessagesList « components « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6b71c0b846afe96e6fd7c79a83880f0cc3d8b53d (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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
import Vuex from 'vuex'
import { createLocalVue, shallowMount } from '@vue/test-utils'
import { ATTENDEE } from '../../../constants'
import { cloneDeep } from 'lodash'
import storeConfig from '../../../store/storeConfig'

import MessagesGroup from './MessagesGroup'

describe('MessagesGroup.vue', () => {
	const TOKEN = 'XXTOKENXX'
	let store
	let localVue
	let testStoreConfig
	let getGuestNameMock

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

		testStoreConfig = cloneDeep(storeConfig)
		getGuestNameMock = jest.fn()
		testStoreConfig.modules.guestNameStore.getters.getGuestName = () => getGuestNameMock
		store = new Vuex.Store(testStoreConfig)
	})

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

	test('renders grouped messages', () => {
		const wrapper = shallowMount(MessagesGroup, {
			localVue,
			store,
			propsData: {
				id: 123,
				token: TOKEN,
				previousMessageId: 90,
				nextMessageId: 200,
				lastReadMessageId: 110,
				messages: [{
					id: 100,
					token: TOKEN,
					actorId: 'actor-1',
					actorDisplayName: 'actor one',
					actorType: ATTENDEE.ACTOR_TYPE.USERS,
					message: 'first',
					messageType: 'comment',
					messageParameters: {},
					systemMessage: '',
					timestamp: 100,
					isReplyable: true,
					dateSeparator: '<date separator>',
				}, {
					id: 110,
					token: TOKEN,
					actorId: 'actor-1',
					actorDisplayName: 'actor one',
					actorType: ATTENDEE.ACTOR_TYPE.USERS,
					message: 'second',
					messageType: 'comment',
					messageParameters: {},
					systemMessage: '',
					timestamp: 200,
					isReplyable: true,
				}, {
					id: 120,
					token: TOKEN,
					actorId: 'actor-1',
					actorDisplayName: 'actor one',
					actorType: ATTENDEE.ACTOR_TYPE.USERS,
					message: 'third',
					messageType: 'comment',
					messageParameters: {},
					systemMessage: '',
					timestamp: 0, // temporary
					isReplyable: true,
				}],
			},
		})

		const dateEl = wrapper.find('.message-group__date-header')
		expect(dateEl.text()).toBe('<date separator>')

		const avatarEl = wrapper.findComponent({ name: 'AuthorAvatar' })
		expect(avatarEl.attributes('authortype')).toBe(ATTENDEE.ACTOR_TYPE.USERS)
		expect(avatarEl.attributes('authorid')).toBe('actor-1')
		expect(avatarEl.attributes('displayname')).toBe('actor one')

		const messagesEl = wrapper.findAllComponents({ name: 'Message' })
		let message = messagesEl.at(0)
		expect(message.attributes('id')).toBe('100')
		expect(message.attributes('message')).toBe('first')
		expect(message.attributes('actorid')).toBe('actor-1')
		expect(message.attributes('actordisplayname')).toBe('actor one')
		expect(message.attributes('previousmessageid')).toBe('90')
		expect(message.attributes('nextmessageid')).toBe('110')
		expect(message.attributes('isfirstmessage')).toBe('true')
		expect(message.attributes('lastreadmessageid')).toBe('110')
		expect(message.attributes('showauthor')).toBe('true')
		expect(message.attributes('istemporary')).not.toBeDefined()

		message = messagesEl.at(1)
		expect(message.attributes('id')).toBe('110')
		expect(message.attributes('message')).toBe('second')
		expect(message.attributes('actorid')).toBe('actor-1')
		expect(message.attributes('actordisplayname')).toBe('actor one')
		expect(message.attributes('previousmessageid')).toBe('100')
		expect(message.attributes('nextmessageid')).toBe('120')
		expect(message.attributes('isfirstmessage')).not.toBeDefined()
		expect(message.attributes('lastreadmessageid')).toBe('110')
		expect(message.attributes('showauthor')).toBe('true')
		expect(message.attributes('istemporary')).not.toBeDefined()

		message = messagesEl.at(2)
		expect(message.attributes('id')).toBe('120')
		expect(message.attributes('message')).toBe('third')
		expect(message.attributes('actorid')).toBe('actor-1')
		expect(message.attributes('actordisplayname')).toBe('actor one')
		expect(message.attributes('previousmessageid')).toBe('110')
		expect(message.attributes('nextmessageid')).toBe('200')
		expect(message.attributes('isfirstmessage')).not.toBeDefined()
		expect(message.attributes('lastreadmessageid')).toBe('110')
		expect(message.attributes('showauthor')).toBe('true')
		expect(message.attributes('istemporary')).toBe('true')
	})

	test('renders grouped system messages', () => {
		const wrapper = shallowMount(MessagesGroup, {
			localVue,
			store,
			propsData: {
				id: 123,
				token: TOKEN,
				previousMessageId: 90,
				nextMessageId: 200,
				lastReadMessageId: 110,
				messages: [{
					id: 100,
					token: TOKEN,
					actorId: 'actor-1',
					actorDisplayName: 'actor one',
					actorType: ATTENDEE.ACTOR_TYPE.USERS,
					message: 'Actor entered the scene',
					messageType: 'comment',
					messageParameters: {},
					systemMessage: 'call_started',
					timestamp: 100,
					isReplyable: false,
					dateSeparator: '<date separator>',
				}, {
					id: 110,
					token: TOKEN,
					actorId: 'actor-1',
					actorDisplayName: 'actor one',
					actorType: ATTENDEE.ACTOR_TYPE.USERS,
					message: 'Actor left the scene',
					messageType: 'comment',
					messageParameters: {},
					systemMessage: 'call_stopped',
					timestamp: 200,
					isReplyable: false,
				}],
			},
		})

		const dateEl = wrapper.find('.message-group__date-header')
		expect(dateEl.text()).toBe('<date separator>')

		const avatarEl = wrapper.findComponent({ name: 'AuthorAvatar' })
		expect(avatarEl.exists()).toBe(false)

		const messagesEl = wrapper.findAllComponents({ name: 'Message' })
		// TODO: date separator
		let message = messagesEl.at(0)
		expect(message.attributes('id')).toBe('100')
		expect(message.attributes('message')).toBe('Actor entered the scene')
		expect(message.attributes('actorid')).toBe('actor-1')
		expect(message.attributes('actordisplayname')).toBe('actor one')
		expect(message.attributes('previousmessageid')).toBe('90')
		expect(message.attributes('nextmessageid')).toBe('110')
		expect(message.attributes('isfirstmessage')).toBe('true')
		expect(message.attributes('lastreadmessageid')).toBe('110')
		expect(message.attributes('showauthor')).not.toBeDefined()

		message = messagesEl.at(1)
		expect(message.attributes('id')).toBe('110')
		expect(message.attributes('message')).toBe('Actor left the scene')
		expect(message.attributes('actorid')).toBe('actor-1')
		expect(message.attributes('actordisplayname')).toBe('actor one')
		expect(message.attributes('previousmessageid')).toBe('100')
		expect(message.attributes('nextmessageid')).toBe('200')
		expect(message.attributes('isfirstmessage')).not.toBeDefined()
		expect(message.attributes('lastreadmessageid')).toBe('110')
		expect(message.attributes('showauthor')).not.toBeDefined()
	})

	test('renders guest display name', () => {
		getGuestNameMock.mockReturnValue('guest-one-display-name')
		const wrapper = shallowMount(MessagesGroup, {
			localVue,
			store,
			propsData: {
				id: 123,
				token: TOKEN,
				previousMessageId: 90,
				nextMessageId: 200,
				lastReadMessageId: 110,
				messages: [{
					id: 100,
					token: TOKEN,
					actorId: 'actor-1',
					actorDisplayName: 'actor one',
					actorType: ATTENDEE.ACTOR_TYPE.GUESTS,
					message: 'first',
					messageType: 'comment',
					messageParameters: {},
					systemMessage: '',
					timestamp: 100,
					isReplyable: true,
					dateSeparator: '<date separator>',
				}, {
					id: 110,
					token: TOKEN,
					actorId: 'actor-1',
					actorDisplayName: 'actor one',
					actorType: ATTENDEE.ACTOR_TYPE.GUESTS,
					message: 'second',
					messageType: 'comment',
					messageParameters: {},
					systemMessage: '',
					timestamp: 200,
					isReplyable: true,
				}],
			},
		})

		const dateEl = wrapper.find('.message-group__date-header')
		expect(dateEl.text()).toBe('<date separator>')

		const avatarEl = wrapper.findComponent({ name: 'AuthorAvatar' })
		expect(avatarEl.attributes('authortype')).toBe(ATTENDEE.ACTOR_TYPE.GUESTS)
		expect(avatarEl.attributes('authorid')).toBe('actor-1')
		expect(avatarEl.attributes('displayname')).toBe('guest-one-display-name')

		const messagesEl = wrapper.findAllComponents({ name: 'Message' })
		let message = messagesEl.at(0)
		expect(message.attributes('id')).toBe('100')
		expect(message.attributes('actorid')).toBe('actor-1')
		expect(message.attributes('actordisplayname')).toBe('guest-one-display-name')

		message = messagesEl.at(1)
		expect(message.attributes('id')).toBe('110')
		expect(message.attributes('actorid')).toBe('actor-1')
		expect(message.attributes('actordisplayname')).toBe('guest-one-display-name')

		expect(getGuestNameMock).toHaveBeenCalledWith(TOKEN, 'actor-1')
	})

	test('renders guest display name', () => {
		const wrapper = shallowMount(MessagesGroup, {
			localVue,
			store,
			propsData: {
				id: 123,
				token: TOKEN,
				previousMessageId: 90,
				nextMessageId: 200,
				lastReadMessageId: 110,
				messages: [{
					id: 100,
					token: TOKEN,
					actorId: 'actor-1',
					actorDisplayName: '',
					actorType: ATTENDEE.ACTOR_TYPE.USERS,
					message: 'first',
					messageType: 'comment',
					messageParameters: {},
					systemMessage: '',
					timestamp: 100,
					isReplyable: true,
					dateSeparator: '<date separator>',
				}, {
					id: 110,
					token: TOKEN,
					actorId: 'actor-1',
					actorDisplayName: '',
					actorType: ATTENDEE.ACTOR_TYPE.USERS,
					message: 'second',
					messageType: 'comment',
					messageParameters: {},
					systemMessage: '',
					timestamp: 200,
					isReplyable: true,
				}],
			},
		})

		const avatarEl = wrapper.findComponent({ name: 'AuthorAvatar' })
		expect(avatarEl.attributes('authortype')).toBe(ATTENDEE.ACTOR_TYPE.USERS)
		expect(avatarEl.attributes('authorid')).toBe('actor-1')
		expect(avatarEl.attributes('displayname')).toBe('Deleted user')

		const messagesEl = wrapper.findAllComponents({ name: 'Message' })
		let message = messagesEl.at(0)
		expect(message.attributes('id')).toBe('100')
		expect(message.attributes('actorid')).toBe('actor-1')
		expect(message.attributes('actordisplayname')).toBe('Deleted user')

		message = messagesEl.at(1)
		expect(message.attributes('id')).toBe('110')
		expect(message.attributes('actorid')).toBe('actor-1')
		expect(message.attributes('actordisplayname')).toBe('Deleted user')
	})
})