From cac04d076a07a10330b966ac3a464fa10f2358c2 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sun, 21 Jan 2018 19:34:49 +0100 Subject: [PATCH] Remove jquery as a dependency in MAM spec --- spec/mam.js | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/spec/mam.js b/spec/mam.js index 8472c4ce1..cbc6bd691 100644 --- a/spec/mam.js +++ b/spec/mam.js @@ -1,6 +1,6 @@ (function (root, factory) { - define(["jquery", "jasmine", "mock", "converse-core", "test-utils"], factory); -} (this, function ($, jasmine, mock, converse, test_utils) { + define(["jasmine", "mock", "converse-core", "test-utils"], factory); +} (this, function (jasmine, mock, converse, test_utils) { "use strict"; var _ = converse.env._; var Backbone = converse.env.Backbone; @@ -63,7 +63,7 @@ _converse.disco_entities.get(_converse.domain).features.create({'var': Strophe.NS.MAM}); } _converse.api.archive.query(); - var queryid = $(sent_stanza.toString()).find('query').attr('queryid'); + var queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid'); expect(sent_stanza.toString()).toBe( ""); done(); @@ -80,7 +80,35 @@ _converse.disco_entities.get(_converse.domain).features.create({'var': Strophe.NS.MAM}); } _converse.api.archive.query({'with':'juliet@capulet.lit'}); - var queryid = $(sent_stanza.toString()).find('query').attr('queryid'); + var queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid'); + expect(sent_stanza.toString()).toBe( + ""+ + ""+ + ""+ + ""+ + "urn:xmpp:mam:2"+ + ""+ + ""+ + "juliet@capulet.lit"+ + ""+ + ""+ + ""+ + "" + ); + })); + + it("checks whether returned messages are from the right JID", mock.initConverse(function (_converse) { + var sent_stanza, IQ_id; + var sendIQ = _converse.connection.sendIQ; + spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { + sent_stanza = iq; + IQ_id = sendIQ.bind(this)(iq, callback, errback); + }); + if (!_converse.disco_entities.get(_converse.domain).features.findWhere({'var': Strophe.NS.MAM})) { + _converse.disco_entities.get(_converse.domain).features.create({'var': Strophe.NS.MAM}); + } + _converse.api.archive.query({'with':'juliet@capulet.lit'}); + var queryid = sent_stanza.toString().querySelector('query').getAttribute('queryid'); expect(sent_stanza.toString()).toBe( ""+ ""+ @@ -114,7 +142,7 @@ 'end': end }); - var queryid = $(sent_stanza.toString()).find('query').attr('queryid'); + var queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid'); expect(sent_stanza.toString()).toBe( ""+ ""+ @@ -155,7 +183,7 @@ } var start = '2010-06-07T00:00:00Z'; _converse.api.archive.query({'start': start}); - var queryid = $(sent_stanza.toString()).find('query').attr('queryid'); + var queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid'); expect(sent_stanza.toString()).toBe( ""+ ""+ @@ -184,7 +212,7 @@ } var start = '2010-06-07T00:00:00Z'; _converse.api.archive.query({'start': start, 'max':10}); - var queryid = $(sent_stanza.toString()).find('query').attr('queryid'); + var queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid'); expect(sent_stanza.toString()).toBe( ""+ ""+ @@ -220,7 +248,7 @@ 'after': '09af3-cc343-b409f', 'max':10 }); - var queryid = $(sent_stanza.toString()).find('query').attr('queryid'); + var queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid'); expect(sent_stanza.toString()).toBe( ""+ ""+ @@ -252,7 +280,7 @@ _converse.disco_entities.get(_converse.domain).features.create({'var': Strophe.NS.MAM}); } _converse.api.archive.query({'before': '', 'max':10}); - var queryid = $(sent_stanza.toString()).find('query').attr('queryid'); + var queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid'); expect(sent_stanza.toString()).toBe( ""+ ""+ @@ -289,7 +317,7 @@ rsm.start = '2010-06-07T00:00:00Z'; _converse.api.archive.query(rsm); - var queryid = $(sent_stanza.toString()).find('query').attr('queryid'); + var queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid'); expect(sent_stanza.toString()).toBe( ""+ ""+ @@ -325,7 +353,7 @@ var callback = jasmine.createSpy('callback'); _converse.api.archive.query({'with': 'romeo@capulet.lit', 'max':'10'}, callback); - var queryid = $(sent_stanza.toString()).find('query').attr('queryid'); + var queryid = sent_stanza.nodeTree.querySelector('query').getAttribute('queryid'); /* *