Sfoglia il codice sorgente

Move tests to headless plugin

JC Brand 4 anni fa
parent
commit
a4b90e3ab2
3 ha cambiato i file con 68 aggiunte e 70 eliminazioni
  1. 1 0
      karma.conf.js
  2. 0 70
      spec/converse.js
  3. 67 0
      src/headless/plugins/chat/tests/api.js

+ 1 - 0
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' },

+ 0 - 70
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) => {

+ 67 - 0
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();
+    }));
+});