From a4b90e3ab214647c44d048f9a54ee609e40206b5 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Wed, 21 Apr 2021 12:25:28 +0200 Subject: [PATCH] Move tests to headless plugin --- karma.conf.js | 1 + spec/converse.js | 70 -------------------------- src/headless/plugins/chat/tests/api.js | 67 ++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 70 deletions(-) create mode 100644 src/headless/plugins/chat/tests/api.js diff --git a/karma.conf.js b/karma.conf.js index 226ea90a9..fbd9b31c5 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -41,6 +41,7 @@ module.exports = function(config) { { pattern: "spec/user-details-modal.js", type: 'module' }, { pattern: "spec/utils.js", type: 'module' }, { pattern: "spec/xmppstatus.js", type: 'module' }, + { pattern: "src/headless/plugins/chat/tests/api.js", type: 'module' }, { pattern: "src/headless/plugins/disco/tests/disco.js", type: 'module' }, { pattern: "src/headless/plugins/muc/tests/affiliations.js", type: 'module' }, { pattern: "src/headless/plugins/ping/tests/ping.js", type: 'module' }, diff --git a/spec/converse.js b/spec/converse.js index d7aa36c16..d84f6bc0e 100644 --- a/spec/converse.js +++ b/spec/converse.js @@ -265,76 +265,6 @@ describe("Converse", function() { })); }); - describe("The \"chats\" API", function() { - - it("has a method 'get' which returns the promise that resolves to a chat model", mock.initConverse( - ['rosterInitialized', 'chatBoxesInitialized'], {}, - async (done, _converse) => { - - const u = converse.env.utils; - - await mock.openControlBox(_converse); - await mock.waitForRoster(_converse, 'current', 2); - - // Test on chat that doesn't exist. - let chat = await _converse.api.chats.get('non-existing@jabber.org'); - expect(chat).toBeFalsy(); - const jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit'; - const jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit'; - - // Test on chat that's not open - chat = await _converse.api.chats.get(jid); - expect(chat === null).toBeTruthy(); - expect(_converse.chatboxes.length).toBe(1); - - // Test for one JID - chat = await _converse.api.chats.open(jid); - expect(chat instanceof Object).toBeTruthy(); - expect(chat.get('box_id')).toBe(`box-${jid}`); - - const view = _converse.chatboxviews.get(jid); - await u.waitUntil(() => u.isVisible(view)); - // Test for multiple JIDs - mock.openChatBoxFor(_converse, jid2); - await u.waitUntil(() => _converse.chatboxes.length == 3); - const list = await _converse.api.chats.get([jid, jid2]); - expect(Array.isArray(list)).toBeTruthy(); - expect(list[0].get('box_id')).toBe(`box-${jid}`); - expect(list[1].get('box_id')).toBe(`box-${jid2}`); - done(); - })); - - it("has a method 'open' which opens and returns a promise that resolves to a chat model", mock.initConverse( - ['chatBoxesInitialized'], {}, async (done, _converse) => { - - const u = converse.env.utils; - await mock.openControlBox(_converse); - await mock.waitForRoster(_converse, 'current', 2); - - const jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit'; - const jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit'; - // Test on chat that doesn't exist. - let chat = await _converse.api.chats.get('non-existing@jabber.org'); - expect(chat).toBeFalsy(); - - chat = await _converse.api.chats.open(jid); - expect(chat instanceof Object).toBeTruthy(); - expect(chat.get('box_id')).toBe(`box-${jid}`); - expect( - Object.keys(chat), - ['close', 'endOTR', 'focus', 'get', 'initiateOTR', 'is_chatroom', 'maximize', 'minimize', 'open', 'set'] - ); - const view = _converse.chatboxviews.get(jid); - await u.waitUntil(() => u.isVisible(view)); - // Test for multiple JIDs - const list = await _converse.api.chats.open([jid, jid2]); - expect(Array.isArray(list)).toBeTruthy(); - expect(list[0].get('box_id')).toBe(`box-${jid}`); - expect(list[1].get('box_id')).toBe(`box-${jid2}`); - done(); - })); - }); - describe("The \"settings\" API", function() { it("has methods 'get' and 'set' to set configuration settings", mock.initConverse(null, {'play_sounds': true}, (done, _converse) => { diff --git a/src/headless/plugins/chat/tests/api.js b/src/headless/plugins/chat/tests/api.js new file mode 100644 index 000000000..5d2331031 --- /dev/null +++ b/src/headless/plugins/chat/tests/api.js @@ -0,0 +1,67 @@ +/* global mock, converse */ + +describe("The \"chats\" API", function() { + + it("has a method 'get' which returns the promise that resolves to a chat model", mock.initConverse( + ['rosterInitialized', 'chatBoxesInitialized'], {}, + async (done, _converse) => { + + const u = converse.env.utils; + + await mock.openControlBox(_converse); + await mock.waitForRoster(_converse, 'current', 2); + + // Test on chat that doesn't exist. + let chat = await _converse.api.chats.get('non-existing@jabber.org'); + expect(chat).toBeFalsy(); + const jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit'; + const jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit'; + + // Test on chat that's not open + chat = await _converse.api.chats.get(jid); + expect(chat === null).toBeTruthy(); + expect(_converse.chatboxes.length).toBe(1); + + // Test for one JID + chat = await _converse.api.chats.open(jid); + expect(chat instanceof Object).toBeTruthy(); + expect(chat.get('box_id')).toBe(`box-${jid}`); + + // Test for multiple JIDs + mock.openChatBoxFor(_converse, jid2); + await u.waitUntil(() => _converse.chatboxes.length == 3); + const list = await _converse.api.chats.get([jid, jid2]); + expect(Array.isArray(list)).toBeTruthy(); + expect(list[0].get('box_id')).toBe(`box-${jid}`); + expect(list[1].get('box_id')).toBe(`box-${jid2}`); + done(); + })); + + it("has a method 'open' which opens and returns a promise that resolves to a chat model", mock.initConverse( + ['chatBoxesInitialized'], {}, async (done, _converse) => { + + await mock.openControlBox(_converse); + await mock.waitForRoster(_converse, 'current', 2); + + const jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit'; + const jid2 = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit'; + // Test on chat that doesn't exist. + let chat = await _converse.api.chats.get('non-existing@jabber.org'); + expect(chat).toBeFalsy(); + + chat = await _converse.api.chats.open(jid); + expect(chat instanceof Object).toBeTruthy(); + expect(chat.get('box_id')).toBe(`box-${jid}`); + expect( + Object.keys(chat), + ['close', 'endOTR', 'focus', 'get', 'initiateOTR', 'is_chatroom', 'maximize', 'minimize', 'open', 'set'] + ); + + // Test for multiple JIDs + const list = await _converse.api.chats.open([jid, jid2]); + expect(Array.isArray(list)).toBeTruthy(); + expect(list[0].get('box_id')).toBe(`box-${jid}`); + expect(list[1].get('box_id')).toBe(`box-${jid2}`); + done(); + })); +});