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
|
import mockAxios from '../__mocks__/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { shallowMount } from '@vue/test-utils'
import { CONVERSATION } from '../constants'
import RoomSelector from './RoomSelector'
describe('RoomSelector.vue', () => {
let conversations
beforeEach(() => {
conversations = [{
token: 'token-3',
displayName: 'zzz',
type: CONVERSATION.TYPE.ONE_TO_ONE,
lastActivity: 3,
isFavorite: false,
readOnly: CONVERSATION.STATE.READ_WRITE,
}, {
token: 'token-1',
displayName: 'conversation one',
type: CONVERSATION.TYPE.PUBLIC,
lastActivity: 1,
isFavorite: true,
readOnly: CONVERSATION.STATE.READ_WRITE,
}, {
token: 'token-2',
displayName: 'abc',
type: CONVERSATION.TYPE.GROUP,
lastActivity: 2,
isFavorite: false,
readOnly: CONVERSATION.STATE.READ_ONLY,
}, {
// all entries below will be filtered out
token: 'token-changelog',
displayName: 'changelog',
type: CONVERSATION.TYPE.CHANGELOG,
}, {
token: 'current-token',
displayName: 'current room',
type: CONVERSATION.TYPE.GROUP,
}, {
token: 'token-password',
displayName: 'share password room',
type: CONVERSATION.TYPE.ONE_TO_ONE,
objectType: 'share:password',
}, {
token: 'token-file',
displayName: 'file room',
type: CONVERSATION.TYPE.GROUP,
objectType: 'file',
}]
global.OCA.Talk = {
instance: {
$store: {
getters: {
getToken: jest.fn().mockReturnValue('current-token'),
},
},
},
}
})
afterEach(() => {
mockAxios.reset()
jest.clearAllMocks()
})
test('renders sorted conversation list fetched from server', async () => {
const wrapper = shallowMount(RoomSelector)
expect(mockAxios.get).toHaveBeenCalledWith(
generateOcsUrl('/apps/spreed/api/v4/room')
)
mockAxios.mockResponse({
data: {
ocs: {
data: conversations,
},
},
})
// need to wait for re-render, otherwise the list is not rendered yet
await wrapper.vm.$nextTick()
const list = wrapper.findAll('li')
expect(list.length).toBe(3)
expect(list.at(0).text()).toBe('conversation one')
expect(list.at(1).text()).toBe('zzz')
expect(list.at(2).text()).toBe('abc')
})
test('excludes non-postable conversations', async () => {
const wrapper = shallowMount(RoomSelector, {
propsData: {
showPostableOnly: true,
},
})
expect(mockAxios.get).toHaveBeenCalledWith(
generateOcsUrl('/apps/spreed/api/v4/room')
)
mockAxios.mockResponse({
data: {
ocs: {
data: conversations,
},
},
})
// need to wait for re-render, otherwise the list is not rendered yet
await wrapper.vm.$nextTick()
const list = wrapper.findAll('li')
expect(list.length).toBe(2)
expect(list.at(0).text()).toBe('conversation one')
expect(list.at(1).text()).toBe('zzz')
})
test('emits select event on select', async () => {
const wrapper = shallowMount(RoomSelector)
expect(mockAxios.get).toHaveBeenCalledWith(
generateOcsUrl('/apps/spreed/api/v4/room')
)
mockAxios.mockResponse({
data: {
ocs: {
data: conversations,
},
},
})
await wrapper.vm.$nextTick()
const eventHandler = jest.fn()
wrapper.vm.$root.$on('select', eventHandler)
const list = wrapper.findAll('li')
await list.at(1).trigger('click')
await wrapper.find('button').trigger('click')
expect(eventHandler).toHaveBeenCalledWith('token-3')
})
test('emits close event', async () => {
const wrapper = shallowMount(RoomSelector)
const eventHandler = jest.fn()
wrapper.vm.$root.$on('close', eventHandler)
await wrapper.findComponent({ name: 'Modal' }).vm.$emit('close')
expect(eventHandler).toHaveBeenCalled()
})
})
|