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

LeftSidebar.spec.js « LeftSidebar « components « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5e813e222adfb7e8c35f072d94d1ac8db32c425f (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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
/* eslint-disable import/no-named-as-default-member */
import Vuex from 'vuex'
import { createLocalVue, mount } from '@vue/test-utils'
import VueRouter from 'vue-router'
import router from '../../router/router.js'
import { cloneDeep } from 'lodash'
import storeConfig from '../../store/storeConfig.js'
import { loadState } from '@nextcloud/initial-state'
import { EventBus } from '../../services/EventBus.js'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import {
	searchPossibleConversations,
	searchListedConversations,
} from '../../services/conversationsService.js'

import LeftSidebar from './LeftSidebar.vue'

jest.mock('@nextcloud/initial-state', () => ({
	loadState: jest.fn(),
}))
jest.mock('../../services/conversationsService', () => ({
	searchPossibleConversations: jest.fn(),
	searchListedConversations: jest.fn(),
}))

// short-circuit debounce
jest.mock('debounce', () => jest.fn().mockImplementation(fn => fn))

describe('LeftSidebar.vue', () => {
	let store
	let localVue
	let testStoreConfig
	let loadStateSettings
	let conversationsListMock
	let fetchConversationsAction
	let addConversationAction
	let createOneToOneConversationAction

	/**
	 *
	 */
	function mountComponent() {
		return mount(LeftSidebar, {
			localVue,
			router,
			store,
			stubs: {
				// to prevent user status fetching
				Avatar: true,
				// to prevent complex dialog logic
				NewGroupConversation: true,
			},
		})
	}

	beforeEach(() => {
		jest.useFakeTimers()

		localVue = createLocalVue()
		localVue.use(Vuex)
		localVue.use(VueRouter)

		loadStateSettings = {
			circles_enabled: true,
			start_conversations: true,
		}

		loadState.mockImplementation((app, key) => {
			if (app === 'spreed') {
				return loadStateSettings[key]
			}
			return null
		})

		testStoreConfig = cloneDeep(storeConfig)

		// note: need a copy because the Vue modifies it when sorting
		conversationsListMock = jest.fn()
		fetchConversationsAction = jest.fn()
		addConversationAction = jest.fn()
		createOneToOneConversationAction = jest.fn()
		const getUserIdMock = jest.fn().mockReturnValue('current-user')
		testStoreConfig.modules.actorStore.getters.getUserId = () => getUserIdMock
		testStoreConfig.modules.conversationsStore.getters.conversationsList = conversationsListMock
		testStoreConfig.modules.conversationsStore.actions.fetchConversations = fetchConversationsAction
		testStoreConfig.modules.conversationsStore.actions.addConversation = addConversationAction
		testStoreConfig.modules.conversationsStore.actions.createOneToOneConversation = createOneToOneConversationAction

		store = new Vuex.Store(testStoreConfig)
	})

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

	describe('conversation list', () => {
		let conversationsList

		beforeEach(() => {
			conversationsList = [{
				id: 100,
				token: 't100',
				lastActivity: 100,
				isFavorite: false,
				name: 'one',
				displayName: 'one',
			}, {
				id: 200,
				token: 't200',
				lastActivity: 80,
				isFavorite: false,
				name: 'two',
				displayName: 'two',
			}, {
				id: 300,
				token: 't300',
				lastActivity: 120,
				isFavorite: true,
				name: 'three',
				displayName: 'three',
			}]

			// note: need a copy because the Vue modifies it when sorting
			conversationsListMock.mockImplementation(() => cloneDeep(conversationsList))
		})

		test('fetches and renders conversation list initially', async () => {
			const conversationsReceivedEvent = jest.fn()
			EventBus.$once('conversations-received', conversationsReceivedEvent)
			fetchConversationsAction.mockResolvedValueOnce()

			const wrapper = mountComponent()

			expect(fetchConversationsAction).toHaveBeenCalledWith(expect.anything(), undefined)
			expect(conversationsListMock).toHaveBeenCalled()

			const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })
			const listEl = appNavEl.findComponent({ name: 'ConversationsList' })

			expect(listEl.exists()).toBe(true)
			expect(listEl.props('searchText')).toBe('')
			expect(listEl.props('initialisedConversations')).toBe(false)

			expect(conversationsReceivedEvent).not.toHaveBeenCalled()

			// move on past the fetchConversation call
			await wrapper.vm.$nextTick()
			await wrapper.vm.$nextTick()

			expect(listEl.props('initialisedConversations')).toBe(true)
			expect(listEl.props('conversationsList')).toStrictEqual([
				conversationsList[2],
				conversationsList[0],
				conversationsList[1],
			])

			expect(conversationsReceivedEvent).toHaveBeenCalledWith({
				singleConversation: false,
			})
		})

		test('re-fetches conversations every 30 seconds', async () => {
			const wrapper = mountComponent()

			expect(fetchConversationsAction).toHaveBeenCalled()

			fetchConversationsAction.mockClear()

			// move past async call
			await wrapper.vm.$nextTick()
			await wrapper.vm.$nextTick()

			expect(fetchConversationsAction).not.toHaveBeenCalled()

			jest.advanceTimersByTime(15000)

			expect(fetchConversationsAction).not.toHaveBeenCalled()

			jest.advanceTimersByTime(20000)

			expect(fetchConversationsAction).toHaveBeenCalled()
		})

		test('re-fetches conversations when receiving bus event', async () => {
			const wrapper = mountComponent()

			expect(fetchConversationsAction).toHaveBeenCalled()

			fetchConversationsAction.mockClear()

			// move past async call
			await wrapper.vm.$nextTick()
			await wrapper.vm.$nextTick()

			expect(fetchConversationsAction).not.toHaveBeenCalled()

			EventBus.$emit('should-refresh-conversations')

			// note: debounce was short-circuited so no delay needed
			expect(fetchConversationsAction).toHaveBeenCalled()
		})
	})

	describe('search results', () => {
		let listedResults
		let usersResults
		let groupsResults
		let circlesResults
		let conversationsList

		beforeEach(() => {
			conversationsList = [{
				id: 100,
				token: 't100',
				lastActivity: 100,
				isFavorite: false,
				name: 'one',
				displayName: 'the searched one by display name',
				lastMessage: {},
			}, {
				id: 200,
				token: 't200',
				lastActivity: 80,
				isFavorite: false,
				name: 'searched by name',
				displayName: 'another one',
				lastMessage: {},
			}, {
				id: 300,
				token: 't300',
				lastActivity: 120,
				isFavorite: true,
				name: 'excluded',
				displayName: 'excluded from results',
				lastMessage: {},
			}]

			listedResults = [{
				id: 1000,
				name: 'listed one searched',
				displayName: 'listed one searched',
				lastMessage: {},
				token: 'listed-token-1',
			}, {
				id: 1001,
				name: 'listed two searched',
				displayName: 'listed two searched',
				lastMessage: {},
				token: 'listed-token-2',
			}]
			usersResults = [{
				id: 'current-user',
				label: 'Current User searched',
				source: 'users',
			}, {
				id: 'one-user',
				label: 'One user searched',
				source: 'users',
			}, {
				id: 'two-user',
				label: 'Two user searched',
				source: 'users',
			}]
			groupsResults = [{
				id: 'one-group',
				label: 'One group searched',
				source: 'groups',
			}, {
				id: 'two-group',
				label: 'Two group searched',
				source: 'groups',
			}]
			circlesResults = [{
				id: 'one-circle',
				label: 'One circle searched',
				source: 'circles',
			}, {
				id: 'two-circle',
				label: 'Two circle searched',
				source: 'circles',
			}]

			// note: need a copy because the Vue modifies it when sorting
			conversationsListMock.mockImplementation(() => cloneDeep(conversationsList))
			fetchConversationsAction.mockResolvedValue()
		})

		/**
		 * @param {string} searchTerm The search term to filter by
		 * @param {Array} possibleResults Result options returned by the APIs
		 * @param {Array} listedResults The displayed results
		 * @param {object} loadStateSettingsOverride Allows to override some properties
		 */
		async function testSearch(searchTerm, possibleResults, listedResults, loadStateSettingsOverride) {
			searchPossibleConversations.mockResolvedValueOnce({
				data: {
					ocs: {
						data: possibleResults,
					},
				},
			})
			searchListedConversations.mockResolvedValueOnce({
				data: {
					ocs: {
						data: listedResults,
					},
				},
			})

			if (loadStateSettingsOverride) {
				loadStateSettings = loadStateSettingsOverride
			}

			const wrapper = mountComponent()

			expect(fetchConversationsAction).toHaveBeenCalledWith(expect.anything(), undefined)
			expect(conversationsListMock).toHaveBeenCalled()

			const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })
			const searchBoxEl = appNavEl.findComponent({ name: 'SearchBox' })
			expect(searchBoxEl.exists()).toBe(true)

			// move past async call
			await wrapper.vm.$nextTick()
			await wrapper.vm.$nextTick()

			await searchBoxEl.find('input[type="text"]').setValue(searchTerm)
			expect(searchBoxEl.props('isSearching')).toBe(true)

			await wrapper.vm.$nextTick()
			await wrapper.vm.$nextTick()

			return wrapper
		}

		describe('displaying search results', () => {
			test('displays search results when search is active', async () => {
				const wrapper = await testSearch(
					'search',
					[...usersResults, ...groupsResults, ...circlesResults],
					listedResults,
					{
						circles_enabled: true,
						start_conversations: true,
					}
				)

				const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })

				const captionListEl = appNavEl.findAllComponents({ name: 'AppNavigationCaption' })

				expect(captionListEl.exists()).toBe(true)
				expect(captionListEl.length).toBe(5)
				expect(captionListEl.at(0).props('title')).toStrictEqual('Conversations')
				expect(captionListEl.at(1).props('title')).toStrictEqual('Open conversations')
				expect(captionListEl.at(2).props('title')).toStrictEqual('Users')
				expect(captionListEl.at(3).props('title')).toStrictEqual('Groups')
				expect(captionListEl.at(4).props('title')).toStrictEqual('Circles')

				const listEl = appNavEl.findComponent({ name: 'ConversationsList' })

				expect(listEl.exists()).toBe(true)
				expect(listEl.props('conversationsList')).toStrictEqual([
					conversationsList[0],
					conversationsList[1],
				])

				const listedEls = appNavEl.findAllComponents({ name: 'Conversation' })
				expect(listedEls.exists()).toBe(true)
				expect(listedEls.length).toBe(4)
				expect(listedEls.at(0).props('item')).toStrictEqual(conversationsList[0])
				expect(listedEls.at(1).props('item')).toStrictEqual(conversationsList[1])
				expect(listedEls.at(2).props('item')).toStrictEqual(listedResults[0])
				expect(listedEls.at(3).props('item')).toStrictEqual(listedResults[1])

				const optionsEls = appNavEl.findAllComponents({ name: 'ConversationsOptionsList' })
				expect(optionsEls.exists()).toBe(true)
				expect(optionsEls.length).toBe(3)
				expect(optionsEls.at(0).props('items')).toStrictEqual([usersResults[1], usersResults[2]])
				expect(optionsEls.at(1).props('items')).toStrictEqual([groupsResults[0], groupsResults[1]])
				expect(optionsEls.at(2).props('items')).toStrictEqual([circlesResults[0], circlesResults[1]])
			})
			test('only shows user search results when cannot create conversations', async () => {
				const wrapper = await testSearch(
					'search',
					[...usersResults, ...groupsResults, ...circlesResults],
					listedResults,
					{
						circles_enabled: true,
						start_conversations: false,
					}
				)

				const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })

				const captionListEl = appNavEl.findAllComponents({ name: 'AppNavigationCaption' })

				expect(captionListEl.exists()).toBe(true)
				expect(captionListEl.length).toBe(3)
				expect(captionListEl.at(0).props('title')).toStrictEqual('Conversations')
				expect(captionListEl.at(1).props('title')).toStrictEqual('Open conversations')
				expect(captionListEl.at(2).props('title')).toStrictEqual('Users')

				const listEl = appNavEl.findComponent({ name: 'ConversationsList' })

				expect(listEl.exists()).toBe(true)
				expect(listEl.props('conversationsList')).toStrictEqual([
					conversationsList[0],
					conversationsList[1],
				])

				const listedEls = appNavEl.findAllComponents({ name: 'Conversation' })
				expect(listedEls.exists()).toBe(true)
				expect(listedEls.length).toBe(4)
				expect(listedEls.at(0).props('item')).toStrictEqual(conversationsList[0])
				expect(listedEls.at(1).props('item')).toStrictEqual(conversationsList[1])
				expect(listedEls.at(2).props('item')).toStrictEqual(listedResults[0])
				expect(listedEls.at(3).props('item')).toStrictEqual(listedResults[1])

				const optionsEls = appNavEl.findAllComponents({ name: 'ConversationsOptionsList' })
				expect(optionsEls.exists()).toBe(true)
				expect(optionsEls.at(0).props('items')).toStrictEqual([usersResults[1], usersResults[2]])
				expect(optionsEls.length).toBe(1)
			})
			test('does not show circles results when circles are disabled', async () => {
				const wrapper = await testSearch(
					'search',
					[...usersResults, ...groupsResults],
					listedResults,
					{
						circles_enabled: false,
						start_conversations: true,
					}
				)

				const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })

				const captionListEl = appNavEl.findAllComponents({ name: 'AppNavigationCaption' })

				expect(captionListEl.exists()).toBe(true)
				expect(captionListEl.length).toBe(4)
				expect(captionListEl.at(0).props('title')).toStrictEqual('Conversations')
				expect(captionListEl.at(1).props('title')).toStrictEqual('Open conversations')
				expect(captionListEl.at(2).props('title')).toStrictEqual('Users')
				expect(captionListEl.at(3).props('title')).toStrictEqual('Groups')

				const listEl = appNavEl.findComponent({ name: 'ConversationsList' })

				expect(listEl.exists()).toBe(true)
				expect(listEl.props('conversationsList')).toStrictEqual([
					conversationsList[0],
					conversationsList[1],
				])

				const listedEls = appNavEl.findAllComponents({ name: 'Conversation' })
				expect(listedEls.exists()).toBe(true)
				expect(listedEls.length).toBe(4)
				expect(listedEls.at(0).props('item')).toStrictEqual(conversationsList[0])
				expect(listedEls.at(1).props('item')).toStrictEqual(conversationsList[1])
				expect(listedEls.at(2).props('item')).toStrictEqual(listedResults[0])
				expect(listedEls.at(3).props('item')).toStrictEqual(listedResults[1])

				const optionsEls = appNavEl.findAllComponents({ name: 'ConversationsOptionsList' })
				expect(optionsEls.exists()).toBe(true)
				expect(optionsEls.length).toBe(2)
				expect(optionsEls.at(0).props('items')).toStrictEqual([usersResults[1], usersResults[2]])
				expect(optionsEls.at(1).props('items')).toStrictEqual([groupsResults[0], groupsResults[1]])
			})
		})

		describe('not found caption', () => {
			/**
			 * @param {string} searchTerm The search term to filter by
			 * @param {Array} possibleResults Result options returned by the APIs
			 * @param {Array} listedResults The displayed results
			 * @param {object} loadStateSettingsOverride Allows to override some properties
			 * @param {string} expectedCaption The caption of the "No results found" section
			 */
			async function testSearchNotFound(searchTerm, possibleResults, listedResults, loadStateSettingsOverride, expectedCaption) {
				const wrapper = await testSearch(searchTerm, possibleResults, listedResults, loadStateSettingsOverride)

				const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })
				const listEl = appNavEl.findComponent({ name: 'ConversationsList' })
				expect(listEl.exists()).toBe(true)
				const listedEls = appNavEl.findAllComponents({ name: 'Conversation' })
				expect(listedEls.exists()).toBe(true)
				expect(listedEls.length).toBe(2 + listedResults.length)
				// only filters the existing conversations in the list
				expect(listedEls.at(0).props('item')).toStrictEqual(conversationsList[0])
				expect(listedEls.at(1).props('item')).toStrictEqual(conversationsList[1])

				const captionsEls = appNavEl.findAllComponents({ name: 'AppNavigationCaption' })
				expect(captionsEls.exists()).toBe(true)
				if (listedResults.length > 0) {
					expect(captionsEls.length).toBeGreaterThan(2)
					expect(captionsEls.at(0).props('title')).toBe('Conversations')
					expect(captionsEls.at(1).props('title')).toBe('Open conversations')
				} else {
					expect(captionsEls.length).toBeGreaterThan(1)
					expect(captionsEls.at(0).props('title')).toBe('Conversations')
				}
				// last dynamic caption for "No search results"
				expect(captionsEls.at(captionsEls.length - 1).props('title')).toBe(expectedCaption)

				return wrapper
			}

			test('displays all types in caption when nothing was found', async () => {
				await testSearchNotFound(
					'search',
					[],
					[],
					{
						circles_enabled: true,
						start_conversations: true,
					},
					'Users, groups and circles'
				)
			})

			test('displays all types in caption when only listed conversations were found', async () => {
				await testSearchNotFound(
					'search',
					[],
					listedResults,
					{
						circles_enabled: true,
						start_conversations: true,
					},
					'Users, groups and circles'
				)
			})

			test('displays all types minus circles when nothing was found but circles is disabled', async () => {
				await testSearchNotFound(
					'search',
					[],
					[],
					{
						circles_enabled: false,
						start_conversations: true,
					},
					'Users and groups'
				)
			})

			test('displays caption for users and groups not found', async () => {
				await testSearchNotFound(
					'search',
					[...circlesResults],
					[],
					{
						circles_enabled: true,
						start_conversations: true,
					},
					'Users and groups'
				)
			})
			test('displays caption for users not found', async () => {
				await testSearchNotFound(
					'search',
					[...circlesResults, ...groupsResults],
					[],
					{
						circles_enabled: true,
						start_conversations: true,
					},
					'Users'
				)
			})
			test('displays caption for groups not found', async () => {
				await testSearchNotFound(
					'search',
					[...usersResults, ...circlesResults],
					[],
					{
						circles_enabled: true,
						start_conversations: true,
					},
					'Groups'
				)
			})
			test('displays caption for groups and circles not found', async () => {
				await testSearchNotFound(
					'search',
					[...usersResults],
					[],
					{
						circles_enabled: true,
						start_conversations: true,
					},
					'Groups and circles'
				)
			})
			test('displays caption for users and circles not found', async () => {
				await testSearchNotFound(
					'search',
					[...groupsResults],
					[],
					{
						circles_enabled: true,
						start_conversations: true,
					},
					'Users and circles'
				)
			})
		})

		describe('clicking search results', () => {
			test('joins listed conversation from search result', async () => {
				const wrapper = await testSearch('search', [], listedResults)

				const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })
				const listedEls = appNavEl.findAllComponents({ name: 'Conversation' })
				expect(listedEls.exists()).toBe(true)
				expect(listedEls.length).toBe(4)
				await listedEls.at(3).find('a').trigger('click')

				expect(addConversationAction).toHaveBeenCalledWith(expect.anything(), listedResults[1])
				expect(wrapper.vm.$route.name).toBe('conversation')
				expect(wrapper.vm.$route.params).toStrictEqual({ token: 'listed-token-2' })
			})
			test('creates one to one conversation from user search result', async () => {
				createOneToOneConversationAction.mockResolvedValue({
					id: 9999,
					token: 'new-conversation',
				})

				const wrapper = await testSearch('search', [...usersResults], [])

				const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })
				const optionsEls = appNavEl.findAllComponents({ name: 'ConversationsOptionsList' })
				expect(optionsEls.exists()).toBe(true)
				await optionsEls.at(0).findAll('a').at(1).trigger('click')

				expect(createOneToOneConversationAction).toHaveBeenCalledWith(expect.anything(), 'two-user')
				expect(wrapper.vm.$route.name).toBe('conversation')
				expect(wrapper.vm.$route.params).toStrictEqual({ token: 'new-conversation' })
			})
			test('shows group conversation dialog when clicking search result', async () => {
				const eventHandler = jest.fn()
				EventBus.$once('new-group-conversation-dialog', eventHandler)

				const wrapper = await testSearch('search', [...groupsResults], [])

				const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })
				const optionsEls = appNavEl.findAllComponents({ name: 'ConversationsOptionsList' })
				expect(optionsEls.exists()).toBe(true)
				await optionsEls.at(0).findAll('a').at(1).trigger('click')

				expect(eventHandler).toHaveBeenCalledWith(groupsResults[1])

				// nothing created yet
				expect(createOneToOneConversationAction).not.toHaveBeenCalled()
				expect(addConversationAction).not.toHaveBeenCalled()
			})
			test('shows circles conversation dialog when clicking search result', async () => {
				const eventHandler = jest.fn()
				EventBus.$once('new-group-conversation-dialog', eventHandler)

				const wrapper = await testSearch('search', [...circlesResults], [])

				const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })
				const optionsEls = appNavEl.findAllComponents({ name: 'ConversationsOptionsList' })
				expect(optionsEls.exists()).toBe(true)
				await optionsEls.at(0).findAll('a').at(1).trigger('click')

				expect(eventHandler).toHaveBeenCalledWith(circlesResults[1])

				// nothing created yet
				expect(createOneToOneConversationAction).not.toHaveBeenCalled()
			})
			test('clears search results when joining user chat', async () => {
				createOneToOneConversationAction.mockResolvedValue({
					id: 9999,
					token: 'new-conversation',
				})

				const wrapper = await testSearch('search', [...usersResults], [])

				const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })
				const searchBoxEl = appNavEl.findComponent({ name: 'SearchBox' })
				const input = searchBoxEl.find('input[type="text"]')
				expect(input.element.value).toBe('search')

				const optionsEls = appNavEl.findAllComponents({ name: 'ConversationsOptionsList' })
				expect(optionsEls.exists()).toBe(true)
				await optionsEls.at(0).findAll('a').at(1).trigger('click')

				await wrapper.vm.$nextTick()

				expect(searchBoxEl.exists()).toBe(true)
				expect(input.element.value).toBe('')
			})
			test('does not clear search results when clicking group chat', async () => {
				const wrapper = await testSearch('search', [...groupsResults], [])

				const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })
				const searchBoxEl = appNavEl.findComponent({ name: 'SearchBox' })
				const input = searchBoxEl.find('input[type="text"]')
				expect(input.element.value).toBe('search')

				const optionsEls = appNavEl.findAllComponents({ name: 'ConversationsOptionsList' })
				expect(optionsEls.exists()).toBe(true)
				await optionsEls.at(0).findAll('a').at(1).trigger('click')

				await wrapper.vm.$nextTick()

				expect(searchBoxEl.exists()).toBe(true)
				expect(input.element.value).toBe('search')
			})
		})
	})

	describe('new conversation button', () => {
		beforeEach(() => {
			conversationsListMock.mockReturnValue([])
			fetchConversationsAction.mockResolvedValueOnce()
		})
		test('shows new conversation button if user can start conversations', () => {
			loadStateSettings.start_conversations = true

			const wrapper = mountComponent()
			const buttonEl = wrapper.findComponent({ name: 'NewGroupConversation' })
			expect(buttonEl.exists()).toBe(true)
		})
		test('does not show new conversation button if user cannot start conversations', () => {
			loadStateSettings.start_conversations = false

			const wrapper = mountComponent()
			const buttonEl = wrapper.findComponent({ name: 'NewGroupConversation' })
			expect(buttonEl.exists()).toBe(false)
		})
	})

	test('shows settings when clicking the settings button', async () => {
		conversationsListMock.mockImplementation(() => [])
		const eventHandler = jest.fn()
		subscribe('show-settings', eventHandler)
		const wrapper = mountComponent()

		const appNavEl = wrapper.findComponent({ name: 'AppNavigation' })
		const button = appNavEl.find('.settings-button')
		expect(button.exists()).toBe(true)

		await button.trigger('click')

		unsubscribe('show-settings', eventHandler)

		expect(eventHandler).toHaveBeenCalled()
	})
})