-
-
Notifications
You must be signed in to change notification settings - Fork 771
/
bookmarks.js
118 lines (102 loc) · 4.97 KB
/
bookmarks.js
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
/* global mock, converse */
describe("A chat room", function () {
describe("when autojoin is set", function () {
it("will be be opened and joined automatically upon login", mock.initConverse(
[], {}, async function (_converse) {
await mock.waitForRoster(_converse, 'current', 0);
await mock.waitUntilBookmarksReturned(_converse);
spyOn(_converse.api.rooms, 'create').and.callThrough();
const jid = 'theplay@conference.shakespeare.lit';
const { bookmarks } = _converse.state;
const model = bookmarks.create({
'jid': jid,
'autojoin': false,
'name': 'The Play',
'nick': ''
});
expect(_converse.api.rooms.create).not.toHaveBeenCalled();
bookmarks.remove(model);
bookmarks.create({
'jid': jid,
'autojoin': true,
'name': 'Hamlet',
'nick': ''
});
expect(_converse.api.rooms.create).toHaveBeenCalled();
}));
});
});
describe("A bookmark", function () {
it("can be created and sends out a stanza", mock.initConverse(
['connected', 'chatBoxesFetched'], {}, async function (_converse) {
await mock.waitForRoster(_converse, 'current', 0);
await mock.waitUntilBookmarksReturned(_converse);
const jid = _converse.session.get('jid');
const muc1_jid = 'theplay@conference.shakespeare.lit';
const { Strophe, sizzle, u } = converse.env;
const { bookmarks } = _converse.state;
bookmarks.createBookmark({
jid: muc1_jid,
autojoin: true,
name: 'Hamlet',
nick: ''
});
const IQ_stanzas = _converse.api.connection.get().IQ_stanzas;
let sent_stanza = await u.waitUntil(
() => IQ_stanzas.filter(s => sizzle('item[id="current"]', s).length).pop());
expect(Strophe.serialize(sent_stanza)).toBe(
`<iq from="${jid}" id="${sent_stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
'<publish node="storage:bookmarks">'+
'<item id="current">'+
'<storage xmlns="storage:bookmarks">'+
`<conference autojoin="true" jid="${muc1_jid}" name="Hamlet"/>`+
'</storage>'+
'</item>'+
'</publish>'+
'<publish-options>'+
'<x type="submit" xmlns="jabber:x:data">'+
'<field type="hidden" var="FORM_TYPE">'+
'<value>http://jabber.org/protocol/pubsub#publish-options</value>'+
'</field>'+
'<field var="pubsub#persist_items"><value>true</value></field>'+
'<field var="pubsub#access_model"><value>whitelist</value></field>'+
'</x>'+
'</publish-options>'+
'</pubsub>'+
'</iq>');
const muc2_jid = 'balcony@conference.shakespeare.lit';
bookmarks.createBookmark({
jid: muc2_jid,
autojoin: true,
name: 'Balcony',
nick: 'romeo'
});
sent_stanza = await u.waitUntil(
() => IQ_stanzas.filter(s => sizzle('item[id="current"] conference[name="Balcony"]', s).length).pop());
expect(Strophe.serialize(sent_stanza)).toBe(
`<iq from="${jid}" id="${sent_stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
'<publish node="storage:bookmarks">'+
'<item id="current">'+
'<storage xmlns="storage:bookmarks">'+
`<conference autojoin="true" jid="${muc2_jid}" name="Balcony">`+
'<nick>romeo</nick>'+
'</conference>'+
`<conference autojoin="true" jid="${muc1_jid}" name="Hamlet"/>`+
'</storage>'+
'</item>'+
'</publish>'+
'<publish-options>'+
'<x type="submit" xmlns="jabber:x:data">'+
'<field type="hidden" var="FORM_TYPE">'+
'<value>http://jabber.org/protocol/pubsub#publish-options</value>'+
'</field>'+
'<field var="pubsub#persist_items"><value>true</value></field>'+
'<field var="pubsub#access_model"><value>whitelist</value></field>'+
'</x>'+
'</publish-options>'+
'</pubsub>'+
'</iq>');
}));
});