|
@@ -1,9 +1,12 @@
|
1
|
|
-import { parser } from './ChatRoom';
|
|
1
|
+import ChatRoom, { parser } from './ChatRoom';
|
2
|
2
|
import { $pres } from 'strophe.js';
|
|
3
|
+import XMPPEvents from '../../service/xmpp/XMPPEvents';
|
3
|
4
|
|
4
|
5
|
// This rule makes creating the xml elements take up way more
|
5
|
6
|
// space than necessary.
|
6
|
7
|
/* eslint-disable newline-per-chained-call */
|
|
8
|
+// These rules makes the xml strings harder to read
|
|
9
|
+/* eslint-disable operator-linebreak, max-len */
|
7
|
10
|
|
8
|
11
|
describe('ChatRoom', () => {
|
9
|
12
|
describe('packet2JSON', () => {
|
|
@@ -126,4 +129,103 @@ describe('ChatRoom', () => {
|
126
|
129
|
expect(identity.value).toBeFalsy();
|
127
|
130
|
});
|
128
|
131
|
});
|
|
132
|
+
|
|
133
|
+ describe('onPresence', () => {
|
|
134
|
+ let room;
|
|
135
|
+ let emitterSpy;
|
|
136
|
+
|
|
137
|
+ beforeEach(() => {
|
|
138
|
+ const xmpp = {
|
|
139
|
+ options: {}
|
|
140
|
+ };
|
|
141
|
+
|
|
142
|
+ room = new ChatRoom(
|
|
143
|
+ {} /* connection */,
|
|
144
|
+ 'jid',
|
|
145
|
+ 'password',
|
|
146
|
+ xmpp,
|
|
147
|
+ {} /* options */);
|
|
148
|
+ emitterSpy = spyOn(room.eventEmitter, 'emit');
|
|
149
|
+ });
|
|
150
|
+ it('parses status correctly', () => {
|
|
151
|
+ const presStr = '' +
|
|
152
|
+ '<presence to="tojid" from="fromjid">' +
|
|
153
|
+ '<status>status-text</status>' +
|
|
154
|
+ '</presence>';
|
|
155
|
+ const pres = new DOMParser().parseFromString(presStr, 'text/xml').documentElement;
|
|
156
|
+
|
|
157
|
+ room.onPresence(pres);
|
|
158
|
+ expect(emitterSpy.calls.count()).toEqual(1);
|
|
159
|
+ expect(emitterSpy).toHaveBeenCalledWith(
|
|
160
|
+ XMPPEvents.MUC_MEMBER_JOINED,
|
|
161
|
+ 'fromjid',
|
|
162
|
+ undefined, // nick
|
|
163
|
+ undefined, // role
|
|
164
|
+ undefined, // isHiddenDomain
|
|
165
|
+ undefined, // statsID
|
|
166
|
+ 'status-text',
|
|
167
|
+ undefined);
|
|
168
|
+ });
|
|
169
|
+
|
|
170
|
+ it('parses muc user item correctly', () => {
|
|
171
|
+ const presStr = '' +
|
|
172
|
+ '<presence to="tojid" from="fromjid">' +
|
|
173
|
+ '<x xmlns="http://jabber.org/protocol/muc#user">' +
|
|
174
|
+ '<item jid="jid=attr" affiliation="affiliation-attr" role="role-attr"/>' +
|
|
175
|
+ '</x>' +
|
|
176
|
+ '</presence>';
|
|
177
|
+ const pres = new DOMParser().parseFromString(presStr, 'text/xml').documentElement;
|
|
178
|
+
|
|
179
|
+ room.onPresence(pres);
|
|
180
|
+ expect(emitterSpy.calls.count()).toEqual(1);
|
|
181
|
+ expect(emitterSpy).toHaveBeenCalledWith(
|
|
182
|
+ XMPPEvents.MUC_MEMBER_JOINED,
|
|
183
|
+ 'fromjid',
|
|
184
|
+ undefined, // nick
|
|
185
|
+ 'role-attr', // role
|
|
186
|
+ jasmine.any(Boolean), // isHiddenDomain
|
|
187
|
+ undefined, // statsID
|
|
188
|
+ undefined,
|
|
189
|
+ undefined);
|
|
190
|
+ });
|
|
191
|
+
|
|
192
|
+ it('parses identity correctly', () => {
|
|
193
|
+ const presStr = '' +
|
|
194
|
+ '<presence to="tojid" from="fromjid">' +
|
|
195
|
+ '<status>status-text</status>' +
|
|
196
|
+ '<identity>' +
|
|
197
|
+ '<user>' +
|
|
198
|
+ '<id>id-text</id>' +
|
|
199
|
+ '<name>name-text</name>' +
|
|
200
|
+ '<avatar>avatar-text</avatar>' +
|
|
201
|
+ '</user>' +
|
|
202
|
+ '<group>group-text</group>' +
|
|
203
|
+ '</identity>' +
|
|
204
|
+ '</presence>';
|
|
205
|
+ const pres = new DOMParser().parseFromString(presStr, 'text/xml').documentElement;
|
|
206
|
+
|
|
207
|
+ const expectedIdentity = {
|
|
208
|
+ user: {
|
|
209
|
+ id: 'id-text',
|
|
210
|
+ name: 'name-text',
|
|
211
|
+ avatar: 'avatar-text'
|
|
212
|
+ },
|
|
213
|
+ group: 'group-text'
|
|
214
|
+ };
|
|
215
|
+
|
|
216
|
+ room.onPresence(pres);
|
|
217
|
+ expect(emitterSpy.calls.count()).toEqual(1);
|
|
218
|
+ expect(emitterSpy).toHaveBeenCalledWith(
|
|
219
|
+ XMPPEvents.MUC_MEMBER_JOINED,
|
|
220
|
+ 'fromjid',
|
|
221
|
+ undefined, // nick
|
|
222
|
+ undefined, // role
|
|
223
|
+ undefined, // isHiddenDomain
|
|
224
|
+ undefined, // statsID
|
|
225
|
+ 'status-text',
|
|
226
|
+ expectedIdentity);
|
|
227
|
+ });
|
|
228
|
+
|
|
229
|
+ });
|
129
|
230
|
});
|
|
231
|
+
|