@@ -632,4 +632,74 @@ describe('A bookmark', function () {
632632 </iq>` ) ;
633633 } )
634634 ) ;
635+
636+ it ( "can be unpinned and sends out a stanza" , mock . initConverse (
637+ [ 'connected' , 'chatBoxesFetched' ] , { } , async function ( _converse ) {
638+ await mock . waitForRoster ( _converse , 'current' , 0 ) ;
639+ await mock . waitUntilBookmarksReturned ( _converse ) ;
640+
641+ const bare_jid = _converse . session . get ( 'bare_jid' ) ;
642+ const muc_jid = 'theplay@conference.shakespeare.lit' ;
643+ const { api, state } = _converse ;
644+
645+ // First create a pinned bookmark
646+ const bookmark = state . bookmarks . create ( {
647+ jid : muc_jid ,
648+ autojoin : true ,
649+ name : 'The Play' ,
650+ nick : 'romeo' ,
651+ extensions : [ '<pinned xmlns="urn:xmpp:bookmarks-pinning:0"/>' ] ,
652+ } ) ;
653+
654+ await mock . waitForMUCDiscoInfo ( _converse , muc_jid ) ;
655+ await u . waitUntil ( ( ) => state . chatboxes . length === 1 ) ;
656+
657+ const IQ_stanzas = api . connection . get ( ) . IQ_stanzas ;
658+
659+ expect ( bookmark . pinned ) . toBe ( true ) ;
660+ expect ( state . chatboxes . get ( muc_jid ) . get ( 'pinned' ) ) . toBe ( true ) ;
661+
662+ // Now unpin the bookmark
663+ await state . bookmarks . unpinBookmark ( bookmark ) ;
664+
665+ const sent_stanza = await u . waitUntil ( ( ) =>
666+ IQ_stanzas . filter ( ( s ) => sizzle ( 'publish[node="urn:xmpp:bookmarks:1"] conference[name="The Play"]' , s ) . length ) . pop ( )
667+ ) ;
668+
669+ expect ( bookmark . pinned ) . toBe ( false ) ;
670+ expect ( state . chatboxes . get ( muc_jid ) . get ( 'pinned' ) ) . toBe ( false ) ;
671+
672+ expect ( sent_stanza ) . toEqualStanza ( stx `
673+ <iq from="${ bare_jid } " to="${ bare_jid } " id="${ sent_stanza . getAttribute ( 'id' ) } " type="set" xmlns="jabber:client">
674+ <pubsub xmlns="http://jabber.org/protocol/pubsub">
675+ <publish node="urn:xmpp:bookmarks:1">
676+ <item id="${ muc_jid } ">
677+ <conference xmlns="urn:xmpp:bookmarks:1" autojoin="true" name="The Play">
678+ <nick>romeo</nick>
679+ </conference>
680+ </item>
681+ </publish>
682+ <publish-options>
683+ <x type="submit" xmlns="jabber:x:data">
684+ <field type="hidden" var="FORM_TYPE">
685+ <value>http://jabber.org/protocol/pubsub#publish-options</value>
686+ </field>
687+ <field var='pubsub#persist_items'>
688+ <value>true</value>
689+ </field>
690+ <field var='pubsub#max_items'>
691+ <value>max</value>
692+ </field>
693+ <field var='pubsub#send_last_published_item'>
694+ <value>never</value>
695+ </field>
696+ <field var='pubsub#access_model'>
697+ <value>whitelist</value>
698+ </field>
699+ </x>
700+ </publish-options>
701+ </pubsub>
702+ </iq>` ) ;
703+ } )
704+ ) ;
635705} ) ;
0 commit comments