12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878 |
- (function (root, factory) {
- define(["jquery", "jasmine", "mock", "test-utils" ], factory);
- } (this, function ($, jasmine, mock, test_utils) {
- const _ = converse.env._,
- $pres = converse.env.$pres,
- $iq = converse.env.$iq,
- $msg = converse.env.$msg,
- Strophe = converse.env.Strophe,
- Promise = converse.env.Promise,
- moment = converse.env.moment,
- sizzle = converse.env.sizzle,
- Backbone = converse.env.Backbone,
- u = converse.env.utils;
- describe("Chatrooms", function () {
- describe("The \"rooms\" API", function () {
- it("has a method 'close' which closes rooms by JID or all rooms when called with no arguments",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy')
- .then(() => test_utils.openAndEnterChatRoom(_converse, 'leisure', 'localhost', 'dummy'))
- .then(() => test_utils.openAndEnterChatRoom(_converse, 'news', 'localhost', 'dummy'))
- .then(() => {
- expect(u.isVisible(_converse.chatboxviews.get('lounge@localhost').el)).toBeTruthy();
- expect(u.isVisible(_converse.chatboxviews.get('leisure@localhost').el)).toBeTruthy();
- expect(u.isVisible(_converse.chatboxviews.get('news@localhost').el)).toBeTruthy();
- // XXX: bit of a cheat here. We want `cleanup()` to be
- // called on the room. Either it's this or faking
- // `sendPresence`.
- _converse.connection.connected = false;
- _converse.api.roomviews.close('lounge@localhost');
- expect(_converse.chatboxviews.get('lounge@localhost')).toBeUndefined();
- expect(u.isVisible(_converse.chatboxviews.get('leisure@localhost').el)).toBeTruthy();
- expect(u.isVisible(_converse.chatboxviews.get('news@localhost').el)).toBeTruthy();
- _converse.api.roomviews.close(['leisure@localhost', 'news@localhost']);
- expect(_converse.chatboxviews.get('lounge@localhost')).toBeUndefined();
- expect(_converse.chatboxviews.get('leisure@localhost')).toBeUndefined();
- expect(_converse.chatboxviews.get('news@localhost')).toBeUndefined();
- return test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
- })
- .then(() => test_utils.openAndEnterChatRoom(_converse, 'leisure', 'localhost', 'dummy'))
- .then(() => {
- expect(u.isVisible(_converse.chatboxviews.get('lounge@localhost').el)).toBeTruthy();
- expect(u.isVisible(_converse.chatboxviews.get('leisure@localhost').el)).toBeTruthy();
- _converse.api.roomviews.close();
- expect(_converse.chatboxviews.get('lounge@localhost')).toBeUndefined();
- expect(_converse.chatboxviews.get('leisure@localhost')).toBeUndefined();
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("has a method 'get' which returns a wrapped groupchat (if it exists)",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- let jid, room, chatroomview;
- test_utils.createContacts(_converse, 'current');
- test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group .group-toggle').length, 300)
- .then(() => test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'))
- .then(() => {
- jid = 'lounge@localhost';
- room = _converse.api.rooms.get(jid);
- expect(room instanceof Object).toBeTruthy();
- chatroomview = _converse.chatboxviews.get(jid);
- expect(chatroomview.is_chatroom).toBeTruthy();
- expect(u.isVisible(chatroomview.el)).toBeTruthy();
- chatroomview.close();
- // Test with mixed case
- return test_utils.openAndEnterChatRoom(_converse, 'Leisure', 'localhost', 'dummy');
- }).then(() => {
- jid = 'Leisure@localhost';
- room = _converse.api.rooms.get(jid);
- expect(room instanceof Object).toBeTruthy();
- chatroomview = _converse.chatboxviews.get(jid.toLowerCase());
- expect(u.isVisible(chatroomview.el)).toBeTruthy();
- jid = 'leisure@localhost';
- room = _converse.api.rooms.get(jid);
- expect(room instanceof Object).toBeTruthy();
- chatroomview = _converse.chatboxviews.get(jid.toLowerCase());
- expect(u.isVisible(chatroomview.el)).toBeTruthy();
- jid = 'leiSure@localhost';
- room = _converse.api.rooms.get(jid);
- expect(room instanceof Object).toBeTruthy();
- chatroomview = _converse.chatboxviews.get(jid.toLowerCase());
- expect(u.isVisible(chatroomview.el)).toBeTruthy();
- chatroomview.close();
- // Non-existing room
- jid = 'lounge2@localhost';
- room = _converse.api.rooms.get(jid);
- expect(typeof room === 'undefined').toBeTruthy();
- done();
- }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
- }));
- it("has a method 'open' which opens (optionally configures) and returns a wrapped chat box",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- // Mock 'getRoomFeatures', otherwise the room won't be
- // displayed as it waits first for the features to be returned
- // (when it's a new room being created).
- spyOn(_converse.ChatRoom.prototype, 'getRoomFeatures').and.callFake(function () {
- var deferred = new $.Deferred();
- deferred.resolve();
- return deferred.promise();
- });
- const sent_IQ_els = [];
- let jid = 'lounge@localhost';
- let chatroomview, sent_IQ, IQ_id;
- test_utils.openControlBox();
- test_utils.createContacts(_converse, 'current');
- test_utils.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group .group-toggle').length)
- .then(() => _converse.api.rooms.open(jid))
- .then((room) => {
- // Test on groupchat that's not yet open
- expect(room instanceof Backbone.Model).toBeTruthy();
- chatroomview = _converse.chatboxviews.get(jid);
- expect(chatroomview.is_chatroom).toBeTruthy();
- expect(u.isVisible(chatroomview.el)).toBeTruthy();
- // Test again, now that the room exists.
- return _converse.api.rooms.open(jid);
- }).then((room) => {
- expect(room instanceof Backbone.Model).toBeTruthy();
- chatroomview = _converse.chatboxviews.get(jid);
- expect(chatroomview.is_chatroom).toBeTruthy();
- expect(u.isVisible(chatroomview.el)).toBeTruthy();
- chatroomview.close();
- // Test with mixed case in JID
- jid = 'Leisure@localhost';
- return _converse.api.rooms.open(jid);
- }).then((room) => {
- expect(room instanceof Backbone.Model).toBeTruthy();
- chatroomview = _converse.chatboxviews.get(jid.toLowerCase());
- expect(u.isVisible(chatroomview.el)).toBeTruthy();
- jid = 'leisure@localhost';
- return _converse.api.rooms.open(jid);
- }).then((room) => {
- expect(room instanceof Backbone.Model).toBeTruthy();
- chatroomview = _converse.chatboxviews.get(jid.toLowerCase());
- expect(u.isVisible(chatroomview.el)).toBeTruthy();
- jid = 'leiSure@localhost';
- return _converse.api.rooms.open(jid);
- }).then((room) => {
- expect(room instanceof Backbone.Model).toBeTruthy();
- chatroomview = _converse.chatboxviews.get(jid.toLowerCase());
- expect(u.isVisible(chatroomview.el)).toBeTruthy();
- chatroomview.close();
- _converse.muc_instant_rooms = false;
- var sendIQ = _converse.connection.sendIQ;
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
- sent_IQ = iq;
- sent_IQ_els.push(iq.nodeTree);
- IQ_id = sendIQ.bind(this)(iq, callback, errback);
- });
- // Test with configuration
- return _converse.api.rooms.open('room@conference.example.org', {
- 'nick': 'some1',
- 'auto_configure': true,
- 'roomconfig': {
- 'changesubject': false,
- 'membersonly': true,
- 'persistentroom': true,
- 'publicroom': true,
- 'roomdesc': 'Welcome to this groupchat',
- 'whois': 'anyone'
- }
- });
- }).then((room) => {
- chatroomview = _converse.chatboxviews.get('room@conference.example.org');
- // We pretend this is a new room, so no disco info is returned.
- var features_stanza = $iq({
- from: 'room@conference.example.org',
- 'id': IQ_id,
- 'to': 'dummy@localhost/desktop',
- 'type': 'error'
- }).c('error', {'type': 'cancel'})
- .c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
- _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
- /* <presence xmlns="jabber:client" to="dummy@localhost/pda" from="room@conference.example.org/yo">
- * <x xmlns="http://jabber.org/protocol/muc#user">
- * <item affiliation="owner" jid="dummy@localhost/pda" role="moderator"/>
- * <status code="110"/>
- * <status code="201"/>
- * </x>
- * </presence>
- */
- var presence = $pres({
- from:'room@conference.example.org/some1',
- to:'dummy@localhost/pda'
- })
- .c('x', {xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item', {
- affiliation: 'owner',
- jid: 'dummy@localhost/pda',
- role: 'moderator'
- }).up()
- .c('status', {code:'110'}).up()
- .c('status', {code:'201'});
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(_converse.connection.sendIQ).toHaveBeenCalled();
- expect(sent_IQ.toLocaleString()).toBe(
- "<iq to='room@conference.example.org' type='get' xmlns='jabber:client' id='"+IQ_id+
- "'><query xmlns='http://jabber.org/protocol/muc#owner'/></iq>"
- );
- var node = Strophe.xmlHtmlNode(
- '<iq xmlns="jabber:client"'+
- ' type="result"'+
- ' to="dummy@localhost/pda"'+
- ' from="room@conference.example.org" id="'+IQ_id+'">'+
- ' <query xmlns="http://jabber.org/protocol/muc#owner">'+
- ' <x xmlns="jabber:x:data" type="form">'+
- ' <title>Configuration for room@conference.example.org</title>'+
- ' <instructions>Complete and submit this form to configure the room.</instructions>'+
- ' <field var="FORM_TYPE" type="hidden">'+
- ' <value>http://jabber.org/protocol/muc#roomconfig</value>'+
- ' </field>'+
- ' <field type="text-single" var="muc#roomconfig_roomname" label="Name">'+
- ' <value>Room</value>'+
- ' </field>'+
- ' <field type="text-single" var="muc#roomconfig_roomdesc" label="Description"><value/></field>'+
- ' <field type="boolean" var="muc#roomconfig_persistentroom" label="Make Room Persistent?"/>'+
- ' <field type="boolean" var="muc#roomconfig_publicroom" label="Make Room Publicly Searchable?"><value>1</value></field>'+
- ' <field type="boolean" var="muc#roomconfig_changesubject" label="Allow Occupants to Change Subject?"/>'+
- ' <field type="list-single" var="muc#roomconfig_whois" label="Who May Discover Real JIDs?"><option label="Moderators Only">'+
- ' <value>moderators</value></option><option label="Anyone"><value>anyone</value></option>'+
- ' </field>'+
- ' <field type="text-private" var="muc#roomconfig_roomsecret" label="Password"><value/></field>'+
- ' <field type="boolean" var="muc#roomconfig_moderatedroom" label="Make Room Moderated?"/>'+
- ' <field type="boolean" var="muc#roomconfig_membersonly" label="Make Room Members-Only?"/>'+
- ' <field type="text-single" var="muc#roomconfig_historylength" label="Maximum Number of History Messages Returned by Room">'+
- ' <value>20</value></field>'+
- ' </x>'+
- ' </query>'+
- ' </iq>');
- spyOn(chatroomview.model, 'sendConfiguration').and.callThrough();
- _converse.connection._dataRecv(test_utils.createRequest(node.firstElementChild));
- return test_utils.waitUntil(() => chatroomview.model.sendConfiguration.calls.count() === 1);
- }).then(() => {
- var sent_stanza = sent_IQ_els.pop();
- while (sent_stanza.getAttribute('type') !== 'set') {
- sent_stanza = sent_IQ_els.pop();
- }
- expect(sizzle('field[var="muc#roomconfig_roomname"] value', sent_stanza).pop().textContent).toBe('Room');
- expect(sizzle('field[var="muc#roomconfig_roomdesc"] value', sent_stanza).pop().textContent).toBe('Welcome to this groupchat');
- expect(sizzle('field[var="muc#roomconfig_persistentroom"] value', sent_stanza).pop().textContent).toBe('1');
- expect(sizzle('field[var="muc#roomconfig_publicroom"] value ', sent_stanza).pop().textContent).toBe('1');
- expect(sizzle('field[var="muc#roomconfig_changesubject"] value', sent_stanza).pop().textContent).toBe('0');
- expect(sizzle('field[var="muc#roomconfig_whois"] value ', sent_stanza).pop().textContent).toBe('anyone');
- expect(sizzle('field[var="muc#roomconfig_membersonly"] value', sent_stanza).pop().textContent).toBe('1');
- expect(sizzle('field[var="muc#roomconfig_historylength"] value', sent_stanza).pop().textContent).toBe('20');
- done();
- });
- }));
- });
- describe("An instant groupchat", function () {
- it("will be created when muc_instant_rooms is set to true",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- const IQ_stanzas = _converse.connection.IQ_stanzas;
- const sendIQ = _converse.connection.sendIQ;
- const room_jid = 'lounge@localhost';
- let sent_IQ, IQ_id, view;
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
- if (iq.nodeTree.getAttribute('to') === 'lounge@localhost') {
- sent_IQ = iq;
- IQ_id = sendIQ.bind(this)(iq, callback, errback);
- } else {
- sendIQ.bind(this)(iq, callback, errback);
- }
- });
- test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy')
- .then(() => {
- return test_utils.waitUntil(() => _.get(_.filter(
- IQ_stanzas,
- iq => iq.nodeTree.querySelector(
- `iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
- )).pop(), 'nodeTree'));
- }).then(stanza => {
- // We pretend this is a new room, so no disco info is returned.
-
- /* <iq from="jordie.langen@chat.example.org/converse.js-11659299" to="myroom@conference.chat.example.org" type="get">
- * <query xmlns="http://jabber.org/protocol/disco#info"/>
- * </iq>
- * <iq xmlns="jabber:client" type="error" to="jordie.langen@chat.example.org/converse.js-11659299" from="myroom@conference.chat.example.org">
- * <error type="cancel">
- * <item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
- * </error>
- * </iq>
- */
- var features_stanza = $iq({
- 'from': 'lounge@localhost',
- 'id': stanza.getAttribute('id'),
- 'to': 'dummy@localhost/desktop',
- 'type': 'error'
- }).c('error', {'type': 'cancel'})
- .c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
- _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
- view = _converse.chatboxviews.get('lounge@localhost');
- spyOn(view, 'join').and.callThrough();
- spyOn(view, 'submitNickname').and.callThrough();
- /* <iq to="myroom@conference.chat.example.org"
- * from="jordie.langen@chat.example.org/converse.js-11659299"
- * type="get">
- * <query xmlns="http://jabber.org/protocol/disco#info"
- * node="x-roomuser-item"/>
- * </iq>
- */
- return test_utils.waitUntil(() => _.get(_.filter(
- IQ_stanzas,
- s => sizzle(`iq[to="${room_jid}"] query[node="x-roomuser-item"]`, s.nodeTree).length
- ).pop(), 'nodeTree')
- );
- }).then(stanza => {
- expect(stanza.outerHTML.trim()).toBe(
- `<iq to="lounge@localhost" from="dummy@localhost/resource" `+
- `type="get" xmlns="jabber:client" id="${stanza.getAttribute("id")}">`+
- `<query xmlns="http://jabber.org/protocol/disco#info" node="x-roomuser-item"/></iq>`);
- /* <iq xmlns="jabber:client" type="error" to="jordie.langen@chat.example.org/converse.js-11659299" from="myroom@conference.chat.example.org">
- * <error type="cancel">
- * <item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
- * </error>
- * </iq>
- */
- var result_stanza = $iq({
- 'type': 'error',
- 'id': stanza.getAttribute('id'),
- 'from': view.model.get('jid'),
- 'to': _converse.connection.jid
- }).c('error', {'type': 'cancel'})
- .c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
- _converse.connection._dataRecv(test_utils.createRequest(result_stanza));
- return test_utils.waitUntil(() => view.el.querySelector('input[name="nick"]'));
- }).then(input => {
- input.value = 'nicky';
- view.el.querySelector('input[type=submit]').click();
- expect(view.submitNickname).toHaveBeenCalled();
- expect(view.join).toHaveBeenCalled();
- // The user has just entered the room (because join was called)
- // and receives their own presence from the server.
- // See example 24:
- // http://xmpp.org/extensions/xep-0045.html#enter-pres
- //
- /* <presence xmlns="jabber:client" to="jordie.langen@chat.example.org/converse.js-11659299" from="myroom@conference.chat.example.org/jc">
- * <x xmlns="http://jabber.org/protocol/muc#user">
- * <item jid="jordie.langen@chat.example.org/converse.js-11659299" affiliation="owner" role="moderator"/>
- * <status code="110"/>
- * <status code="201"/>
- * </x>
- * </presence>
- */
- var presence = $pres({
- to:'dummy@localhost/resource',
- from:'lounge@localhost/thirdwitch',
- id:'5025e055-036c-4bc5-a227-706e7e352053'
- }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- affiliation: 'owner',
- jid: 'dummy@localhost/resource',
- role: 'moderator'
- }).up()
- .c('status').attrs({code:'110'}).up()
- .c('status').attrs({code:'201'}).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- var info_text = view.el.querySelector('.chat-content .chat-info').textContent;
- expect(info_text).toBe('A new groupchat has been created');
- // An instant room is created by saving the default configuratoin.
- //
- /* <iq to="myroom@conference.chat.example.org" type="set" xmlns="jabber:client" id="5025e055-036c-4bc5-a227-706e7e352053:sendIQ">
- * <query xmlns="http://jabber.org/protocol/muc#owner"><x xmlns="jabber:x:data" type="submit"/></query>
- * </iq>
- */
- expect(sent_IQ.toLocaleString()).toBe(
- "<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#owner'><x xmlns='jabber:x:data' type='submit'/>"+
- "</query></iq>");
- done();
- }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
- }));
- });
- describe("A Groupchat", function () {
- it("shows join/leave messages when users enter or exit a groupchat",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoom(_converse, "coven", 'chat.shakespeare.lit', 'some1')
- .then(() => {
- var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- var $chat_content = $(view.el).find('.chat-content');
- /* We don't show join/leave messages for existing occupants. We
- * know about them because we receive their presences before we
- * receive our own.
- */
- var presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/oldguy'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'oldguy@localhost/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(0);
- /* <presence to="dummy@localhost/_converse.js-29092160"
- * from="coven@chat.shakespeare.lit/some1">
- * <x xmlns="http://jabber.org/protocol/muc#user">
- * <item affiliation="owner" jid="dummy@localhost/_converse.js-29092160" role="moderator"/>
- * <status code="110"/>
- * </x>
- * </presence></body>
- */
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/some1'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'owner',
- 'jid': 'dummy@localhost/_converse.js-29092160',
- 'role': 'moderator'
- }).up()
- .c('status', {code: '110'});
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content.find('div.chat-info:first').html()).toBe("some1 has entered the groupchat");
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/newguy'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@localhost/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(2);
- expect($chat_content.find('div.chat-info:last').html()).toBe("newguy has entered the groupchat");
- // Add another entrant, otherwise the above message will be
- // collapsed if "newguy" leaves immediately again
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/newgirl'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newgirl@localhost/_converse.js-213098781',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(3);
- expect($chat_content.find('div.chat-info:last').html()).toBe("newgirl has entered the groupchat");
- // Don't show duplicate join messages
- presence = $pres({
- to: 'dummy@localhost/_converse.js-290918392',
- from: 'coven@chat.shakespeare.lit/newguy'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@localhost/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(3);
- /* <presence
- * from='coven@chat.shakespeare.lit/thirdwitch'
- * to='crone1@shakespeare.lit/desktop'
- * type='unavailable'>
- * <status>Disconnected: Replaced by new connection</status>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='member'
- * jid='hag66@shakespeare.lit/pda'
- * role='none'/>
- * </x>
- * </presence>
- */
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- type: 'unavailable',
- from: 'coven@chat.shakespeare.lit/newguy'
- })
- .c('status', 'Disconnected: Replaced by new connection').up()
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@localhost/_converse.js-290929789',
- 'role': 'none'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content.find('div.chat-info').length).toBe(4);
- expect($chat_content.find('div.chat-info:last').html()).toBe(
- 'newguy has left the groupchat. '+
- '"Disconnected: Replaced by new connection"');
- // When the user immediately joins again, we collapse the
- // multiple join/leave messages.
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/newguy'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@localhost/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content.find('div.chat-info').length).toBe(4);
- var $msg_el = $chat_content.find('div.chat-info:last');
- expect($msg_el.html()).toBe("newguy has left and re-entered the groupchat");
- expect($msg_el.data('leavejoin')).toBe('"newguy"');
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- type: 'unavailable',
- from: 'coven@chat.shakespeare.lit/newguy'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@localhost/_converse.js-290929789',
- 'role': 'none'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content.find('div.chat-info').length).toBe(4);
- $msg_el = $chat_content.find('div.chat-info:last');
- expect($msg_el.html()).toBe('newguy has left the groupchat');
- expect($msg_el.data('leave')).toBe('"newguy"');
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/nomorenicks'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'nomorenicks@localhost/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(5);
- expect($chat_content.find('div.chat-info:last').html()).toBe("nomorenicks has entered the groupchat");
- presence = $pres({
- to: 'dummy@localhost/_converse.js-290918392',
- type: 'unavailable',
- from: 'coven@chat.shakespeare.lit/nomorenicks'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'nomorenicks@localhost/_converse.js-290929789',
- 'role': 'none'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(5);
- expect($chat_content.find('div.chat-info:last').html()).toBe("nomorenicks has entered and left the groupchat");
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/nomorenicks'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'nomorenicks@localhost/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(5);
- expect($chat_content.find('div.chat-info:last').html()).toBe("nomorenicks has entered the groupchat");
- done();
- });
- }));
- it("shows a new day indicator if a join/leave message is received on a new day",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'dummy').then(function () {
- var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- var chat_content = view.el.querySelector('.chat-content');
- var $chat_content = $(chat_content);
- var indicator = chat_content.querySelector('.date-separator');
- expect(indicator).not.toBe(null);
- expect(indicator.getAttribute('class')).toEqual('message date-separator');
- expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').format());
- expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
- expect(chat_content.querySelectorAll('div.chat-info').length).toBe(1);
- expect(chat_content.querySelector('div.chat-info').textContent).toBe(
- "dummy has entered the groupchat"
- );
- var baseTime = new Date();
- jasmine.clock().install();
- jasmine.clock().mockDate(baseTime);
- var ONE_DAY_LATER = 86400000;
- jasmine.clock().tick(ONE_DAY_LATER);
- /* <presence to="dummy@localhost/_converse.js-29092160"
- * from="coven@chat.shakespeare.lit/some1">
- * <x xmlns="http://jabber.org/protocol/muc#user">
- * <item affiliation="owner" jid="dummy@localhost/_converse.js-29092160" role="moderator"/>
- * <status code="110"/>
- * </x>
- * </presence></body>
- */
- var presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/some1'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'owner',
- 'jid': 'some1@localhost/_converse.js-290929789',
- 'role': 'moderator'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- indicator = chat_content.querySelector('.date-separator[data-isodate="'+moment().startOf('day').format()+'"]');
- expect(indicator).not.toBe(null);
- expect(indicator.getAttribute('class')).toEqual('message date-separator');
- expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').format());
- expect(indicator.querySelector('time').getAttribute('class')).toEqual('separator-text');
- expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
- expect(chat_content.querySelectorAll('div.chat-info').length).toBe(2);
- expect(chat_content.querySelector('div.chat-info:last-child').textContent).toBe(
- "some1 has entered the groupchat"
- );
- jasmine.clock().tick(ONE_DAY_LATER);
- // Test a user leaving a groupchat
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- type: 'unavailable',
- from: 'coven@chat.shakespeare.lit/some1'
- })
- .c('status', 'Disconnected: Replaced by new connection').up()
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'owner',
- 'jid': 'some1@localhost/_converse.js-290929789',
- 'role': 'moderator'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- indicator = chat_content.querySelector('.date-separator[data-isodate="'+moment().startOf('day').format()+'"]');
- expect(indicator).not.toBe(null);
- expect(indicator.getAttribute('class')).toEqual('message date-separator');
- expect(indicator.getAttribute('data-isodate')).toEqual(moment().startOf('day').format());
- expect(indicator.querySelector('time').textContent).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
- expect(chat_content.querySelectorAll('div.chat-info').length).toBe(3);
- expect($(chat_content).find('div.chat-info:last').html()).toBe(
- 'some1 has left the groupchat. '+
- '"Disconnected: Replaced by new connection"');
- jasmine.clock().tick(ONE_DAY_LATER);
- var stanza = Strophe.xmlHtmlNode(
- '<message xmlns="jabber:client"' +
- ' to="dummy@localhost/_converse.js-290929789"' +
- ' type="groupchat"' +
- ' from="coven@chat.shakespeare.lit/some1">'+
- ' <body>hello world</body>'+
- ' <delay xmlns="urn:xmpp:delay" stamp="'+moment().format()+'" from="some1@localhost"/>'+
- '</message>').firstChild;
- _converse.connection._dataRecv(test_utils.createRequest(stanza));
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/newguy'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@localhost/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- let time = chat_content.querySelectorAll('time.separator-text');
- expect(time.length).toEqual(4);
- var $indicator = $chat_content.find('.date-separator:eq(3)');
- expect($indicator.attr('class')).toEqual('message date-separator');
- expect($indicator.data('isodate')).toEqual(moment().startOf('day').format());
- expect($indicator.find('time').text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
- expect(chat_content.querySelectorAll('div.chat-info').length).toBe(4);
- expect($chat_content.find('div.chat-info:last').html()).toBe("newguy has entered the groupchat");
- jasmine.clock().tick(ONE_DAY_LATER);
- stanza = Strophe.xmlHtmlNode(
- '<message xmlns="jabber:client"' +
- ' to="dummy@localhost/_converse.js-290929789"' +
- ' type="groupchat"' +
- ' from="coven@chat.shakespeare.lit/some1">'+
- ' <body>hello world</body>'+
- ' <delay xmlns="urn:xmpp:delay" stamp="'+moment().format()+'" from="some1@localhost"/>'+
- '</message>').firstChild;
- _converse.connection._dataRecv(test_utils.createRequest(stanza));
- jasmine.clock().tick(ONE_DAY_LATER);
- // Test a user leaving a groupchat
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- type: 'unavailable',
- from: 'coven@chat.shakespeare.lit/newguy'
- })
- .c('status', 'Disconnected: Replaced by new connection').up()
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@localhost/_converse.js-290929789',
- 'role': 'none'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- time = chat_content.querySelectorAll('time.separator-text');
- expect(time.length).toEqual(6);
- $indicator = $chat_content.find('.date-separator:eq(5)');
- expect($indicator.attr('class')).toEqual('message date-separator');
- expect($indicator.data('isodate')).toEqual(moment().startOf('day').format());
- expect($indicator.find('time').text()).toEqual(moment().startOf('day').format("dddd MMM Do YYYY"));
- expect(chat_content.querySelectorAll('div.chat-info').length).toBe(5);
- expect($chat_content.find('div.chat-info:last').html()).toBe(
- 'newguy has left the groupchat. '+
- '"Disconnected: Replaced by new connection"');
- jasmine.clock().uninstall();
- done();
- }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
- }));
- it("supports the /me command",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- let view;
- test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
- .then(() => test_utils.waitUntil(() => _converse.xmppstatus.vcard.get('fullname')))
- .then(() => {
- test_utils.createContacts(_converse, 'current');
- return test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
- }).then(() => {
- view = _converse.chatboxviews.get('lounge@localhost');
- if (!$(view.el).find('.chat-area').length) { view.renderChatArea(); }
- var message = '/me is tired';
- var nick = mock.chatroom_names[0],
- msg = $msg({
- 'from': 'lounge@localhost/'+nick,
- 'id': (new Date()).getTime(),
- 'to': 'dummy@localhost',
- 'type': 'groupchat'
- }).c('body').t(message).tree();
- view.model.onMessage(msg);
- expect(_.includes($(view.el).find('.chat-msg__author').text(), '**Dyon van de Wege')).toBeTruthy();
- expect($(view.el).find('.chat-msg__text').text()).toBe(' is tired');
- message = '/me is as well';
- msg = $msg({
- from: 'lounge@localhost/Max Mustermann',
- id: (new Date()).getTime(),
- to: 'dummy@localhost',
- type: 'groupchat'
- }).c('body').t(message).tree();
- view.model.onMessage(msg);
- expect(_.includes($(view.el).find('.chat-msg__author:last').text(), '**Max Mustermann')).toBeTruthy();
- expect($(view.el).find('.chat-msg__text:last').text()).toBe(' is as well');
- done();
- });
- }));
- it("can be configured if you're its owner",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- let view, sent_IQ, IQ_id;
- const sendIQ = _converse.connection.sendIQ;
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
- sent_IQ = iq;
- IQ_id = sendIQ.bind(this)(iq, callback, errback);
- });
- _converse.api.rooms.open('coven@chat.shakespeare.lit', {'nick': 'some1'})
- .then(() => {
- view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- spyOn(view.model, 'saveAffiliationAndRole').and.callThrough();
- // We pretend this is a new room, so no disco info is returned.
- var features_stanza = $iq({
- from: 'coven@chat.shakespeare.lit',
- 'id': IQ_id,
- 'to': 'dummy@localhost/desktop',
- 'type': 'error'
- }).c('error', {'type': 'cancel'})
- .c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
- _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
- /* <presence to="dummy@localhost/_converse.js-29092160"
- * from="coven@chat.shakespeare.lit/some1">
- * <x xmlns="http://jabber.org/protocol/muc#user">
- * <item affiliation="owner" jid="dummy@localhost/_converse.js-29092160" role="moderator"/>
- * <status code="110"/>
- * </x>
- * </presence></body>
- */
- var presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/some1'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'owner',
- 'jid': 'dummy@localhost/_converse.js-29092160',
- 'role': 'moderator'
- }).up()
- .c('status', {code: '110'});
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.model.saveAffiliationAndRole).toHaveBeenCalled();
- expect($(view.el.querySelector('.toggle-chatbox-button')).is(':visible')).toBeTruthy();
- return test_utils.waitUntil(() => !_.isNull(view.el.querySelector('.configure-chatroom-button')))
- }).then(() => {
- expect($(view.el.querySelector('.configure-chatroom-button')).is(':visible')).toBeTruthy();
- view.el.querySelector('.configure-chatroom-button').click();
- /* Check that an IQ is sent out, asking for the
- * configuration form.
- * See: // http://xmpp.org/extensions/xep-0045.html#example-163
- *
- * <iq from='crone1@shakespeare.lit/desktop'
- * id='config1'
- * to='coven@chat.shakespeare.lit'
- * type='get'>
- * <query xmlns='http://jabber.org/protocol/muc#owner'/>
- * </iq>
- */
- expect(sent_IQ.toLocaleString()).toBe(
- "<iq to='coven@chat.shakespeare.lit' type='get' xmlns='jabber:client' id='"+IQ_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#owner'/>"+
- "</iq>");
- /* Server responds with the configuration form.
- * See: // http://xmpp.org/extensions/xep-0045.html#example-165
- */
- var config_stanza = $iq({from: 'coven@chat.shakespeare.lit',
- 'id': IQ_id,
- 'to': 'dummy@localhost/desktop',
- 'type': 'result'})
- .c('query', { 'xmlns': 'http://jabber.org/protocol/muc#owner'})
- .c('x', { 'xmlns': 'jabber:x:data', 'type': 'form'})
- .c('title').t('Configuration for "coven" Room').up()
- .c('instructions').t('Complete this form to modify the configuration of your room.').up()
- .c('field', {'type': 'hidden', 'var': 'FORM_TYPE'})
- .c('value').t('http://jabber.org/protocol/muc#roomconfig').up().up()
- .c('field', {
- 'label': 'Natural-Language Room Name',
- 'type': 'text-single',
- 'var': 'muc#roomconfig_roomname'})
- .c('value').t('A Dark Cave').up().up()
- .c('field', {
- 'label': 'Short Description of Room',
- 'type': 'text-single',
- 'var': 'muc#roomconfig_roomdesc'})
- .c('value').t('The place for all good witches!').up().up()
- .c('field', {
- 'label': 'Enable Public Logging?',
- 'type': 'boolean',
- 'var': 'muc#roomconfig_enablelogging'})
- .c('value').t(0).up().up()
- .c('field', {
- 'label': 'Allow Occupants to Change Subject?',
- 'type': 'boolean',
- 'var': 'muc#roomconfig_changesubject'})
- .c('value').t(0).up().up()
- .c('field', {
- 'label': 'Allow Occupants to Invite Others?',
- 'type': 'boolean',
- 'var': 'muc#roomconfig_allowinvites'})
- .c('value').t(0).up().up()
- .c('field', {
- 'label': 'Who Can Send Private Messages?',
- 'type': 'list-single',
- 'var': 'muc#roomconfig_allowpm'})
- .c('value').t('anyone').up()
- .c('option', {'label': 'Anyone'})
- .c('value').t('anyone').up().up()
- .c('option', {'label': 'Anyone with Voice'})
- .c('value').t('participants').up().up()
- .c('option', {'label': 'Moderators Only'})
- .c('value').t('moderators').up().up()
- .c('option', {'label': 'Nobody'})
- .c('value').t('none').up().up().up()
- .c('field', {
- 'label': 'Roles for which Presence is Broadcasted',
- 'type': 'list-multi',
- 'var': 'muc#roomconfig_presencebroadcast'})
- .c('value').t('moderator').up()
- .c('value').t('participant').up()
- .c('value').t('visitor').up()
- .c('option', {'label': 'Moderator'})
- .c('value').t('moderator').up().up()
- .c('option', {'label': 'Participant'})
- .c('value').t('participant').up().up()
- .c('option', {'label': 'Visitor'})
- .c('value').t('visitor').up().up().up()
- .c('field', {
- 'label': 'Roles and Affiliations that May Retrieve Member List',
- 'type': 'list-multi',
- 'var': 'muc#roomconfig_getmemberlist'})
- .c('value').t('moderator').up()
- .c('value').t('participant').up()
- .c('value').t('visitor').up()
- .c('option', {'label': 'Moderator'})
- .c('value').t('moderator').up().up()
- .c('option', {'label': 'Participant'})
- .c('value').t('participant').up().up()
- .c('option', {'label': 'Visitor'})
- .c('value').t('visitor').up().up().up()
- .c('field', {
- 'label': 'Make Room Publicly Searchable?',
- 'type': 'boolean',
- 'var': 'muc#roomconfig_publicroom'})
- .c('value').t(0).up().up()
- .c('field', {
- 'label': 'Make Room Publicly Searchable?',
- 'type': 'boolean',
- 'var': 'muc#roomconfig_publicroom'})
- .c('value').t(0).up().up()
- .c('field', {
- 'label': 'Make Room Persistent?',
- 'type': 'boolean',
- 'var': 'muc#roomconfig_persistentroom'})
- .c('value').t(0).up().up()
- .c('field', {
- 'label': 'Make Room Moderated?',
- 'type': 'boolean',
- 'var': 'muc#roomconfig_moderatedroom'})
- .c('value').t(0).up().up()
- .c('field', {
- 'label': 'Make Room Members Only?',
- 'type': 'boolean',
- 'var': 'muc#roomconfig_membersonly'})
- .c('value').t(0).up().up()
- .c('field', {
- 'label': 'Password Required for Entry?',
- 'type': 'boolean',
- 'var': 'muc#roomconfig_passwordprotectedroom'})
- .c('value').t(1).up().up()
- .c('field', {'type': 'fixed'})
- .c('value').t('If a password is required to enter this groupchat,'+
- 'you must specify the password below.').up().up()
- .c('field', {
- 'label': 'Password',
- 'type': 'text-private',
- 'var': 'muc#roomconfig_roomsecret'})
- .c('value').t('cauldronburn');
- _converse.connection._dataRecv(test_utils.createRequest(config_stanza));
- return test_utils.waitUntil(() => view.el.querySelectorAll('form.chatroom-form').length)
- }).then(() => {
- expect($(view.el.querySelector('form.chatroom-form')).length).toBe(1);
- expect(view.el.querySelectorAll('form.chatroom-form fieldset').length).toBe(2);
- var $membersonly = $(view.el.querySelector('input[name="muc#roomconfig_membersonly"]'));
- expect($membersonly.length).toBe(1);
- expect($membersonly.attr('type')).toBe('checkbox');
- $membersonly.prop('checked', true);
- var $moderated = $(view.el.querySelector('input[name="muc#roomconfig_moderatedroom"]'));
- expect($moderated.length).toBe(1);
- expect($moderated.attr('type')).toBe('checkbox');
- $moderated.prop('checked', true);
- var $password = $(view.el.querySelector('input[name="muc#roomconfig_roomsecret"]'));
- expect($password.length).toBe(1);
- expect($password.attr('type')).toBe('password');
- var $allowpm = $(view.el.querySelector('select[name="muc#roomconfig_allowpm"]'));
- expect($allowpm.length).toBe(1);
- $allowpm.val('moderators');
- var $presencebroadcast = $(view.el.querySelector('select[name="muc#roomconfig_presencebroadcast"]'));
- expect($presencebroadcast.length).toBe(1);
- $presencebroadcast.val(['moderator']);
- view.el.querySelector('input[type="submit"]').click();
- var $sent_stanza = $(sent_IQ.toLocaleString());
- expect($sent_stanza.find('field[var="muc#roomconfig_membersonly"] value').text()).toBe('1');
- expect($sent_stanza.find('field[var="muc#roomconfig_moderatedroom"] value').text()).toBe('1');
- expect($sent_stanza.find('field[var="muc#roomconfig_allowpm"] value').text()).toBe('moderators');
- expect($sent_stanza.find('field[var="muc#roomconfig_presencebroadcast"] value').text()).toBe('moderator');
- done();
- }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
- }));
- it("shows all members even if they're not currently present in the groupchat",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function() {
- var name;
- var view = _converse.chatboxviews.get('lounge@localhost'),
- occupants = view.el.querySelector('.occupant-list');
- var presence, role, jid, model;
- for (var i=0; i<mock.chatroom_names.length; i++) {
- name = mock.chatroom_names[i];
- role = mock.chatroom_roles[name].role;
- // See example 21 http://xmpp.org/extensions/xep-0045.html#enter-pres
- jid =
- presence = $pres({
- to:'dummy@localhost/pda',
- from:'lounge@localhost/'+name
- }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- affiliation: mock.chatroom_roles[name].affiliation,
- jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
- role: role
- }).up()
- .c('status').attrs({code:'110'}).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(occupants.querySelectorAll('li').length).toBe(2+i);
- model = view.occupantsview.model.where({'nick': name})[0];
- var index = view.occupantsview.model.indexOf(model);
- expect(occupants.querySelectorAll('li .occupant-nick')[index].textContent.trim()).toBe(mock.chatroom_names[i]);
- }
- // Test users leaving the groupchat
- // http://xmpp.org/extensions/xep-0045.html#exit
- for (i=mock.chatroom_names.length-1; i>-1; i--) {
- name = mock.chatroom_names[i];
- role = mock.chatroom_roles[name].role;
- // See example 21 http://xmpp.org/extensions/xep-0045.html#enter-pres
- presence = $pres({
- to:'dummy@localhost/pda',
- from:'lounge@localhost/'+name,
- type: 'unavailable'
- }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- affiliation: mock.chatroom_roles[name].affiliation,
- jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
- role: 'none'
- }).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(occupants.querySelectorAll('li').length).toBe(7);
- }
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("shows users currently present in the groupchat",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function() {
- var name;
- var view = _converse.chatboxviews.get('lounge@localhost'),
- occupants = view.el.querySelector('.occupant-list');
- var presence, role, jid, model;
- for (var i=0; i<mock.chatroom_names.length; i++) {
- name = mock.chatroom_names[i];
- role = mock.chatroom_roles[name].role;
- // See example 21 http://xmpp.org/extensions/xep-0045.html#enter-pres
- jid =
- presence = $pres({
- to:'dummy@localhost/pda',
- from:'lounge@localhost/'+name
- }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- affiliation: 'none',
- jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
- role: role
- }).up()
- .c('status').attrs({code:'110'}).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(occupants.querySelectorAll('li').length).toBe(2+i);
- model = view.occupantsview.model.where({'nick': name})[0];
- var index = view.occupantsview.model.indexOf(model);
- expect(occupants.querySelectorAll('li .occupant-nick')[index].textContent.trim()).toBe(mock.chatroom_names[i]);
- }
- // Test users leaving the groupchat
- // http://xmpp.org/extensions/xep-0045.html#exit
- for (i=mock.chatroom_names.length-1; i>-1; i--) {
- name = mock.chatroom_names[i];
- role = mock.chatroom_roles[name].role;
- // See example 21 http://xmpp.org/extensions/xep-0045.html#enter-pres
- presence = $pres({
- to:'dummy@localhost/pda',
- from:'lounge@localhost/'+name,
- type: 'unavailable'
- }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- affiliation: mock.chatroom_roles[name].affiliation,
- jid: name.replace(/ /g,'.').toLowerCase() + '@localhost',
- role: 'none'
- }).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(occupants.querySelectorAll('li').length).toBe(i+1);
- }
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("can handle multi-session nicknames",
- mock.initConverseWithPromises(null, ['rosterGroupsFetched'], {}, function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'oldhag').then(() => {
- let presence = $pres({
- 'to':'dummy@localhost/pda',
- 'from':"coven@chat.shakespeare.lit/my1stNick"
- }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- jid: 'someone@localhost/foo',
- role: 'moderator',
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- let occupants = view.el.querySelector('.occupant-list').querySelectorAll('li .occupant-nick');
- expect(occupants.length).toBe(2);
- expect(occupants.pop().textContent.trim()).toBe("my1stNick");
- presence = $pres({
- 'to':'dummy@localhost/pda',
- 'from':"coven@chat.shakespeare.lit/my2ndNick"
- }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- jid: 'someone@localhost/bar',
- role: 'moderator',
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- occupants = view.el.querySelector('.occupant-list').querySelectorAll('li .occupant-nick');
- expect(occupants.length).toBe(3);
- expect(occupants.pop().textContent.trim()).toBe("my2ndNick");
- done();
- });
- }));
- it("escapes occupant nicknames when rendering them, to avoid JS-injection attacks",
- mock.initConverseWithPromises(null, ['rosterGroupsFetched'], {}, function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
- /* <presence xmlns="jabber:client" to="jc@chat.example.org/converse.js-17184538"
- * from="oo@conference.chat.example.org/<img src="x" onerror="alert(123)"/>">
- * <x xmlns="http://jabber.org/protocol/muc#user">
- * <item jid="jc@chat.example.org/converse.js-17184538" affiliation="owner" role="moderator"/>
- * <status code="110"/>
- * </x>
- * </presence>"
- */
- var presence = $pres({
- to:'dummy@localhost/pda',
- from:"lounge@localhost/<img src="x" onerror="alert(123)"/>"
- }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- jid: 'someone@localhost',
- role: 'moderator',
- }).up()
- .c('status').attrs({code:'110'}).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- var view = _converse.chatboxviews.get('lounge@localhost');
- var occupants = view.el.querySelector('.occupant-list').querySelectorAll('li .occupant-nick');
- expect(occupants.length).toBe(2);
- expect($(occupants).first().text().trim()).toBe("<img src="x" onerror="alert(123)"/>");
- done();
- });
- }));
- it("indicates moderators and visitors by means of a special css class and tooltip",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
- var view = _converse.chatboxviews.get('lounge@localhost');
- var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
- var occupants = view.el.querySelector('.occupant-list').querySelectorAll('li');
- expect(occupants.length).toBe(1);
- expect($(occupants).first().find('.occupant-nick').text().trim()).toBe("dummy");
- expect($(occupants).first().find('.badge').length).toBe(2);
- expect($(occupants).first().find('.badge').first().text()).toBe('Owner');
- expect($(occupants).first().find('.badge').last().text()).toBe('Moderator');
- var presence = $pres({
- to:'dummy@localhost/pda',
- from:'lounge@localhost/moderatorman'
- }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- affiliation: 'admin',
- jid: contact_jid,
- role: 'moderator',
- }).up()
- .c('status').attrs({code:'110'}).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- occupants = view.el.querySelectorAll('.occupant-list li');
- expect(occupants.length).toBe(2);
- expect($(occupants).first().find('.occupant-nick').text().trim()).toBe("dummy");
- expect($(occupants).last().find('.occupant-nick').text().trim()).toBe("moderatorman");
- expect($(occupants).last().find('.badge').length).toBe(2);
- expect($(occupants).last().find('.badge').first().text()).toBe('Admin');
- expect($(occupants).last().find('.badge').last().text()).toBe('Moderator');
- expect($(occupants).last().attr('title')).toBe(
- contact_jid + ' This user is a moderator. Click to mention moderatorman in your message.'
- );
- contact_jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost';
- presence = $pres({
- to:'dummy@localhost/pda',
- from:'lounge@localhost/visitorwoman'
- }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- jid: contact_jid,
- role: 'visitor',
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- occupants = view.el.querySelector('.occupant-list').querySelectorAll('li');
- expect($(occupants).last().find('.occupant-nick').text().trim()).toBe("visitorwoman");
- expect($(occupants).last().find('.badge').length).toBe(1);
- expect($(occupants).last().find('.badge').last().text()).toBe('Visitor');
- expect($(occupants).last().attr('title')).toBe(
- contact_jid + ' This user can NOT send messages in this groupchat. Click to mention visitorwoman in your message.'
- );
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("will use the user's reserved nickname, if it exists",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- let sent_IQ, IQ_id, view;
- const IQ_stanzas = _converse.connection.IQ_stanzas;
- const sendIQ = _converse.connection.sendIQ;
- const room_jid = 'lounge@localhost';
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
- if (iq.nodeTree.getAttribute('to') === 'lounge@localhost') {
- sent_IQ = iq;
- IQ_id = sendIQ.bind(this)(iq, callback, errback);
- } else {
- sendIQ.bind(this)(iq, callback, errback);
- }
- });
- test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy')
- .then(() => {
- return test_utils.waitUntil(() => _.get(_.filter(
- IQ_stanzas,
- iq => iq.nodeTree.querySelector(
- `iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
- )).pop(), 'nodeTree'));
- }).then(stanza => {
- // We pretend this is a new room, so no disco info is returned.
- var features_stanza = $iq({
- from: 'lounge@localhost',
- 'id': stanza.getAttribute('id'),
- 'to': 'dummy@localhost/desktop',
- 'type': 'error'
- }).c('error', {'type': 'cancel'})
- .c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
- _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
- view = _converse.chatboxviews.get('lounge@localhost');
- spyOn(view, 'join').and.callThrough();
- /* <iq from='hag66@shakespeare.lit/pda'
- * id='getnick1'
- * to='coven@chat.shakespeare.lit'
- * type='get'>
- * <query xmlns='http://jabber.org/protocol/disco#info'
- * node='x-roomuser-item'/>
- * </iq>
- */
- return test_utils.waitUntil(() => _.get(_.filter(
- IQ_stanzas,
- s => sizzle(`iq[to="${room_jid}"] query[node="x-roomuser-item"]`, s.nodeTree).length
- ).pop(), 'nodeTree')
- );
- }).then(iq => {
- expect(iq.outerHTML).toBe(
- `<iq to="lounge@localhost" from="dummy@localhost/resource" `+
- `type="get" xmlns="jabber:client" id="${iq.getAttribute('id')}">`+
- `<query xmlns="http://jabber.org/protocol/disco#info" node="x-roomuser-item"/></iq>`);
- /* <iq from='coven@chat.shakespeare.lit'
- * id='getnick1'
- * to='hag66@shakespeare.lit/pda'
- * type='result'>
- * <query xmlns='http://jabber.org/protocol/disco#info'
- * node='x-roomuser-item'>
- * <identity
- * category='conference'
- * name='thirdwitch'
- * type='text'/>
- * </query>
- * </iq>
- */
- var stanza = $iq({
- 'type': 'result',
- 'id': IQ_id,
- 'from': view.model.get('jid'),
- 'to': _converse.connection.jid
- }).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info', 'node': 'x-roomuser-item'})
- .c('identity', {'category': 'conference', 'name': 'thirdwitch', 'type': 'text'});
- _converse.connection._dataRecv(test_utils.createRequest(stanza));
- expect(view.join).toHaveBeenCalled();
- // The user has just entered the groupchat (because join was called)
- // and receives their own presence from the server.
- // See example 24:
- // http://xmpp.org/extensions/xep-0045.html#enter-pres
- var presence = $pres({
- to:'dummy@localhost/resource',
- from:'lounge@localhost/thirdwitch',
- id:'DC352437-C019-40EC-B590-AF29E879AF97'
- }).c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- affiliation: 'member',
- jid: 'dummy@localhost/resource',
- role: 'participant'
- }).up()
- .c('status').attrs({code:'110'}).up()
- .c('status').attrs({code:'210'}).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- var info_text = $(view.el).find('.chat-content .chat-info:first').text();
- expect(info_text).toBe('Your nickname has been automatically set to thirdwitch');
- done();
- });
- }));
- it("allows the user to invite their roster contacts to enter the groupchat",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- test_utils.createContacts(_converse, 'current'); // We need roster contacts, so that we have someone to invite
- // Since we don't actually fetch roster contacts, we need to
- // cheat here and emit the event.
- _converse.emit('rosterContactsFetched');
- let view;
- test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy')
- .then(() => {
- spyOn(_converse, 'emit');
- spyOn(window, 'prompt').and.callFake(function () {
- return "Please join!";
- });
- view = _converse.chatboxviews.get('lounge@localhost');
- // XXX: cheating a lttle bit, normally this'll be set after
- // receiving the features for the groupchat.
- view.model.set('open', 'true');
- spyOn(view.model, 'directInvite').and.callThrough();
- var $input;
- $(view.el).find('.chat-area').remove();
- return test_utils.waitUntil(() => view.el.querySelectorAll('input.invited-contact').length)
- }).then(function () {
- var $input = $(view.el).find('input.invited-contact');
- expect($input.attr('placeholder')).toBe('Invite');
- $input.val("Felix");
- var evt = new Event('input');
- $input[0].dispatchEvent(evt);
- var sent_stanza;
- spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
- sent_stanza = stanza;
- });
- var $hint = $input.siblings('ul').children('li');
- expect($input.val()).toBe('Felix');
- expect($hint[0].textContent).toBe('Felix Amsel');
- expect($hint.length).toBe(1);
- if (typeof(Event) === 'function') {
- // Not working on PhantomJS
- evt = new Event('mousedown', {'bubbles': true});
- evt.button = 0; // For some reason awesomplete wants this
- $hint[0].dispatchEvent(evt);
- expect(window.prompt).toHaveBeenCalled();
- expect(view.model.directInvite).toHaveBeenCalled();
- expect(sent_stanza.toLocaleString()).toBe(
- "<message from='dummy@localhost/resource' to='felix.amsel@localhost' id='" +
- sent_stanza.nodeTree.getAttribute('id') +
- "' xmlns='jabber:client'>"+
- "<x xmlns='jabber:x:conference' jid='lounge@localhost' reason='Please join!'/>"+
- "</message>"
- );
- }
- done();
- });
- }));
- it("can be joined automatically, based upon a received invite",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.createContacts(_converse, 'current'); // We need roster contacts, who can invite us
- spyOn(window, 'confirm').and.callFake(function () {
- return true;
- });
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
- var view = _converse.chatboxviews.get('lounge@localhost');
- view.close(); // Hack, otherwise we have to mock stanzas.
- var name = mock.cur_names[0];
- var from_jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
- var room_jid = 'lounge@localhost';
- var reason = "Please join this groupchat";
- expect(_converse.chatboxes.models.length).toBe(1);
- expect(_converse.chatboxes.models[0].id).toBe("controlbox");
- var stanza = Strophe.xmlHtmlNode(
- '<message xmlns="jabber:client" to="'+_converse.bare_jid+'" from="'+from_jid+'" id="9bceb415-f34b-4fa4-80d5-c0d076a24231">'+
- '<x xmlns="jabber:x:conference" jid="'+room_jid+'" reason="'+reason+'"/>'+
- '</message>').firstChild;
- _converse.onDirectMUCInvitation(stanza);
- expect(window.confirm).toHaveBeenCalledWith(
- name + ' has invited you to join a groupchat: '+ room_jid +
- ', and left the following reason: "'+reason+'"');
- expect(_converse.chatboxes.models.length).toBe(2);
- expect(_converse.chatboxes.models[0].id).toBe('controlbox');
- expect(_converse.chatboxes.models[1].id).toBe(room_jid);
- done();
- });
- }));
- it("shows received groupchat messages",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- let view;
- const text = 'This is a received message';
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
- spyOn(_converse, 'emit');
- view = _converse.chatboxviews.get('lounge@localhost');
- if (!$(view.el).find('.chat-area').length) { view.renderChatArea(); }
- var nick = mock.chatroom_names[0];
- view.model.occupants.create({
- 'nick': nick,
- 'muc_jid': `${view.model.get('jid')}/${nick}`
- });
- var message = $msg({
- from: 'lounge@localhost/'+nick,
- id: '1',
- to: 'dummy@localhost',
- type: 'groupchat'
- }).c('body').t(text);
- view.model.onMessage(message.nodeTree);
- var $chat_content = $(view.el).find('.chat-content');
- expect($chat_content.find('.chat-msg').length).toBe(1);
- expect($chat_content.find('.chat-msg__text').text()).toBe(text);
- expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
- done();
- });
- }));
- it("shows sent groupchat messages",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
- spyOn(_converse, 'emit');
- var view = _converse.chatboxviews.get('lounge@localhost');
- if (!$(view.el).find('.chat-area').length) { view.renderChatArea(); }
- var text = 'This is a sent message';
- var textarea = view.el.querySelector('.chat-textarea');
- textarea.value = text;
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(_converse.emit).toHaveBeenCalledWith('messageSend', text);
- var $chat_content = $(view.el).find('.chat-content');
- expect($chat_content.find('.chat-msg').length).toBe(1);
- // Let's check that if we receive the same message again, it's
- // not shown.
- var message = $msg({
- from: 'lounge@localhost/dummy',
- to: 'dummy@localhost.com',
- type: 'groupchat',
- id: view.model.messages.at(0).get('msgid')
- }).c('body').t(text);
- view.model.onMessage(message.nodeTree);
- expect($chat_content.find('.chat-msg').length).toBe(1);
- expect($chat_content.find('.chat-msg__text').last().text()).toBe(text);
- // We don't emit an event if it's our own message
- expect(_converse.emit.calls.count(), 1);
- done();
- });
- }));
- it("will cause the chat area to be scrolled down only if it was at the bottom already",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- var message = 'This message is received while the chat area is scrolled up';
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
- var view = _converse.chatboxviews.get('lounge@localhost');
- spyOn(view, 'scrollDown').and.callThrough();
- /* Create enough messages so that there's a
- * scrollbar.
- */
- for (var i=0; i<20; i++) {
- view.model.onMessage(
- $msg({
- from: 'lounge@localhost/someone',
- to: 'dummy@localhost.com',
- type: 'groupchat',
- id: (new Date()).getTime(),
- }).c('body').t('Message: '+i).tree());
- }
- // Give enough time for `markScrolled` to have been called
- setTimeout(() => {
- view.content.scrollTop = 0;
- view.model.onMessage(
- $msg({
- from: 'lounge@localhost/someone',
- to: 'dummy@localhost.com',
- type: 'groupchat',
- id: (new Date()).getTime(),
- }).c('body').t(message).tree());
- // Now check that the message appears inside the chatbox in the DOM
- var $chat_content = $(view.el).find('.chat-content');
- var msg_txt = $chat_content.find('.chat-msg:last').find('.chat-msg__text').text();
- expect(msg_txt).toEqual(message);
- expect(view.content.scrollTop).toBe(0);
- done();
- }, 500);
- });
- }));
- it("shows the room topic in the header",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'jdev', 'conference.jabber.org', 'jc').then(function () {
- var text = 'Jabber/XMPP Development | RFCs and Extensions: http://xmpp.org/ | Protocol and XSF discussions: xsf@muc.xmpp.org';
- var stanza = Strophe.xmlHtmlNode(
- '<message xmlns="jabber:client" to="jc@opkode.com/_converse.js-60429116" type="groupchat" from="jdev@conference.jabber.org/ralphm">'+
- ' <subject>'+text+'</subject>'+
- ' <delay xmlns="urn:xmpp:delay" stamp="2014-02-04T09:35:39Z" from="jdev@conference.jabber.org"/>'+
- ' <x xmlns="jabber:x:delay" stamp="20140204T09:35:39" from="jdev@conference.jabber.org"/>'+
- '</message>').firstChild;
- _converse.connection._dataRecv(test_utils.createRequest(stanza));
- var view = _converse.chatboxviews.get('jdev@conference.jabber.org');
- var chat_content = view.el.querySelector('.chat-content');
- expect($(chat_content).find('.chat-event:last').text()).toBe('Topic set by ralphm');
- expect($(chat_content).find('.chat-topic:last').text()).toBe(text);
- expect(view.el.querySelector('.chatroom-description').textContent).toBe(text);
- done();
- });
- }));
- it("escapes the subject before rendering it, to avoid JS-injection attacks",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'jdev', 'conference.jabber.org', 'jc').then(function () {
- spyOn(window, 'alert');
- var subject = '<img src="x" onerror="alert(\'XSS\');"/>';
- var view = _converse.chatboxviews.get('jdev@conference.jabber.org');
- view.model.set({'subject': {
- 'text': subject,
- 'author': 'ralphm'
- }});
- var chat_content = view.el.querySelector('.chat-content');
- expect($(chat_content).find('.chat-event:last').text()).toBe('Topic set by ralphm');
- expect($(chat_content).find('.chat-topic:last').text()).toBe(subject);
- done();
- });
- }));
- it("informs users if their nicknames has been changed.",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- /* The service then sends two presence stanzas to the full JID
- * of each occupant (including the occupant who is changing his
- * or her room nickname), one of type "unavailable" for the old
- * nickname and one indicating availability for the new
- * nickname.
- *
- * See: http://xmpp.org/extensions/xep-0045.html#changenick
- *
- * <presence
- * from='coven@localhost/thirdwitch'
- * id='DC352437-C019-40EC-B590-AF29E879AF98'
- * to='hag66@shakespeare.lit/pda'
- * type='unavailable'>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='member'
- * jid='hag66@shakespeare.lit/pda'
- * nick='oldhag'
- * role='participant'/>
- * <status code='303'/>
- * <status code='110'/>
- * </x>
- * </presence>
- *
- * <presence
- * from='coven@localhost/oldhag'
- * id='5B4F27A4-25ED-43F7-A699-382C6B4AFC67'
- * to='hag66@shakespeare.lit/pda'>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='member'
- * jid='hag66@shakespeare.lit/pda'
- * role='participant'/>
- * <status code='110'/>
- * </x>
- * </presence>
- */
- var __ = _converse.__;
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'oldnick').then(function () {
- var view = _converse.chatboxviews.get('lounge@localhost');
- var $chat_content = $(view.el).find('.chat-content');
- var $occupants = $(view.el.querySelector('.occupant-list'));
- expect($occupants.children().length).toBe(1);
- expect($occupants.children().first(0).find('.occupant-nick').text().trim()).toBe("oldnick");
- expect($chat_content.find('div.chat-info').length).toBe(1);
- expect($chat_content.find('div.chat-info:first').html()).toBe("oldnick has entered the groupchat");
- var presence = $pres().attrs({
- from:'lounge@localhost/oldnick',
- id:'DC352437-C019-40EC-B590-AF29E879AF98',
- to:'dummy@localhost/pda',
- type:'unavailable'
- })
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- affiliation: 'owner',
- jid: 'dummy@localhost/pda',
- nick: 'newnick',
- role: 'moderator'
- }).up()
- .c('status').attrs({code:'303'}).up()
- .c('status').attrs({code:'110'}).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content.find('div.chat-info').length).toBe(2);
- expect($chat_content.find('div.chat-info').last().html()).toBe(
- __(_converse.muc.new_nickname_messages["303"], "newnick")
- );
- $occupants = $(view.el.querySelector('.occupant-list'));
- expect($occupants.children().length).toBe(1);
- presence = $pres().attrs({
- from:'lounge@localhost/newnick',
- id:'5B4F27A4-25ED-43F7-A699-382C6B4AFC67',
- to:'dummy@localhost/pda'
- })
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- affiliation: 'owner',
- jid: 'dummy@localhost/pda',
- role: 'moderator'
- }).up()
- .c('status').attrs({code:'110'}).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- // XXX: currently we still have an additional "has entered the groupchat"
- // notification for the new nickname. Ideally we'd not have
- // that, but that's probably not possible without some
- // significant refactoring.
- expect($chat_content.find('div.chat-info').length).toBe(3);
- expect($chat_content.find('div.chat-info').get(1).textContent).toBe(
- __(_converse.muc.new_nickname_messages["303"], "newnick")
- );
- $occupants = $(view.el.querySelector('.occupant-list'));
- expect($occupants.children().length).toBe(1);
- expect($occupants.children().find('.occupant-nick').first(0).text()).toBe("newnick");
- done();
- });
- }));
- it("queries for the groupchat information before attempting to join the user",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- const IQ_stanzas = _converse.connection.IQ_stanzas;
- const room_jid = 'coven@chat.shakespeare.lit';
- _converse.api.rooms.open(room_jid, {'nick': 'some1'})
- .then(() => {
- return test_utils.waitUntil(() => _.get(_.filter(
- IQ_stanzas,
- iq => iq.nodeTree.querySelector(
- `iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
- )).pop(), 'nodeTree'));
- }).then(stanza => {
- // Check that the groupchat queried for the feautures.
- expect(stanza.outerHTML).toBe(
- `<iq from="dummy@localhost/resource" to="${room_jid}" type="get" xmlns="jabber:client" id="${stanza.getAttribute("id")}">`+
- `<query xmlns="http://jabber.org/protocol/disco#info"/>`+
- `</iq>`);
- /* <iq from='coven@chat.shakespeare.lit'
- * id='ik3vs715'
- * to='hag66@shakespeare.lit/pda'
- * type='result'>
- * <query xmlns='http://jabber.org/protocol/disco#info'>
- * <identity
- * category='conference'
- * name='A Dark Cave'
- * type='text'/>
- * <feature var='http://jabber.org/protocol/muc'/>
- * <feature var='muc_passwordprotected'/>
- * <feature var='muc_hidden'/>
- * <feature var='muc_temporary'/>
- * <feature var='muc_open'/>
- * <feature var='muc_unmoderated'/>
- * <feature var='muc_nonanonymous'/>
- * </query>
- * </iq>
- */
- const features_stanza = $iq({
- 'from': room_jid,
- 'id': stanza.getAttribute('id'),
- 'to': 'dummy@localhost/desktop',
- 'type': 'result'
- })
- .c('query', { 'xmlns': 'http://jabber.org/protocol/disco#info'})
- .c('identity', {
- 'category': 'conference',
- 'name': 'A Dark Cave',
- 'type': 'text'
- }).up()
- .c('feature', {'var': 'http://jabber.org/protocol/muc'}).up()
- .c('feature', {'var': 'muc_passwordprotected'}).up()
- .c('feature', {'var': 'muc_hidden'}).up()
- .c('feature', {'var': 'muc_temporary'}).up()
- .c('feature', {'var': 'muc_open'}).up()
- .c('feature', {'var': 'muc_unmoderated'}).up()
- .c('feature', {'var': 'muc_nonanonymous'});
- _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
- const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- return test_utils.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING));
- }).then(() => {
- const view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- expect(view.model.get('features_fetched')).toBeTruthy();
- expect(view.model.get('passwordprotected')).toBe(true);
- expect(view.model.get('hidden')).toBe(true);
- expect(view.model.get('temporary')).toBe(true);
- expect(view.model.get('open')).toBe(true);
- expect(view.model.get('unmoderated')).toBe(true);
- expect(view.model.get('nonanonymous')).toBe(true);
- done();
- }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
- }));
- it("updates the shown features when the groupchat configuration has changed",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- var sent_IQ, IQ_id;
- var sendIQ = _converse.connection.sendIQ;
- test_utils.openAndEnterChatRoom(_converse, 'room', 'conference.example.org', 'dummy').then(function () {
- var view = _converse.chatboxviews.get('room@conference.example.org');
- view.model.set({
- 'passwordprotected': false,
- 'unsecured': true,
- 'hidden': false,
- 'public': true,
- 'membersonly': false,
- 'open': true,
- 'persistent': false,
- 'temporary': true,
- 'nonanonymous': true,
- 'semianonymous': false,
- 'moderated': false,
- 'unmoderated': true
- });
- expect(view.model.get('persistent')).toBe(false);
- expect(view.model.get('temporary')).toBe(true);
- view.model.set({'persistent': true});
- expect(view.model.get('persistent')).toBe(true);
- expect(view.model.get('temporary')).toBe(false);
- expect(view.model.get('unsecured')).toBe(true);
- expect(view.model.get('passwordprotected')).toBe(false);
- view.model.set({'passwordprotected': true});
- expect(view.model.get('unsecured')).toBe(false);
- expect(view.model.get('passwordprotected')).toBe(true);
- expect(view.model.get('unmoderated')).toBe(true);
- expect(view.model.get('moderated')).toBe(false);
- view.model.set({'moderated': true});
- expect(view.model.get('unmoderated')).toBe(false);
- expect(view.model.get('moderated')).toBe(true);
- expect(view.model.get('nonanonymous')).toBe(true);
- expect(view.model.get('semianonymous')).toBe(false);
- view.model.set({'nonanonymous': false});
- expect(view.model.get('nonanonymous')).toBe(false);
- expect(view.model.get('semianonymous')).toBe(true);
- expect(view.model.get('open')).toBe(true);
- expect(view.model.get('membersonly')).toBe(false);
- view.model.set({'membersonly': true});
- expect(view.model.get('open')).toBe(false);
- expect(view.model.get('membersonly')).toBe(true);
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("indicates when a room is no longer anonymous",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- var sent_IQ, IQ_id;
- var sendIQ = _converse.connection.sendIQ;
- test_utils.openAndEnterChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'some1').then(function () {
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
- sent_IQ = iq;
- IQ_id = sendIQ.bind(this)(iq, callback, errback);
- });
- // We pretend this is a new room, so no disco info is returned.
- var features_stanza = $iq({
- from: 'coven@chat.shakespeare.lit',
- 'id': IQ_id,
- 'to': 'dummy@localhost/desktop',
- 'type': 'error'
- }).c('error', {'type': 'cancel'})
- .c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"});
- _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
- var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- /* <message xmlns="jabber:client"
- * type="groupchat"
- * to="dummy@localhost/_converse.js-27854181"
- * from="coven@chat.shakespeare.lit">
- * <x xmlns="http://jabber.org/protocol/muc#user">
- * <status code="104"/>
- * <status code="172"/>
- * </x>
- * </message>
- */
- var message = $msg({
- type:'groupchat',
- to: 'dummy@localhost/_converse.js-27854181',
- from: 'coven@chat.shakespeare.lit'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('status', {code: '104'}).up()
- .c('status', {code: '172'});
- _converse.connection._dataRecv(test_utils.createRequest(message));
- var $chat_body = $(view.el.querySelector('.chatroom-body'));
- expect($chat_body.find('.message:last').text()).toBe('This groupchat is now no longer anonymous');
- done();
- });
- }));
- it("informs users if they have been kicked out of the groupchat",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- /* <presence
- * from='harfleur@chat.shakespeare.lit/pistol'
- * to='pistol@shakespeare.lit/harfleur'
- * type='unavailable'>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='none' role='none'>
- * <actor nick='Fluellen'/>
- * <reason>Avaunt, you cullion!</reason>
- * </item>
- * <status code='110'/>
- * <status code='307'/>
- * </x>
- * </presence>
- */
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy')
- .then(() => {
- var presence = $pres().attrs({
- from:'lounge@localhost/dummy',
- to:'dummy@localhost/pda',
- type:'unavailable'
- })
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc#user'})
- .c('item').attrs({
- affiliation: 'none',
- jid: 'dummy@localhost/pda',
- role: 'none'
- })
- .c('actor').attrs({nick: 'Fluellen'}).up()
- .c('reason').t('Avaunt, you cullion!').up()
- .up()
- .c('status').attrs({code:'110'}).up()
- .c('status').attrs({code:'307'}).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- const view = _converse.chatboxviews.get('lounge@localhost');
- expect($(view.el.querySelector('.chat-area')).is(':visible')).toBeFalsy();
- expect($(view.el.querySelector('.occupants')).is(':visible')).toBeFalsy();
- const chat_body = view.el.querySelector('.chatroom-body');
- expect(chat_body.querySelectorAll('.disconnect-msg').length).toBe(3);
- expect(chat_body.querySelector('.disconnect-msg:first-child').textContent).toBe(
- 'You have been kicked from this groupchat');
- expect(chat_body.querySelector('.disconnect-msg:nth-child(2)').textContent).toBe(
- 'This action was done by Fluellen.');
- expect(chat_body.querySelector('.disconnect-msg:nth-child(3)').textContent).toBe(
- 'The reason given is: "Avaunt, you cullion!".');
- done();
- });
- }));
- it("can be saved to, and retrieved from, browserStorage",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy')
- .then(() => {
- // We instantiate a new ChatBoxes collection, which by default
- // will be empty.
- test_utils.openControlBox();
- var newchatboxes = new _converse.ChatBoxes();
- expect(newchatboxes.length).toEqual(0);
- // The chatboxes will then be fetched from browserStorage inside the
- // onConnected method
- newchatboxes.onConnected();
- expect(newchatboxes.length).toEqual(2);
- // Check that the chatrooms retrieved from browserStorage
- // have the same attributes values as the original ones.
- var attrs = ['id', 'box_id', 'visible'];
- var new_attrs, old_attrs;
- for (var i=0; i<attrs.length; i++) {
- new_attrs = _.map(_.map(newchatboxes.models, 'attributes'), attrs[i]);
- old_attrs = _.map(_.map(_converse.chatboxes.models, 'attributes'), attrs[i]);
- // FIXME: should have have to sort here? Order must
- // probably be the same...
- // This should be fixed once the controlbox always opens
- // only on the right.
- expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
- }
- _converse.rosterview.render();
- done();
- });
- }));
- it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy')
- .then(() => {
- const view = _converse.chatboxviews.get('lounge@localhost'),
- trimmed_chatboxes = _converse.minimized_chats;
- spyOn(view, 'minimize').and.callThrough();
- spyOn(view, 'maximize').and.callThrough();
- spyOn(_converse, 'emit');
- view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
- view.el.querySelector('.toggle-chatbox-button').click();
- expect(view.minimize).toHaveBeenCalled();
- expect(_converse.emit).toHaveBeenCalledWith('chatBoxMinimized', jasmine.any(Object));
- expect(u.isVisible(view.el)).toBeFalsy();
- expect(view.model.get('minimized')).toBeTruthy();
- expect(view.minimize).toHaveBeenCalled();
- var trimmedview = trimmed_chatboxes.get(view.model.get('id'));
- trimmedview.el.querySelector("a.restore-chat").click();
- expect(view.maximize).toHaveBeenCalled();
- expect(_converse.emit).toHaveBeenCalledWith('chatBoxMaximized', jasmine.any(Object));
- expect(view.model.get('minimized')).toBeFalsy();
- expect(_converse.emit.calls.count(), 3);
- done();
- });
- }));
- it("can be closed again by clicking a DOM element with class 'close-chatbox-button'",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy')
- .then(() => {
- const view = _converse.chatboxviews.get('lounge@localhost');
- spyOn(view, 'close').and.callThrough();
- spyOn(_converse, 'emit');
- spyOn(view.model, 'leave');
- view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
- view.el.querySelector('.close-chatbox-button').click();
- expect(view.close).toHaveBeenCalled();
- expect(view.model.leave).toHaveBeenCalled();
- expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
- done();
- });
- }));
- });
- describe("Each chat groupchat can take special commands", function () {
- it("takes /help to show the available commands",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
- var view = _converse.chatboxviews.get('lounge@localhost');
- spyOn(view, 'onMessageSubmitted').and.callThrough();
- var textarea = view.el.querySelector('.chat-textarea');
- textarea.value = '/help This is the groupchat subject';
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(view.onMessageSubmitted).toHaveBeenCalled();
- const info_messages = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
- expect(info_messages.length).toBe(18);
- expect(info_messages.pop().textContent).toBe('/voice: Allow muted user to post messages');
- expect(info_messages.pop().textContent).toBe('/topic: Set groupchat subject (alias for /subject)');
- expect(info_messages.pop().textContent).toBe('/subject: Set groupchat subject');
- expect(info_messages.pop().textContent).toBe('/revoke: Revoke user\'s membership');
- expect(info_messages.pop().textContent).toBe('/register: Register a nickname for this room');
- expect(info_messages.pop().textContent).toBe('/owner: Grant ownership of this groupchat');
- expect(info_messages.pop().textContent).toBe('/op: Grant moderator role to user');
- expect(info_messages.pop().textContent).toBe('/nick: Change your nickname');
- expect(info_messages.pop().textContent).toBe('/mute: Remove user\'s ability to post messages');
- expect(info_messages.pop().textContent).toBe('/member: Grant membership to a user');
- expect(info_messages.pop().textContent).toBe('/me: Write in 3rd person');
- expect(info_messages.pop().textContent).toBe('/kick: Kick user from groupchat');
- expect(info_messages.pop().textContent).toBe('/help: Show this menu');
- expect(info_messages.pop().textContent).toBe('/deop: Change user role to participant');
- expect(info_messages.pop().textContent).toBe('/clear: Remove messages');
- expect(info_messages.pop().textContent).toBe('/ban: Ban user from groupchat');
- expect(info_messages.pop().textContent).toBe('/admin: Change user\'s affiliation to admin');
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("takes /member to make an occupant a member",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- let iq_stanza, view;
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'muc.localhost', 'dummy')
- .then(() => {
- view = _converse.chatboxviews.get('lounge@muc.localhost');
- /* We don't show join/leave messages for existing occupants. We
- * know about them because we receive their presences before we
- * receive our own.
- */
- const presence = $pres({
- to: 'dummy@localhost/resource',
- from: 'lounge@muc.localhost/marc'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'marc@localhost/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.model.occupants.length).toBe(2);
- const textarea = view.el.querySelector('.chat-textarea');
- let sent_stanza;
- spyOn(_converse.connection, 'send').and.callFake((stanza) => {
- sent_stanza = stanza;
- });
- // First check that an error message appears when a
- // non-existent nick is used.
- textarea.value = '/member chris Welcome to the club!';
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(_converse.connection.send).not.toHaveBeenCalled();
- expect(view.el.querySelectorAll('.chat-error').length).toBe(1);
- expect(view.el.querySelector('.chat-error').textContent.trim())
- .toBe(`Error: couldn't find a groupchat participant "chris"`)
- // Now test with an existing nick
- textarea.value = '/member marc Welcome to the club!';
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(_converse.connection.send).toHaveBeenCalled();
- expect(sent_stanza.outerHTML).toBe(
- `<iq to="lounge@muc.localhost" type="set" xmlns="jabber:client" id="${sent_stanza.getAttribute('id')}">`+
- `<query xmlns="http://jabber.org/protocol/muc#admin">`+
- `<item affiliation="member" jid="marc@localhost">`+
- `<reason>Welcome to the club!</reason>`+
- `</item>`+
- `</query>`+
- `</iq>`);
- const result = $iq({
- "xmlns": "jabber:client",
- "type": "result",
- "to": "dummy@localhost/resource",
- "from": "lounge@muc.localhost",
- "id": sent_stanza.getAttribute('id')
- });
- _converse.connection.IQ_stanzas = [];
- _converse.connection._dataRecv(test_utils.createRequest(result));
- return test_utils.waitUntil(() => {
- return _.filter(
- _converse.connection.IQ_stanzas,
- (iq) => {
- const node = iq.nodeTree.querySelector('iq[to="lounge@muc.localhost"][type="get"] item[affiliation="member"]');
- if (node) { iq_stanza = iq.nodeTree;}
- return node;
- }).length;
- });
- }).then(() => {
- expect(iq_stanza.outerHTML).toBe(
- `<iq to="lounge@muc.localhost" type="get" xmlns="jabber:client" id="${iq_stanza.getAttribute('id')}">`+
- `<query xmlns="http://jabber.org/protocol/muc#admin">`+
- `<item affiliation="member"/>`+
- `</query>`+
- `</iq>`)
- expect(view.model.occupants.length).toBe(2);
- const result = $iq({
- "xmlns": "jabber:client",
- "type": "result",
- "to": "dummy@localhost/resource",
- "from": "lounge@muc.localhost",
- "id": iq_stanza.getAttribute("id")
- }).c("query", {"xmlns": "http://jabber.org/protocol/muc#admin"})
- .c("item", {"jid": "marc", "affiliation": "member"});
- _converse.connection._dataRecv(test_utils.createRequest(result));
- expect(view.model.occupants.length).toBe(2);
- return test_utils.waitUntil(() => {
- return _.filter(
- _converse.connection.IQ_stanzas,
- (iq) => {
- const node = iq.nodeTree.querySelector('iq[to="lounge@muc.localhost"][type="get"] item[affiliation="owner"]');
- if (node) { iq_stanza = iq.nodeTree;}
- return node;
- }).length;
- });
- }).then(() => {
- expect(iq_stanza.outerHTML).toBe(
- `<iq to="lounge@muc.localhost" type="get" xmlns="jabber:client" id="${iq_stanza.getAttribute('id')}">`+
- `<query xmlns="http://jabber.org/protocol/muc#admin">`+
- `<item affiliation="owner"/>`+
- `</query>`+
- `</iq>`)
- expect(view.model.occupants.length).toBe(2);
- const result = $iq({
- "xmlns": "jabber:client",
- "type": "result",
- "to": "dummy@localhost/resource",
- "from": "lounge@muc.localhost",
- "id": iq_stanza.getAttribute("id")
- }).c("query", {"xmlns": "http://jabber.org/protocol/muc#admin"})
- .c("item", {"jid": "dummy@localhost", "affiliation": "owner"});
- _converse.connection._dataRecv(test_utils.createRequest(result));
- expect(view.model.occupants.length).toBe(2);
- return test_utils.waitUntil(() => {
- return _.filter(
- _converse.connection.IQ_stanzas,
- (iq) => {
- const node = iq.nodeTree.querySelector('iq[to="lounge@muc.localhost"][type="get"] item[affiliation="admin"]');
- if (node) { iq_stanza = iq.nodeTree;}
- return node;
- }).length;
- });
- }).then(() => {
- expect(iq_stanza.outerHTML).toBe(
- `<iq to="lounge@muc.localhost" type="get" xmlns="jabber:client" id="${iq_stanza.getAttribute('id')}">`+
- `<query xmlns="http://jabber.org/protocol/muc#admin">`+
- `<item affiliation="admin"/>`+
- `</query>`+
- `</iq>`)
- expect(view.model.occupants.length).toBe(2);
- const result = $iq({
- "xmlns": "jabber:client",
- "type": "result",
- "to": "dummy@localhost/resource",
- "from": "lounge@muc.localhost",
- "id": iq_stanza.getAttribute("id")
- }).c("query", {"xmlns": "http://jabber.org/protocol/muc#admin"})
- _converse.connection._dataRecv(test_utils.createRequest(result));
- return test_utils.waitUntil(() => view.el.querySelectorAll('.badge').length > 1);
- }).then(() => {
- expect(view.model.occupants.length).toBe(2);
- expect(view.el.querySelectorAll('.occupant').length).toBe(2);
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("takes /topic to set the groupchat topic",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
- var sent_stanza;
- var view = _converse.chatboxviews.get('lounge@localhost');
- spyOn(view, 'onMessageSubmitted').and.callThrough();
- spyOn(view, 'clearMessages');
- spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
- sent_stanza = stanza;
- });
- // Check the alias /topic
- var textarea = view.el.querySelector('.chat-textarea');
- textarea.value = '/topic This is the groupchat subject';
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(view.onMessageSubmitted).toHaveBeenCalled();
- expect(_converse.connection.send).toHaveBeenCalled();
- expect(sent_stanza.textContent).toBe('This is the groupchat subject');
- // Check /subject
- textarea.value = '/subject This is a new subject';
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(sent_stanza.textContent).toBe('This is a new subject');
- expect(sent_stanza.outerHTML).toBe(
- '<message to="lounge@localhost" from="dummy@localhost/resource" type="groupchat" xmlns="jabber:client">'+
- '<subject xmlns="jabber:client">This is a new subject</subject>'+
- '</message>');
- // Check case insensitivity
- textarea.value = '/Subject This is yet another subject';
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(sent_stanza.textContent).toBe('This is yet another subject');
- expect(sent_stanza.outerHTML).toBe(
- '<message to="lounge@localhost" from="dummy@localhost/resource" type="groupchat" xmlns="jabber:client">'+
- '<subject xmlns="jabber:client">This is yet another subject</subject>'+
- '</message>');
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("takes /clear to clear messages",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
- var view = _converse.chatboxviews.get('lounge@localhost');
- spyOn(view, 'onMessageSubmitted').and.callThrough();
- spyOn(view, 'clearMessages');
- var textarea = view.el.querySelector('.chat-textarea')
- textarea.value = '/clear';
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(view.onMessageSubmitted).toHaveBeenCalled();
- expect(view.clearMessages).toHaveBeenCalled();
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("takes /owner to make a user an owner",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- let sent_IQ, IQ_id;
- const sendIQ = _converse.connection.sendIQ;
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
- sent_IQ = iq;
- IQ_id = sendIQ.bind(this)(iq, callback, errback);
- });
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
- var view = _converse.chatboxviews.get('lounge@localhost');
- spyOn(view, 'onMessageSubmitted').and.callThrough();
- spyOn(view.model, 'setAffiliation').and.callThrough();
- spyOn(view, 'showErrorMessage').and.callThrough();
- spyOn(view, 'validateRoleChangeCommand').and.callThrough();
- let presence = $pres({
- 'from': 'lounge@localhost/annoyingGuy',
- 'id':'27C55F89-1C6A-459A-9EB5-77690145D624',
- 'to': 'dummy@localhost/desktop'
- })
- .c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
- .c('item', {
- 'jid': 'annoyingguy@localhost',
- 'affiliation': 'member',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- var textarea = view.el.querySelector('.chat-textarea')
- textarea.value = '/owner';
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(view.onMessageSubmitted).toHaveBeenCalled();
- expect(view.validateRoleChangeCommand).toHaveBeenCalled();
- expect(view.showErrorMessage).toHaveBeenCalledWith(
- "Error: the \"owner\" command takes two arguments, the user's nickname and optionally a reason.");
- expect(view.model.setAffiliation).not.toHaveBeenCalled();
- view.onMessageSubmitted('/owner nobody You\'re responsible');
- expect(view.showErrorMessage).toHaveBeenCalledWith(
- 'Error: couldn\'t find a groupchat participant "nobody"');
- expect(view.model.setAffiliation).not.toHaveBeenCalled();
- // Call now with the correct amount of arguments.
- // XXX: Calling onMessageSubmitted directly, trying
- // again via triggering Event doesn't work for some weird
- // reason.
- view.onMessageSubmitted('/owner annoyingGuy You\'re responsible');
- expect(view.validateRoleChangeCommand.calls.count()).toBe(3);
- expect(view.model.setAffiliation).toHaveBeenCalled();
- expect(view.showErrorMessage.calls.count()).toBe(2);
- // Check that the member list now gets updated
- expect(sent_IQ.toLocaleString()).toBe(
- "<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#admin'>"+
- "<item affiliation='owner' jid='annoyingGuy'>"+
- "<reason>You're responsible</reason>"+
- "</item>"+
- "</query>"+
- "</iq>");
- presence = $pres({
- 'from': 'lounge@localhost/annoyingGuy',
- 'id':'27C55F89-1C6A-459A-9EB5-77690145D628',
- 'to': 'dummy@localhost/desktop'
- })
- .c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
- .c('item', {
- 'jid': 'annoyingguy@localhost',
- 'affiliation': 'owner',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.el.querySelectorAll('.chat-info')[4].textContent).toBe("annoyingGuy is now an owner of this groupchat");
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("takes /ban to ban a user",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- let sent_IQ, IQ_id;
- const sendIQ = _converse.connection.sendIQ;
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
- sent_IQ = iq;
- IQ_id = sendIQ.bind(this)(iq, callback, errback);
- });
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy')
- .then(() => {
- const view = _converse.chatboxviews.get('lounge@localhost');
- spyOn(view, 'onMessageSubmitted').and.callThrough();
- spyOn(view.model, 'setAffiliation').and.callThrough();
- spyOn(view, 'showErrorMessage').and.callThrough();
- spyOn(view, 'validateRoleChangeCommand').and.callThrough();
- let presence = $pres({
- 'from': 'lounge@localhost/annoyingGuy',
- 'id':'27C55F89-1C6A-459A-9EB5-77690145D624',
- 'to': 'dummy@localhost/desktop'
- })
- .c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
- .c('item', {
- 'jid': 'annoyingguy@localhost',
- 'affiliation': 'member',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- const textarea = view.el.querySelector('.chat-textarea')
- textarea.value = '/ban';
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(view.onMessageSubmitted).toHaveBeenCalled();
- expect(view.validateRoleChangeCommand).toHaveBeenCalled();
- expect(view.showErrorMessage).toHaveBeenCalledWith(
- "Error: the \"ban\" command takes two arguments, the user's nickname and optionally a reason.");
- expect(view.model.setAffiliation).not.toHaveBeenCalled();
- // Call now with the correct amount of arguments.
- // XXX: Calling onMessageSubmitted directly, trying
- // again via triggering Event doesn't work for some weird
- // reason.
- view.onMessageSubmitted('/ban annoyingGuy You\'re annoying');
- expect(view.validateRoleChangeCommand.calls.count()).toBe(2);
- expect(view.showErrorMessage.calls.count()).toBe(1);
- expect(view.model.setAffiliation).toHaveBeenCalled();
- // Check that the member list now gets updated
- expect(sent_IQ.toLocaleString()).toBe(
- "<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#admin'>"+
- "<item affiliation='outcast' jid='annoyingGuy'>"+
- "<reason>You're annoying</reason>"+
- "</item>"+
- "</query>"+
- "</iq>");
- presence = $pres({
- 'from': 'lounge@localhost/annoyingGuy',
- 'id':'27C55F89-1C6A-459A-9EB5-77690145D628',
- 'to': 'dummy@localhost/desktop'
- })
- .c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
- .c('item', {
- 'jid': 'annoyingguy@localhost',
- 'affiliation': 'outcast',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(
- view.el.querySelectorAll('.chat-info')[3].textContent).toBe(
- "annoyingGuy has been banned from this groupchat");
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("takes /kick to kick a user",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- let sent_IQ, IQ_id;
- const sendIQ = _converse.connection.sendIQ;
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
- sent_IQ = iq;
- IQ_id = sendIQ.bind(this)(iq, callback, errback);
- });
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
- const view = _converse.chatboxviews.get('lounge@localhost');
- spyOn(view, 'onMessageSubmitted').and.callThrough();
- spyOn(view, 'modifyRole').and.callThrough();
- spyOn(view, 'showErrorMessage').and.callThrough();
- spyOn(view, 'validateRoleChangeCommand').and.callThrough();
- let presence = $pres({
- 'from': 'lounge@localhost/annoyingGuy',
- 'id':'27C55F89-1C6A-459A-9EB5-77690145D624',
- 'to': 'dummy@localhost/desktop'
- })
- .c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
- .c('item', {
- 'jid': 'annoyingguy@localhost',
- 'affiliation': 'none',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- var textarea = view.el.querySelector('.chat-textarea')
- textarea.value = '/kick';
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(view.onMessageSubmitted).toHaveBeenCalled();
- expect(view.validateRoleChangeCommand).toHaveBeenCalled();
- expect(view.showErrorMessage).toHaveBeenCalledWith(
- "Error: the \"kick\" command takes two arguments, the user's nickname and optionally a reason.");
- expect(view.modifyRole).not.toHaveBeenCalled();
- // Call now with the correct amount of arguments.
- // XXX: Calling onMessageSubmitted directly, trying
- // again via triggering Event doesn't work for some weird
- // reason.
- view.onMessageSubmitted('/kick annoyingGuy You\'re annoying');
- expect(view.validateRoleChangeCommand.calls.count()).toBe(2);
- expect(view.showErrorMessage.calls.count()).toBe(1);
- expect(view.modifyRole).toHaveBeenCalled();
- expect(sent_IQ.toLocaleString()).toBe(
- "<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#admin'>"+
- "<item nick='annoyingGuy' role='none'>"+
- "<reason>You're annoying</reason>"+
- "</item>"+
- "</query>"+
- "</iq>");
- /* <presence
- * from='harfleur@chat.shakespeare.lit/pistol'
- * to='gower@shakespeare.lit/cell'
- * type='unavailable'>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='none' role='none'/>
- * <status code='307'/>
- * </x>
- * </presence>
- */
- presence = $pres({
- 'from': 'lounge@localhost/annoyingGuy',
- 'to': 'dummy@localhost/desktop',
- 'type': 'unavailable'
- })
- .c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
- .c('item', {
- 'affiliation': 'none',
- 'role': 'none'
- }).up()
- .c('status', {'code': '307'});
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.el.querySelectorAll('.chat-info')[3].textContent).toBe("annoyingGuy has been kicked out");
- expect(view.el.querySelectorAll('.chat-info').length).toBe(4);
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("takes /op and /deop to make a user a moderator or not",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy').then(function () {
- var sent_IQ, IQ_id;
- var sendIQ = _converse.connection.sendIQ;
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
- sent_IQ = iq;
- IQ_id = sendIQ.bind(this)(iq, callback, errback);
- });
- var view = _converse.chatboxviews.get('lounge@localhost');
- spyOn(view, 'onMessageSubmitted').and.callThrough();
- spyOn(view, 'modifyRole').and.callThrough();
- spyOn(view, 'showErrorMessage').and.callThrough();
- spyOn(view, 'showChatEvent').and.callThrough();
- spyOn(view, 'validateRoleChangeCommand').and.callThrough();
- // New user enters the groupchat
- /* <presence
- * from='coven@chat.shakespeare.lit/thirdwitch'
- * id='27C55F89-1C6A-459A-9EB5-77690145D624'
- * to='crone1@shakespeare.lit/desktop'>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='member' role='moderator'/>
- * </x>
- * </presence>
- */
- var presence = $pres({
- 'from': 'lounge@localhost/trustworthyguy',
- 'id':'27C55F89-1C6A-459A-9EB5-77690145D624',
- 'to': 'dummy@localhost/desktop'
- })
- .c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
- .c('item', {
- 'jid': 'trustworthyguy@localhost',
- 'affiliation': 'member',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- var info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
- expect(info_msgs.pop().textContent).toBe("trustworthyguy has entered the groupchat");
- var textarea = view.el.querySelector('.chat-textarea')
- textarea.value = '/op';
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(view.onMessageSubmitted).toHaveBeenCalled();
- expect(view.validateRoleChangeCommand).toHaveBeenCalled();
- expect(view.showErrorMessage).toHaveBeenCalledWith(
- "Error: the \"op\" command takes two arguments, the user's nickname and optionally a reason.");
- expect(view.modifyRole).not.toHaveBeenCalled();
- // Call now with the correct amount of arguments.
- // XXX: Calling onMessageSubmitted directly, trying
- // again via triggering Event doesn't work for some weird
- // reason.
- view.onMessageSubmitted('/op trustworthyguy You\'re trustworthy');
- expect(view.validateRoleChangeCommand.calls.count()).toBe(2);
- expect(view.showErrorMessage.calls.count()).toBe(1);
- expect(view.modifyRole).toHaveBeenCalled();
- expect(sent_IQ.toLocaleString()).toBe(
- "<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#admin'>"+
- "<item nick='trustworthyguy' role='moderator'>"+
- "<reason>You're trustworthy</reason>"+
- "</item>"+
- "</query>"+
- "</iq>");
- /* <presence
- * from='coven@chat.shakespeare.lit/thirdwitch'
- * to='crone1@shakespeare.lit/desktop'>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='member'
- * jid='hag66@shakespeare.lit/pda'
- * role='moderator'/>
- * </x>
- * </presence>
- */
- presence = $pres({
- 'from': 'lounge@localhost/trustworthyguy',
- 'to': 'dummy@localhost/desktop'
- })
- .c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
- .c('item', {
- 'jid': 'trustworthyguy@localhost',
- 'affiliation': 'member',
- 'role': 'moderator'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
- expect(info_msgs.pop().textContent).toBe("trustworthyguy is now a moderator");
- view.onMessageSubmitted('/deop trustworthyguy Perhaps not');
- expect(view.validateRoleChangeCommand.calls.count()).toBe(3);
- expect(view.showChatEvent.calls.count()).toBe(1);
- expect(view.modifyRole).toHaveBeenCalled();
- expect(sent_IQ.toLocaleString()).toBe(
- "<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#admin'>"+
- "<item nick='trustworthyguy' role='participant'>"+
- "<reason>Perhaps not</reason>"+
- "</item>"+
- "</query>"+
- "</iq>");
- /* <presence
- * from='coven@chat.shakespeare.lit/thirdwitch'
- * to='crone1@shakespeare.lit/desktop'>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='member'
- * jid='hag66@shakespeare.lit/pda'
- * role='participant'/>
- * </x>
- * </presence>
- */
- presence = $pres({
- 'from': 'lounge@localhost/trustworthyguy',
- 'to': 'dummy@localhost/desktop'
- }).c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
- .c('item', {
- 'jid': 'trustworthyguy@localhost',
- 'affiliation': 'member',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
- expect(info_msgs.pop().textContent).toBe("trustworthyguy is no longer a moderator");
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("takes /mute and /voice to mute and unmute a user",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy')
- .then(() => {
- var sent_IQ, IQ_id;
- var sendIQ = _converse.connection.sendIQ;
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
- sent_IQ = iq;
- IQ_id = sendIQ.bind(this)(iq, callback, errback);
- });
- var view = _converse.chatboxviews.get('lounge@localhost');
- spyOn(view, 'onMessageSubmitted').and.callThrough();
- spyOn(view, 'modifyRole').and.callThrough();
- spyOn(view, 'showErrorMessage').and.callThrough();
- spyOn(view, 'showChatEvent').and.callThrough();
- spyOn(view, 'validateRoleChangeCommand').and.callThrough();
- // New user enters the groupchat
- /* <presence
- * from='coven@chat.shakespeare.lit/thirdwitch'
- * id='27C55F89-1C6A-459A-9EB5-77690145D624'
- * to='crone1@shakespeare.lit/desktop'>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='member' role='participant'/>
- * </x>
- * </presence>
- */
- var presence = $pres({
- 'from': 'lounge@localhost/annoyingGuy',
- 'id':'27C55F89-1C6A-459A-9EB5-77690145D624',
- 'to': 'dummy@localhost/desktop'
- })
- .c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
- .c('item', {
- 'jid': 'annoyingguy@localhost',
- 'affiliation': 'member',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- var info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
- expect(info_msgs.pop().textContent).toBe("annoyingGuy has entered the groupchat");
- var textarea = view.el.querySelector('.chat-textarea')
- textarea.value = '/mute';
- view.keyPressed({
- target: textarea,
- preventDefault: _.noop,
- keyCode: 13
- });
- expect(view.onMessageSubmitted).toHaveBeenCalled();
- expect(view.validateRoleChangeCommand).toHaveBeenCalled();
- expect(view.showErrorMessage).toHaveBeenCalledWith(
- "Error: the \"mute\" command takes two arguments, the user's nickname and optionally a reason.");
- expect(view.modifyRole).not.toHaveBeenCalled();
- // Call now with the correct amount of arguments.
- // XXX: Calling onMessageSubmitted directly, trying
- // again via triggering Event doesn't work for some weird
- // reason.
- view.onMessageSubmitted('/mute annoyingGuy You\'re annoying');
- expect(view.validateRoleChangeCommand.calls.count()).toBe(2);
- expect(view.showErrorMessage.calls.count()).toBe(1);
- expect(view.modifyRole).toHaveBeenCalled();
- expect(sent_IQ.toLocaleString()).toBe(
- "<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#admin'>"+
- "<item nick='annoyingGuy' role='visitor'>"+
- "<reason>You're annoying</reason>"+
- "</item>"+
- "</query>"+
- "</iq>");
- /* <presence
- * from='coven@chat.shakespeare.lit/thirdwitch'
- * to='crone1@shakespeare.lit/desktop'>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='member'
- * jid='hag66@shakespeare.lit/pda'
- * role='visitor'/>
- * </x>
- * </presence>
- */
- presence = $pres({
- 'from': 'lounge@localhost/annoyingGuy',
- 'to': 'dummy@localhost/desktop'
- })
- .c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
- .c('item', {
- 'jid': 'annoyingguy@localhost',
- 'affiliation': 'member',
- 'role': 'visitor'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
- expect(info_msgs.pop().textContent).toBe("annoyingGuy has been muted");
- view.onMessageSubmitted('/voice annoyingGuy Now you can talk again');
- expect(view.validateRoleChangeCommand.calls.count()).toBe(3);
- expect(view.showChatEvent.calls.count()).toBe(1);
- expect(view.modifyRole).toHaveBeenCalled();
- expect(sent_IQ.toLocaleString()).toBe(
- "<iq to='lounge@localhost' type='set' xmlns='jabber:client' id='"+IQ_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#admin'>"+
- "<item nick='annoyingGuy' role='participant'>"+
- "<reason>Now you can talk again</reason>"+
- "</item>"+
- "</query>"+
- "</iq>");
- /* <presence
- * from='coven@chat.shakespeare.lit/thirdwitch'
- * to='crone1@shakespeare.lit/desktop'>
- * <x xmlns='http://jabber.org/protocol/muc#user'>
- * <item affiliation='member'
- * jid='hag66@shakespeare.lit/pda'
- * role='visitor'/>
- * </x>
- * </presence>
- */
- presence = $pres({
- 'from': 'lounge@localhost/annoyingGuy',
- 'to': 'dummy@localhost/desktop'
- })
- .c('x', { 'xmlns': 'http://jabber.org/protocol/muc#user'})
- .c('item', {
- 'jid': 'annoyingguy@localhost',
- 'affiliation': 'member',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- info_msgs = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info'), 0);
- expect(info_msgs.pop().textContent).toBe("annoyingGuy has been given a voice again");
- done();
- }).catch(_.partial(console.error, _));
- }));
- });
- describe("When attempting to enter a groupchat", function () {
- it("will use the nickname set in the global settings if the user doesn't have a VCard nickname",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'nickname': 'Benedict-Cucumberpatch'},
- function (done, _converse) {
- test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost')
- .then(function () {
- const view = _converse.chatboxviews.get('problematic@muc.localhost');
- expect(view.model.get('nick')).toBe('Benedict-Cucumberpatch');
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("will show an error message if the groupchat requires a password",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
- .then(function () {
- var view = _converse.chatboxviews.get('problematic@muc.localhost');
- spyOn(view, 'renderPasswordForm').and.callThrough();
- var presence = $pres().attrs({
- from:'problematic@muc.localhost/dummy',
- id:'n13mt3l',
- to:'dummy@localhost/pda',
- type:'error'})
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
- .c('error').attrs({by:'lounge@localhost', type:'auth'})
- .c('not-authorized').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'});
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- var $chat_body = $(view.el).find('.chatroom-body');
- expect(view.renderPasswordForm).toHaveBeenCalled();
- expect($chat_body.find('form.chatroom-form').length).toBe(1);
- expect($chat_body.find('legend').text()).toBe('This groupchat requires a password');
- // Let's submit the form
- spyOn(view, 'join');
- var input_el = view.el.querySelector('[name="password"]');
- input_el.value = 'secret';
- view.el.querySelector('input[type=submit]').click();
- expect(view.join).toHaveBeenCalledWith('dummy', 'secret');
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("will show an error message if the groupchat is members-only and the user not included",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
- .then(function () {
- var presence = $pres().attrs({
- from:'problematic@muc.localhost/dummy',
- id:'n13mt3l',
- to:'dummy@localhost/pda',
- type:'error'})
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
- .c('error').attrs({by:'lounge@localhost', type:'auth'})
- .c('registration-required').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
- var view = _converse.chatboxviews.get('problematic@muc.localhost');
- spyOn(view, 'showErrorMessage').and.callThrough();
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
- .toBe('You are not on the member list of this groupchat.');
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("will show an error message if the user has been banned",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
- .then(function () {
- var presence = $pres().attrs({
- from:'problematic@muc.localhost/dummy',
- id:'n13mt3l',
- to:'dummy@localhost/pda',
- type:'error'})
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
- .c('error').attrs({by:'lounge@localhost', type:'auth'})
- .c('forbidden').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
- var view = _converse.chatboxviews.get('problematic@muc.localhost');
- spyOn(view, 'showErrorMessage').and.callThrough();
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
- .toBe('You have been banned from this groupchat.');
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("will render a nickname form if a nickname conflict happens and muc_nickname_from_jid=false",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
- .then(function () {
- var presence = $pres().attrs({
- from:'problematic@muc.localhost/dummy',
- id:'n13mt3l',
- to:'dummy@localhost/pda',
- type:'error'})
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
- .c('error').attrs({by:'lounge@localhost', type:'cancel'})
- .c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
- var view = _converse.chatboxviews.get('problematic@muc.localhost');
- spyOn(view, 'showErrorMessage').and.callThrough();
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($(view.el).find('.chatroom-body form.chatroom-form label:first').text()).toBe('Please choose your nickname');
- var $input = $(view.el).find('.chatroom-body form.chatroom-form input:first');
- $input.val('nicky');
- view.el.querySelector('input[type=submit]').click();
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("will automatically choose a new nickname if a nickname conflict happens and muc_nickname_from_jid=true",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
- .then(function () {
- /* <presence
- * from='coven@chat.shakespeare.lit/thirdwitch'
- * id='n13mt3l'
- * to='hag66@shakespeare.lit/pda'
- * type='error'>
- * <x xmlns='http://jabber.org/protocol/muc'/>
- * <error by='coven@chat.shakespeare.lit' type='cancel'>
- * <conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
- * </error>
- * </presence>
- */
- _converse.muc_nickname_from_jid = true;
- var attrs = {
- from:'problematic@muc.localhost/dummy',
- to:'dummy@localhost/pda',
- type:'error'
- };
- attrs.id = new Date().getTime();
- var presence = $pres().attrs(attrs)
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
- .c('error').attrs({by:'problematic@muc.localhost', type:'cancel'})
- .c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
- var view = _converse.chatboxviews.get('problematic@muc.localhost');
- spyOn(view, 'showErrorMessage').and.callThrough();
- spyOn(view, 'join').and.callThrough();
- // Simulate repeatedly that there's already someone in the groupchat
- // with that nickname
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.join).toHaveBeenCalledWith('dummy-2');
- attrs.from = 'problematic@muc.localhost/dummy-2';
- attrs.id = new Date().getTime();
- presence = $pres().attrs(attrs)
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
- .c('error').attrs({by:'problematic@muc.localhost', type:'cancel'})
- .c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.join).toHaveBeenCalledWith('dummy-3');
- attrs.from = 'problematic@muc.localhost/dummy-3';
- attrs.id = new Date().getTime();
- presence = $pres().attrs(attrs)
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
- .c('error').attrs({by:'problematic@muc.localhost', type:'cancel'})
- .c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.join).toHaveBeenCalledWith('dummy-4');
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("will show an error message if the user is not allowed to have created the groupchat",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
- .then(function () {
- var presence = $pres().attrs({
- from:'problematic@muc.localhost/dummy',
- id:'n13mt3l',
- to:'dummy@localhost/pda',
- type:'error'})
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
- .c('error').attrs({by:'lounge@localhost', type:'cancel'})
- .c('not-allowed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
- var view = _converse.chatboxviews.get('problematic@muc.localhost');
- spyOn(view, 'showErrorMessage').and.callThrough();
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
- .toBe('You are not allowed to create new groupchats.');
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("will show an error message if the user's nickname doesn't conform to room policy",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
- .then(function () {
- var presence = $pres().attrs({
- from:'problematic@muc.localhost/dummy',
- id:'n13mt3l',
- to:'dummy@localhost/pda',
- type:'error'})
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
- .c('error').attrs({by:'lounge@localhost', type:'cancel'})
- .c('not-acceptable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
- var view = _converse.chatboxviews.get('problematic@muc.localhost');
- spyOn(view, 'showErrorMessage').and.callThrough();
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
- .toBe("Your nickname doesn't conform to this groupchat's policies.");
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("will show an error message if the groupchat doesn't yet exist",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
- .then(function () {
- var presence = $pres().attrs({
- from:'problematic@muc.localhost/dummy',
- id:'n13mt3l',
- to:'dummy@localhost/pda',
- type:'error'})
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
- .c('error').attrs({by:'lounge@localhost', type:'cancel'})
- .c('item-not-found').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
- var view = _converse.chatboxviews.get('problematic@muc.localhost');
- spyOn(view, 'showErrorMessage').and.callThrough();
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
- .toBe("This groupchat does not (yet) exist.");
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("will show an error message if the groupchat has reached its maximum number of participants",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoomViaModal(_converse, 'problematic@muc.localhost', 'dummy')
- .then(function () {
- var presence = $pres().attrs({
- from:'problematic@muc.localhost/dummy',
- id:'n13mt3l',
- to:'dummy@localhost/pda',
- type:'error'})
- .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
- .c('error').attrs({by:'lounge@localhost', type:'cancel'})
- .c('service-unavailable').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
- var view = _converse.chatboxviews.get('problematic@muc.localhost');
- spyOn(view, 'showErrorMessage').and.callThrough();
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(view.el.querySelector('.chatroom-body .disconnect-container .disconnect-msg:last-child').textContent)
- .toBe("This groupchat has reached its maximum number of participants.");
- done();
- }).catch(_.partial(console.error, _));
- }));
- });
- describe("Someone being invited to a groupchat", function () {
- it("will first be added to the member list if the groupchat is members only",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- var sent_IQs = [], IQ_ids = [];
- let invitee_jid, sent_stanza, sent_id, view;
- const sendIQ = _converse.connection.sendIQ;
- const IQ_stanzas = _converse.connection.IQ_stanzas;
- const room_jid = 'coven@chat.shakespeare.lit';
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
- sent_IQs.push(iq);
- IQ_ids.push(sendIQ.bind(this)(iq, callback, errback));
- });
- _converse.api.rooms.open(room_jid, {'nick': 'dummy'})
- .then(() => {
- return test_utils.waitUntil(() => _.get(_.filter(
- IQ_stanzas,
- iq => iq.nodeTree.querySelector(
- `iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
- )).pop(), 'nodeTree'));
- }).then(stanza => {
- // Check that the groupchat queried for the feautures.
- expect(stanza.outerHTML).toBe(
- `<iq from="dummy@localhost/resource" to="${room_jid}" type="get" xmlns="jabber:client" id="${stanza.getAttribute("id")}">`+
- `<query xmlns="http://jabber.org/protocol/disco#info"/>`+
- `</iq>`);
- view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- // State that the chat is members-only via the features IQ
- var features_stanza = $iq({
- from: 'coven@chat.shakespeare.lit',
- 'id': IQ_ids.pop(),
- 'to': 'dummy@localhost/desktop',
- 'type': 'result'
- })
- .c('query', { 'xmlns': 'http://jabber.org/protocol/disco#info'})
- .c('identity', {
- 'category': 'conference',
- 'name': 'A Dark Cave',
- 'type': 'text'
- }).up()
- .c('feature', {'var': 'http://jabber.org/protocol/muc'}).up()
- .c('feature', {'var': 'muc_hidden'}).up()
- .c('feature', {'var': 'muc_temporary'}).up()
- .c('feature', {'var': 'muc_membersonly'}).up();
- _converse.connection._dataRecv(test_utils.createRequest(features_stanza));
- return test_utils.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.CONNECTING));
- }).then(() => {
- expect(view.model.get('membersonly')).toBeTruthy();
- test_utils.createContacts(_converse, 'current');
- spyOn(_converse.connection, 'send').and.callFake(function (stanza) {
- if (stanza.nodeTree && stanza.nodeTree.nodeName === 'message') {
- sent_id = stanza.nodeTree.getAttribute('id');
- sent_stanza = stanza;
- }
- });
- var name = mock.cur_names[0];
- invitee_jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
- var reason = "Please join this groupchat";
- view.model.directInvite(invitee_jid, reason);
- // Check in reverse order that we requested all three lists
- // (member, owner and admin).
- var admin_iq_id = IQ_ids.pop();
- var owner_iq_id = IQ_ids.pop();
- var member_iq_id = IQ_ids.pop();
- expect(sent_IQs.pop().toLocaleString()).toBe(
- "<iq to='coven@chat.shakespeare.lit' type='get' xmlns='jabber:client' id='"+admin_iq_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#admin'>"+
- "<item affiliation='admin'/>"+
- "</query>"+
- "</iq>");
- expect(sent_IQs.pop().toLocaleString()).toBe(
- "<iq to='coven@chat.shakespeare.lit' type='get' xmlns='jabber:client' id='"+owner_iq_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#admin'>"+
- "<item affiliation='owner'/>"+
- "</query>"+
- "</iq>");
- expect(sent_IQs.pop().toLocaleString()).toBe(
- "<iq to='coven@chat.shakespeare.lit' type='get' xmlns='jabber:client' id='"+member_iq_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#admin'>"+
- "<item affiliation='member'/>"+
- "</query>"+
- "</iq>");
- /* Now the service sends the member list to the user
- *
- * <iq from='coven@chat.shakespeare.lit'
- * id='member3'
- * to='crone1@shakespeare.lit/desktop'
- * type='result'>
- * <query xmlns='http://jabber.org/protocol/muc#admin'>
- * <item affiliation='member'
- * jid='hag66@shakespeare.lit'
- * nick='thirdwitch'
- * role='participant'/>
- * </query>
- * </iq>
- */
- var member_list_stanza = $iq({
- 'from': 'coven@chat.shakespeare.lit',
- 'id': member_iq_id,
- 'to': 'dummy@localhost/resource',
- 'type': 'result'
- }).c('query', {'xmlns': Strophe.NS.MUC_ADMIN})
- .c('item', {
- 'affiliation': 'member',
- 'jid': 'hag66@shakespeare.lit',
- 'nick': 'thirdwitch',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(member_list_stanza));
- var admin_list_stanza = $iq({
- 'from': 'coven@chat.shakespeare.lit',
- 'id': admin_iq_id,
- 'to': 'dummy@localhost/resource',
- 'type': 'result'
- }).c('query', {'xmlns': Strophe.NS.MUC_ADMIN})
- .c('item', {
- 'affiliation': 'admin',
- 'jid': 'wiccarocks@shakespeare.lit',
- 'nick': 'secondwitch'
- });
- _converse.connection._dataRecv(test_utils.createRequest(admin_list_stanza));
- var owner_list_stanza = $iq({
- 'from': 'coven@chat.shakespeare.lit',
- 'id': owner_iq_id,
- 'to': 'dummy@localhost/resource',
- 'type': 'result'
- }).c('query', {'xmlns': Strophe.NS.MUC_ADMIN})
- .c('item', {
- 'affiliation': 'owner',
- 'jid': 'crone1@shakespeare.lit',
- });
- _converse.connection._dataRecv(test_utils.createRequest(owner_list_stanza));
- return test_utils.waitUntil(() => IQ_ids.length, 300);
- }).then(() => {
- return test_utils.waitUntil(() => _.get(_.filter(
- IQ_stanzas,
- iq => iq.nodeTree.querySelector(
- `iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/muc#admin"]`
- )).pop(), 'nodeTree'));
- }).then(stanza => {
- expect(stanza.outerHTML,
- "<iq to='coven@chat.shakespeare.lit' type='set' xmlns='jabber:client' id='"+IQ_ids.pop()+"'>"+
- "<query xmlns='http://jabber.org/protocol/muc#admin'>"+
- "<item affiliation='member' jid='"+invitee_jid+"'>"+
- "<reason>Please join this groupchat</reason>"+
- "</item>"+
- "</query>"+
- "</iq>");
- // Finally check that the user gets invited.
- expect(sent_stanza.toLocaleString()).toBe( // Strophe adds the xmlns attr (although not in spec)
- "<message from='dummy@localhost/resource' to='"+invitee_jid+"' id='"+sent_id+"' xmlns='jabber:client'>"+
- "<x xmlns='jabber:x:conference' jid='coven@chat.shakespeare.lit' reason='Please join this groupchat'/>"+
- "</message>"
- );
- done();
- }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
- }));
- });
- describe("The affiliations delta", function () {
- it("can be computed in various ways",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'dummy');
- var roomview = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- var exclude_existing = false;
- var remove_absentees = false;
- var new_list = [];
- var old_list = [];
- var delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(0);
- new_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'member'}];
- old_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'member'}];
- delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(0);
- // When remove_absentees is false, then affiliations in the old
- // list which are not in the new one won't be removed.
- old_list = [{'jid': 'oldhag666@shakespeare.lit', 'affiliation': 'owner'},
- {'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'member'}];
- delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(0);
- // With exclude_existing set to false, any changed affiliations
- // will be included in the delta (i.e. existing affiliations
- // are included in the comparison).
- old_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'owner'}];
- delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(1);
- expect(delta[0].jid).toBe('wiccarocks@shakespeare.lit');
- expect(delta[0].affiliation).toBe('member');
- // To also remove affiliations from the old list which are not
- // in the new list, we set remove_absentees to true
- remove_absentees = true;
- old_list = [{'jid': 'oldhag666@shakespeare.lit', 'affiliation': 'owner'},
- {'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'member'}];
- delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(1);
- expect(delta[0].jid).toBe('oldhag666@shakespeare.lit');
- expect(delta[0].affiliation).toBe('none');
- delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, [], old_list);
- expect(delta.length).toBe(2);
- expect(delta[0].jid).toBe('oldhag666@shakespeare.lit');
- expect(delta[0].affiliation).toBe('none');
- expect(delta[1].jid).toBe('wiccarocks@shakespeare.lit');
- expect(delta[1].affiliation).toBe('none');
- // To only add a user if they don't already have an
- // affiliation, we set 'exclude_existing' to true
- exclude_existing = true;
- old_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'owner'}];
- delta = u.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list);
- expect(delta.length).toBe(0);
- done();
- }));
- });
- describe("The \"Groupchats\" section", function () {
- it("contains a link to a modal through which a new chatroom can be created",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- test_utils.openControlBox();
- _converse.emit('rosterContactsFetched');
- var roomspanel = _converse.chatboxviews.get('controlbox').roomspanel;
- roomspanel.el.querySelector('.show-add-muc-modal').click();
- test_utils.closeControlBox(_converse);
- const modal = roomspanel.add_room_modal;
- test_utils.waitUntil(() => u.isVisible(modal.el), 1000)
- .then(function () {
- spyOn(_converse.ChatRoom.prototype, 'getRoomFeatures').and.callFake(function () {
- var deferred = new $.Deferred();
- deferred.resolve();
- return deferred.promise();
- });
- roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
- modal.el.querySelector('input[name="chatroom"]').value = 'lounce@muc.localhost';
- modal.el.querySelector('form input[type="submit"]').click();
- return test_utils.waitUntil(() => _converse.chatboxes.length);
- }).then(() => {
- expect($('.chatroom:visible').length).toBe(1); // There should now be an open chatroom
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("contains a link to a modal which can list groupchats publically available on the server",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- var sendIQ = _converse.connection.sendIQ;
- var sent_stanza, IQ_id;
- spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
- sent_stanza = iq;
- IQ_id = sendIQ.bind(this)(iq, callback, errback);
- });
- test_utils.openControlBox();
- var roomspanel = _converse.chatboxviews.get('controlbox').roomspanel;
- roomspanel.el.querySelector('.show-list-muc-modal').click();
- test_utils.closeControlBox(_converse);
- const modal = roomspanel.list_rooms_modal;
- test_utils.waitUntil(() => u.isVisible(modal.el), 1000)
- .then(() => {
- spyOn(_converse.ChatRoom.prototype, 'getRoomFeatures').and.callFake(function () {
- var deferred = new $.Deferred();
- deferred.resolve();
- return deferred.promise();
- });
- roomspanel.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
- // See: http://xmpp.org/extensions/xep-0045.html#disco-rooms
- expect(modal.el.querySelectorAll('.available-chatrooms li').length).toBe(0);
- const input = modal.el.querySelector('input[name="server"]').value = 'chat.shakespear.lit';
- modal.el.querySelector('input[type="submit"]').click();
- return test_utils.waitUntil(() => _converse.chatboxes.length);
- }).then(() => {
- expect(sent_stanza.toLocaleString()).toBe(
- "<iq to='chat.shakespear.lit' from='dummy@localhost/resource' type='get' xmlns='jabber:client' id='"+IQ_id+"'>"+
- "<query xmlns='http://jabber.org/protocol/disco#items'/>"+
- "</iq>"
- );
- var iq = $iq({
- from:'muc.localhost',
- to:'dummy@localhost/pda',
- id: IQ_id,
- type:'result'
- }).c('query')
- .c('item', { jid:'heath@chat.shakespeare.lit', name:'A Lonely Heath'}).up()
- .c('item', { jid:'coven@chat.shakespeare.lit', name:'A Dark Cave'}).up()
- .c('item', { jid:'forres@chat.shakespeare.lit', name:'The Palace'}).up()
- .c('item', { jid:'inverness@chat.shakespeare.lit', name:'Macbeth's Castle'}).nodeTree;
- _converse.connection._dataRecv(test_utils.createRequest(iq));
- expect(modal.el.querySelectorAll('.available-chatrooms li').length).toBe(5);
- const rooms = modal.el.querySelectorAll('.available-chatrooms li');
- expect(rooms[0].textContent.trim()).toBe("Groupchats found:");
- expect(rooms[1].textContent.trim()).toBe("A Lonely Heath");
- expect(rooms[2].textContent.trim()).toBe("A Dark Cave");
- expect(rooms[3].textContent.trim()).toBe("The Palace");
- expect(rooms[4].textContent.trim()).toBe("Macbeth's Castle");
- rooms[4].querySelector('.open-room').click();
- return test_utils.waitUntil(() => _converse.chatboxes.length > 1);
- }).then(() => {
- expect($('.chatroom:visible').length).toBe(1); // There should now be an open chatroom
- var view = _converse.chatboxviews.get('inverness@chat.shakespeare.lit');
- expect(view.el.querySelector('.chat-head-chatroom').textContent.trim()).toBe("Macbeth's Castle");
- done();
- }).catch(_.partial(console.error, _));
- }));
- it("shows the number of unread mentions received",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {'allow_bookmarks': false},
- function (done, _converse) {
- // XXX: we set `allow_bookmarks` to false, so that the groupchats
- // list gets rendered. Otherwise we would have to mock
- // the bookmark stanza exchange.
- test_utils.openControlBox();
- var roomspanel = _converse.chatboxviews.get('controlbox').roomspanel;
- expect(roomspanel.el.querySelectorAll('.available-room').length).toBe(0);
- let view, nick;
- const room_jid = 'kitchen@conference.shakespeare.lit';
- const message = 'fires: Your attention is required';
- test_utils.openAndEnterChatRoom(_converse, 'kitchen', 'conference.shakespeare.lit', 'fires')
- .then(() => {
- expect(roomspanel.el.querySelectorAll('.available-room').length).toBe(1);
- expect(roomspanel.el.querySelectorAll('.msgs-indicator').length).toBe(0);
- view = _converse.chatboxviews.get(room_jid);
- view.model.set({'minimized': true});
- var contact_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
- nick = mock.chatroom_names[0];
- view.model.onMessage($msg({
- from: room_jid+'/'+nick,
- id: (new Date()).getTime(),
- to: 'dummy@localhost',
- type: 'groupchat'
- }).c('body').t(message).tree());
- return test_utils.waitUntil(() => view.model.messages.length);
- }).then(() => {
- expect(roomspanel.el.querySelectorAll('.available-room').length).toBe(1);
- expect(roomspanel.el.querySelectorAll('.msgs-indicator').length).toBe(1);
- expect(roomspanel.el.querySelector('.msgs-indicator').textContent).toBe('1');
- view.model.onMessage($msg({
- 'from': room_jid+'/'+nick,
- 'id': (new Date()).getTime(),
- 'to': 'dummy@localhost',
- 'type': 'groupchat'
- }).c('body').t(message).tree());
- return test_utils.waitUntil(() => view.model.messages.length > 1);
- }).then(() => {
- expect(roomspanel.el.querySelectorAll('.available-room').length).toBe(1);
- expect(roomspanel.el.querySelectorAll('.msgs-indicator').length).toBe(1);
- expect(roomspanel.el.querySelector('.msgs-indicator').textContent).toBe('2');
- view.model.set({'minimized': false});
- expect(roomspanel.el.querySelectorAll('.available-room').length).toBe(1);
- expect(roomspanel.el.querySelectorAll('.msgs-indicator').length).toBe(0);
- done();
- }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
- }));
- describe("A Chat Status Notification", function () {
- describe("A composing notification", function () {
- it("will be shown if received",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched'], {},
- function (done, _converse) {
- let view;
- const room_jid = 'coven@chat.shakespeare.lit';
- test_utils.openAndEnterChatRoom(
- _converse, 'coven', 'chat.shakespeare.lit', 'some1').then(function () {
- view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- const chat_content = view.el.querySelector('.chat-content');
- expect($(chat_content).find('div.chat-info:first').html()).toBe("some1 has entered the groupchat");
- let presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/newguy'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@localhost/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(chat_content.querySelectorAll('div.chat-info').length).toBe(2);
- expect($(chat_content).find('div.chat-info:last').html()).toBe("newguy has entered the groupchat");
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/nomorenicks'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'nomorenicks@localhost/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect(chat_content.querySelectorAll('div.chat-info').length).toBe(3);
- expect($(chat_content).find('div.chat-info:last').html()).toBe("nomorenicks has entered the groupchat");
- // See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
- // <composing> state
- var msg = $msg({
- from: room_jid+'/newguy',
- id: (new Date()).getTime(),
- to: 'dummy@localhost',
- type: 'groupchat'
- }).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
- view.model.onMessage(msg);
- return test_utils.waitUntil(() => view.el.querySelectorAll('.chat-state-notification').length);
- }).then(() => {
- // Check that the notification appears inside the chatbox in the DOM
- var events = view.el.querySelectorAll('.chat-event');
- expect(events.length).toBe(3);
- expect(events[0].textContent).toEqual('some1 has entered the groupchat');
- expect(events[1].textContent).toEqual('newguy has entered the groupchat');
- expect(events[2].textContent).toEqual('nomorenicks has entered the groupchat');
- var notifications = view.el.querySelectorAll('.chat-state-notification');
- expect(notifications.length).toBe(1);
- expect(notifications[0].textContent).toEqual('newguy is typing');
- const timeout_functions = [];
- spyOn(window, 'setTimeout').and.callFake(function (func, delay) {
- timeout_functions.push(func);
- });
- // Check that it doesn't appear twice
- let msg = $msg({
- from: room_jid+'/newguy',
- id: (new Date()).getTime(),
- to: 'dummy@localhost',
- type: 'groupchat'
- }).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
- view.model.onMessage(msg);
- events = view.el.querySelectorAll('.chat-event');
- expect(events.length).toBe(3);
- expect(events[0].textContent).toEqual('some1 has entered the groupchat');
- expect(events[1].textContent).toEqual('newguy has entered the groupchat');
- expect(events[2].textContent).toEqual('nomorenicks has entered the groupchat');
- notifications = view.el.querySelectorAll('.chat-state-notification');
- expect(notifications.length).toBe(1);
- expect(notifications[0].textContent).toEqual('newguy is typing');
- expect(timeout_functions.length).toBe(1);
- // <composing> state for a different occupant
- msg = $msg({
- from: room_jid+'/nomorenicks',
- id: (new Date()).getTime(),
- to: 'dummy@localhost',
- type: 'groupchat'
- }).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
- view.model.onMessage(msg);
- events = view.el.querySelectorAll('.chat-event');
- expect(events.length).toBe(3);
- expect(events[0].textContent).toEqual('some1 has entered the groupchat');
- expect(events[1].textContent).toEqual('newguy has entered the groupchat');
- expect(events[2].textContent).toEqual('nomorenicks has entered the groupchat');
- notifications = view.el.querySelectorAll('.chat-state-notification');
- expect(notifications.length).toBe(2);
- expect(notifications[0].textContent).toEqual('newguy is typing');
- expect(notifications[1].textContent).toEqual('nomorenicks is typing');
- expect(timeout_functions.length).toBe(2);
- // Check that new messages appear under the chat state
- // notifications
- msg = $msg({
- from: 'lounge@localhost/some1',
- id: (new Date()).getTime(),
- to: 'dummy@localhost',
- type: 'groupchat'
- }).c('body').t('hello world').tree();
- view.model.onMessage(msg);
- var messages = view.el.querySelectorAll('.message');
- expect(messages.length).toBe(7);
- expect(view.el.querySelectorAll('.chat-msg').length).toBe(1);
- expect(view.el.querySelector('.chat-msg .chat-msg__text').textContent).toBe('hello world');
- // Test that the composing notifications get removed
- // via timeout.
- timeout_functions[0]();
- events = view.el.querySelectorAll('.chat-event');
- expect(events.length).toBe(3);
- expect(events[0].textContent).toEqual('some1 has entered the groupchat');
- expect(events[1].textContent).toEqual('newguy has entered the groupchat');
- expect(events[2].textContent).toEqual('nomorenicks has entered the groupchat');
- notifications = view.el.querySelectorAll('.chat-state-notification');
- expect(notifications.length).toBe(1);
- expect(notifications[0].textContent).toEqual('nomorenicks is typing');
- timeout_functions[1]();
- events = view.el.querySelectorAll('.chat-event');
- expect(events.length).toBe(3);
- expect(events[0].textContent).toEqual('some1 has entered the groupchat');
- expect(events[1].textContent).toEqual('newguy has entered the groupchat');
- expect(events[2].textContent).toEqual('nomorenicks has entered the groupchat');
- notifications = view.el.querySelectorAll('.chat-state-notification');
- expect(notifications.length).toBe(0);
- done();
- }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
- }));
- });
- describe("A paused notification", function () {
- it("will be shown if received",
- mock.initConverseWithPromises(
- null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
- function (done, _converse) {
- test_utils.openChatRoom(_converse, "coven", 'chat.shakespeare.lit', 'some1')
- .then(() => {
- var room_jid = 'coven@chat.shakespeare.lit';
- var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit');
- var $chat_content = $(view.el).find('.chat-content');
- /* <presence to="dummy@localhost/_converse.js-29092160"
- * from="coven@chat.shakespeare.lit/some1">
- * <x xmlns="http://jabber.org/protocol/muc#user">
- * <item affiliation="owner" jid="dummy@localhost/_converse.js-29092160" role="moderator"/>
- * <status code="110"/>
- * </x>
- * </presence></body>
- */
- var presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/some1'
- }).c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'owner',
- 'jid': 'dummy@localhost/_converse.js-29092160',
- 'role': 'moderator'
- }).up()
- .c('status', {code: '110'});
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content.find('div.chat-info:first').html()).toBe("some1 has entered the groupchat");
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/newguy'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'newguy@localhost/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(2);
- expect($chat_content.find('div.chat-info:last').html()).toBe("newguy has entered the groupchat");
- presence = $pres({
- to: 'dummy@localhost/_converse.js-29092160',
- from: 'coven@chat.shakespeare.lit/nomorenicks'
- })
- .c('x', {xmlns: Strophe.NS.MUC_USER})
- .c('item', {
- 'affiliation': 'none',
- 'jid': 'nomorenicks@localhost/_converse.js-290929789',
- 'role': 'participant'
- });
- _converse.connection._dataRecv(test_utils.createRequest(presence));
- expect($chat_content[0].querySelectorAll('div.chat-info').length).toBe(3);
- expect($chat_content.find('div.chat-info:last').html()).toBe("nomorenicks has entered the groupchat");
- // See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
- // <composing> state
- var msg = $msg({
- from: room_jid+'/newguy',
- id: (new Date()).getTime(),
- to: 'dummy@localhost',
- type: 'groupchat'
- }).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
- view.model.onMessage(msg);
- // Check that the notification appears inside the chatbox in the DOM
- var events = view.el.querySelectorAll('.chat-event');
- expect(events.length).toBe(3);
- expect(events[0].textContent).toEqual('some1 has entered the groupchat');
- expect(events[1].textContent).toEqual('newguy has entered the groupchat');
- expect(events[2].textContent).toEqual('nomorenicks has entered the groupchat');
- var notifications = view.el.querySelectorAll('.chat-state-notification');
- expect(notifications.length).toBe(1);
- expect(notifications[0].textContent).toEqual('newguy is typing');
- // Check that it doesn't appear twice
- msg = $msg({
- from: room_jid+'/newguy',
- id: (new Date()).getTime(),
- to: 'dummy@localhost',
- type: 'groupchat'
- }).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
- view.model.onMessage(msg);
- events = view.el.querySelectorAll('.chat-event');
- expect(events.length).toBe(3);
- expect(events[0].textContent).toEqual('some1 has entered the groupchat');
- expect(events[1].textContent).toEqual('newguy has entered the groupchat');
- expect(events[2].textContent).toEqual('nomorenicks has entered the groupchat');
- notifications = view.el.querySelectorAll('.chat-state-notification');
- expect(notifications.length).toBe(1);
- expect(notifications[0].textContent).toEqual('newguy is typing');
- // <composing> state for a different occupant
- msg = $msg({
- from: room_jid+'/nomorenicks',
- id: (new Date()).getTime(),
- to: 'dummy@localhost',
- type: 'groupchat'
- }).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
- view.model.onMessage(msg);
- events = view.el.querySelectorAll('.chat-event');
- expect(events.length).toBe(3);
- expect(events[0].textContent).toEqual('some1 has entered the groupchat');
- expect(events[1].textContent).toEqual('newguy has entered the groupchat');
- expect(events[2].textContent).toEqual('nomorenicks has entered the groupchat');
- notifications = view.el.querySelectorAll('.chat-state-notification');
- expect(notifications.length).toBe(2);
- expect(notifications[0].textContent).toEqual('newguy is typing');
- expect(notifications[1].textContent).toEqual('nomorenicks is typing');
- // <paused> state from occupant who typed first
- msg = $msg({
- from: room_jid+'/newguy',
- id: (new Date()).getTime(),
- to: 'dummy@localhost',
- type: 'groupchat'
- }).c('body').c('paused', {'xmlns': Strophe.NS.CHATSTATES}).tree();
- view.model.onMessage(msg);
- events = view.el.querySelectorAll('.chat-event');
- expect(events.length).toBe(3);
- expect(events[0].textContent).toEqual('some1 has entered the groupchat');
- expect(events[1].textContent).toEqual('newguy has entered the groupchat');
- expect(events[2].textContent).toEqual('nomorenicks has entered the groupchat');
- notifications = view.el.querySelectorAll('.chat-state-notification');
- expect(notifications.length).toBe(2);
- expect(notifications[0].textContent).toEqual('nomorenicks is typing');
- expect(notifications[1].textContent).toEqual('newguy has stopped typing');
- done();
- }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
- }));
- });
- });
- });
- });
- }));
|