فهرست منبع

Use `trim()` to fix failing tests

JC Brand 1 ماه پیش
والد
کامیت
f8d4e618c6

+ 5 - 5
src/plugins/adhoc-views/tests/adhoc.js

@@ -66,7 +66,7 @@ describe("Ad-hoc commands", function () {
         </iq>`));
 
         const heading = await u.waitUntil(() => adhoc_form.querySelector('.list-group-item.active'));
-        expect(heading.textContent).toBe('Commands found:');
+        expect(heading.textContent.trim()).toBe('Commands found:');
 
         const items = adhoc_form.querySelectorAll('.list-group-item:not(.active)');
         expect(items.length).toBe(7);
@@ -181,7 +181,7 @@ describe("Ad-hoc commands", function () {
         </iq>`));
 
         const heading = await u.waitUntil(() => adhoc_form.querySelector('.list-group-item.active'));
-        expect(heading.textContent).toBe('Commands found:');
+        expect(heading.textContent.trim()).toBe('Commands found:');
 
         const items = adhoc_form.querySelectorAll('.list-group-item:not(.active)');
         expect(items.length).toBe(1);
@@ -222,7 +222,7 @@ describe("Ad-hoc commands", function () {
         const form = await u.waitUntil(() => adhoc_form.querySelector('form form'));
         const alert = form.querySelector('div.alert');
         expect(u.isVisible(alert)).toBe(true);
-        expect(alert.textContent).toBe(uptime_text);
+        expect(alert.textContent.trim()).toBe(uptime_text);
 
         const inputs = form.querySelectorAll('input[type="button"]');
         expect(inputs.length).toBe(0);
@@ -271,7 +271,7 @@ describe("Ad-hoc commands", function () {
         </iq>`));
 
         const heading = await u.waitUntil(() => adhoc_form.querySelector('.list-group-item.active'));
-        expect(heading.textContent).toBe('Commands found:');
+        expect(heading.textContent.trim()).toBe('Commands found:');
 
         const items = adhoc_form.querySelectorAll('.list-group-item:not(.active)');
         expect(items.length).toBe(1);
@@ -396,7 +396,7 @@ describe("Ad-hoc commands", function () {
         </iq>`));
 
         const heading = await u.waitUntil(() => adhoc_form.querySelector('.list-group-item.active'));
-        expect(heading.textContent).toBe('Commands found:');
+        expect(heading.textContent.trim()).toBe('Commands found:');
 
         const items = adhoc_form.querySelectorAll('.list-group-item:not(.active)');
         expect(items.length).toBe(1);

+ 3 - 3
src/plugins/chatview/tests/message-avatar.js

@@ -24,7 +24,7 @@ describe("A Chat Message", function () {
         await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length === 1);
 
         let el = view.querySelector('converse-chat-message converse-avatar .avatar-initials');
-        expect(el.textContent).toBe('RM');
+        expect(el.textContent.trim()).toBe('RM');
         expect(getComputedStyle(el).backgroundColor).toBe('rgb(198, 84, 0)');
 
         // Test messages from other user
@@ -43,14 +43,14 @@ describe("A Chat Message", function () {
         el = view.querySelector(
             `converse-chat-message div[data-from="${contact_jid}"] converse-avatar .avatar-initials`
         );
-        expect(el.textContent).toBe('M');
+        expect(el.textContent.trim()).toBe('M');
         expect(getComputedStyle(el).backgroundColor).toBe('rgb(195, 0, 249)');
 
         // Change contact nickname and see that it reflects
         const contact = await api.contacts.get(contact_jid);
         contact.set('nickname', 'Wizzard');
 
-        await u.waitUntil(() => el.textContent === 'W');
+        await u.waitUntil(() => el.textContent.trim() === 'W');
 
         // Change own nickname and see that it reflects
         const own_jid = _converse.session.get('jid');

+ 1 - 1
src/plugins/chatview/tests/messages.js

@@ -26,7 +26,7 @@ describe("A Chat Message", function () {
         await u.waitUntil(() => view.querySelectorAll('converse-chat-message').length === 2);
         await u.waitUntil(() => view.querySelector('converse-chat-message:last-child .chat-msg__text')?.textContent === 'This message will be new');
         const last_msg_el = view.querySelector('converse-chat-message:last-child');
-        expect(last_msg_el.firstElementChild?.textContent).toBe('New messages');
+        expect(last_msg_el.firstElementChild?.textContent.trim()).toBe('New messages');
     }));
 
 

+ 24 - 24
src/plugins/muc-views/tests/autocomplete.js

@@ -52,23 +52,23 @@ describe("The nickname autocomplete feature", function () {
 
         const first_child = view.querySelector('.suggestion-box__results li:first-child');
         const first_child_avatar = first_child.querySelector('converse-avatar');
-        expect(first_child_avatar.textContent).toBe('D');
-        expect(first_child.textContent).toBe('D dick');
+        expect(first_child_avatar.textContent.trim()).toBe('D');
+        expect(first_child.textContent.trim()).toBe('D dick');
 
         const second_child = view.querySelector('.suggestion-box__results li:nth-child(2)');
         const second_child_avatar = second_child.querySelector('converse-avatar');
-        expect(second_child_avatar.textContent).toBe('H');
-        expect(second_child.textContent).toBe('H harry');
+        expect(second_child_avatar.textContent.trim()).toBe('H');
+        expect(second_child.textContent.trim()).toBe('H harry');
 
         const third_child = view.querySelector('.suggestion-box__results li:nth-child(3)');
         const third_child_avatar = third_child.querySelector('converse-avatar');
-        expect(third_child_avatar.textContent).toBe('J');
-        expect(third_child.textContent).toBe('J jane');
+        expect(third_child_avatar.textContent.trim()).toBe('J');
+        expect(third_child.textContent.trim()).toBe('J jane');
 
         const fourth_child = view.querySelector('.suggestion-box__results li:nth-child(4)');
         const fourth_child_avatar = fourth_child.querySelector('converse-avatar');
-        expect(fourth_child_avatar.textContent).toBe('T');
-        expect(fourth_child.textContent).toBe('T tom');
+        expect(fourth_child_avatar.textContent.trim()).toBe('T');
+        expect(fourth_child.textContent.trim()).toBe('T tom');
     }));
 
     it("shows all autocompletion options when the user presses @ right after a new line",
@@ -120,23 +120,23 @@ describe("The nickname autocomplete feature", function () {
         await u.waitUntil(() => view.querySelectorAll('.suggestion-box__results li').length === 4);
         const first_child = view.querySelector('.suggestion-box__results li:first-child');
         const first_child_avatar = first_child.querySelector('converse-avatar');
-        expect(first_child_avatar.textContent).toBe('D');
-        expect(first_child.textContent).toBe('D dick');
+        expect(first_child_avatar.textContent.trim()).toBe('D');
+        expect(first_child.textContent.trim()).toBe('D dick');
 
         const second_child = view.querySelector('.suggestion-box__results li:nth-child(2)');
         const second_child_avatar = second_child.querySelector('converse-avatar');
-        expect(second_child_avatar.textContent).toBe('H');
-        expect(second_child.textContent).toBe('H harry');
+        expect(second_child_avatar.textContent.trim()).toBe('H');
+        expect(second_child.textContent.trim()).toBe('H harry');
 
         const third_child = view.querySelector('.suggestion-box__results li:nth-child(3)');
         const third_child_avatar = third_child.querySelector('converse-avatar');
-        expect(third_child_avatar.textContent).toBe('J');
-        expect(third_child.textContent).toBe('J jane');
+        expect(third_child_avatar.textContent.trim()).toBe('J');
+        expect(third_child.textContent.trim()).toBe('J jane');
 
         const fourth_child = view.querySelector('.suggestion-box__results li:nth-child(4)');
         const fourth_child_avatar = fourth_child.querySelector('converse-avatar');
-        expect(fourth_child_avatar.textContent).toBe('T');
-        expect(fourth_child.textContent).toBe('T tom');
+        expect(fourth_child_avatar.textContent.trim()).toBe('T');
+        expect(fourth_child.textContent.trim()).toBe('T tom');
     }));
 
     it("shows all autocompletion options when the user presses @ right after an allowed character",
@@ -190,23 +190,23 @@ describe("The nickname autocomplete feature", function () {
         await u.waitUntil(() => view.querySelectorAll('.suggestion-box__results li').length === 4);
         const first_child = view.querySelector('.suggestion-box__results li:first-child');
         const first_child_avatar = first_child.querySelector('converse-avatar');
-        expect(first_child_avatar.textContent).toBe('D');
-        expect(first_child.textContent).toBe('D dick');
+        expect(first_child_avatar.textContent.trim()).toBe('D');
+        expect(first_child.textContent.trim()).toBe('D dick');
 
         const second_child = view.querySelector('.suggestion-box__results li:nth-child(2)');
         const second_child_avatar = second_child.querySelector('converse-avatar');
-        expect(second_child_avatar.textContent).toBe('H');
-        expect(second_child.textContent).toBe('H harry');
+        expect(second_child_avatar.textContent.trim()).toBe('H');
+        expect(second_child.textContent.trim()).toBe('H harry');
 
         const third_child = view.querySelector('.suggestion-box__results li:nth-child(3)');
         const third_child_avatar = third_child.querySelector('converse-avatar');
-        expect(third_child_avatar.textContent).toBe('J');
-        expect(third_child.textContent).toBe('J jane');
+        expect(third_child_avatar.textContent.trim()).toBe('J');
+        expect(third_child.textContent.trim()).toBe('J jane');
 
         const fourth_child = view.querySelector('.suggestion-box__results li:nth-child(4)');
         const fourth_child_avatar = fourth_child.querySelector('converse-avatar');
-        expect(fourth_child_avatar.textContent).toBe('T');
-        expect(fourth_child.textContent).toBe('T tom');
+        expect(fourth_child_avatar.textContent.trim()).toBe('T');
+        expect(fourth_child.textContent.trim()).toBe('T tom');
     }));
 
     it("should order by query index position and length", mock.initConverse(

+ 11 - 11
src/plugins/muc-views/tests/muc-avatar.js

@@ -12,7 +12,7 @@ describe('Groupchats', () => {
 
                 const view = _converse.chatboxviews.get(muc_jid);
                 const avatar = view.querySelector('.chat-head converse-avatar .avatar-initials');
-                expect(avatar.textContent).toBe('L');
+                expect(avatar.textContent.trim()).toBe('L');
                 expect(getComputedStyle(avatar).backgroundColor).toBe('rgb(0, 135, 113)');
 
                 // eslint-disable-next-line max-len
@@ -103,7 +103,7 @@ describe('Groupchats', () => {
                     );
 
                     const initials_el = avatar_el.querySelector('.avatar-initials');
-                    expect(initials_el.textContent).toBe('AC');
+                    expect(initials_el.textContent.trim()).toBe('AC');
                     await u.waitUntil(() => getComputedStyle(initials_el).backgroundColor === 'rgb(75, 103, 255)');
                     avatar_el.click();
 
@@ -112,28 +112,28 @@ describe('Groupchats', () => {
 
                     const modal_avatar_el = modal.querySelector('converse-avatar');
                     const modal_initials_el = modal_avatar_el.querySelector('.avatar-initials');
-                    expect(modal_initials_el.textContent).toBe('AC');
+                    expect(modal_initials_el.textContent.trim()).toBe('AC');
                     expect(getComputedStyle(modal_initials_el).backgroundColor).toBe('rgb(75, 103, 255)');
 
                     let els = modal.querySelectorAll('p.room-info');
                     expect(els[0].textContent).toBe('Name: A Dark Cave');
 
-                    expect(els[1].querySelector('strong').textContent).toBe('XMPP address:');
+                    expect(els[1].querySelector('strong').textContent.trim()).toBe('XMPP address:');
                     expect(els[1].querySelector('converse-texture').textContent.trim()).toBe(
                         'xmpp:coven@chat.shakespeare.lit?join'
                     );
                     expect(els[2].querySelector('strong').textContent).toBe('Description:');
-                    expect(els[2].querySelector('converse-texture').textContent).toBe('This is the description');
+                    expect(els[2].querySelector('converse-texture').textContent.trim()).toBe('This is the description');
 
                     expect(els[3].textContent).toBe('Online users: 1');
                     const features_list = modal.querySelector('.features-list');
-                    expect(features_list.textContent.replace(/(\n|\s{2,})/g, '')).toBe(
+                    expect(features_list.textContent.replace(/(\n|\s{2,})/g, '').trim()).toBe(
                         'Password protected - This groupchat requires a password before entry' +
                         'Hidden - This groupchat is not publicly searchable' +
                         'Open - Anyone can join this groupchat' +
                         'Temporary - This groupchat will disappear once the last person leaves ' +
                         'Not anonymous - All other groupchat participants can see your XMPP address' +
-                        'Not moderated - Participants entering this groupchat can write right away '
+                        'Not moderated - Participants entering this groupchat can write right away'
                     );
                     presence = stx`
                         <presence to="romeo@montague.lit/_converse.js-29092160"
@@ -154,13 +154,13 @@ describe('Groupchats', () => {
 
                     els = modal.querySelectorAll('p.room-info');
                     expect(els[0].textContent).toBe('Name: A Dark Cave');
-                    expect(els[1].querySelector('strong').textContent).toBe('XMPP address:');
+                    expect(els[1].querySelector('strong').textContent.trim()).toBe('XMPP address:');
                     expect(els[1].querySelector('converse-texture').textContent.trim()).toBe(
                         'xmpp:coven@chat.shakespeare.lit?join'
                     );
-                    expect(els[2].querySelector('strong').textContent).toBe('Description:');
-                    expect(els[2].querySelector('converse-texture').textContent).toBe('This is the description');
-                    expect(els[3].querySelector('strong').textContent).toBe('Topic:');
+                    expect(els[2].querySelector('strong').textContent.trim()).toBe('Description:');
+                    expect(els[2].querySelector('converse-texture').textContent.trim()).toBe('This is the description');
+                    expect(els[3].querySelector('strong').textContent.trim()).toBe('Topic:');
                     await u.waitUntil(
                         () => els[3].querySelector('converse-texture').textContent === 'Hatching dark plots'
                     );

+ 1 - 1
src/plugins/muc-views/tests/muc.js

@@ -1831,7 +1831,7 @@ describe("Groupchats", function () {
             let features_shown = Array.from(features_list.children).map((e) => e.textContent);
             expect(features_shown.length).toBe(5);
 
-            expect(features_shown.join(' ')).toBe(
+            expect(features_shown.join(' ').trim()).toBe(
                 'Password protected - This groupchat requires a password before entry '+
                 'Open - Anyone can join this groupchat '+
                 'Temporary - This groupchat will disappear once the last person leaves '+

+ 1 - 2
src/plugins/profile/tests/profile.js

@@ -8,10 +8,9 @@ describe("The Controlbox", function () {
         it("shows the user's configured nickname",
             mock.initConverse([], { blacklisted_plugins: ['converse-vcard'], nickname: 'nicky'},
             async function (_converse) {
-
                 mock.openControlBox(_converse);
                 const el = await u.waitUntil(() => document.querySelector('converse-user-profile .username'));
-                expect(el.textContent).toBe('nicky');
+                expect(el.textContent.trim()).toBe('nicky');
         }));
     });
 });

+ 4 - 4
src/plugins/roomslist/tests/roomslist.js

@@ -163,12 +163,12 @@ describe("A groupchat shown in the groupchats list", function () {
         expect(avatar_el).toBeDefined();
 
         let initials_el = rooms_list.querySelector('converse-avatar .avatar-initials');
-        expect(initials_el.textContent).toBe('C');
+        expect(initials_el.textContent.trim()).toBe('C');
         expect(getComputedStyle(initials_el).backgroundColor).toBe('rgb(75, 103, 255)');
 
         const muc_el = _converse.chatboxviews.get(muc_jid);
         let muc_initials_el = muc_el.querySelector('converse-muc-heading converse-avatar .avatar-initials');
-        expect(muc_initials_el.textContent).toBe(initials_el.textContent);
+        expect(muc_initials_el.textContent.trim()).toBe(initials_el.textContent);
         expect(getComputedStyle(muc_initials_el).backgroundColor).toBe(getComputedStyle(initials_el).backgroundColor);
 
         // Change MUC name
@@ -243,11 +243,11 @@ describe("A groupchat shown in the groupchats list", function () {
         await u.waitUntil(() => new Promise(success => muc_el.model.features.on('change', success)));
 
         initials_el = rooms_list.querySelector('converse-avatar .avatar-initials');
-        expect(initials_el.textContent).toBe('NN');
+        expect(initials_el.textContent.trim()).toBe('NN');
         expect(getComputedStyle(initials_el).backgroundColor).toBe('rgb(75, 103, 255)');
 
         muc_initials_el = muc_el.querySelector('converse-muc-heading converse-avatar .avatar-initials');
-        expect(muc_initials_el.textContent).toBe(initials_el.textContent);
+        expect(muc_initials_el.textContent.trim()).toBe(initials_el.textContent);
         expect(getComputedStyle(muc_initials_el).backgroundColor).toBe(getComputedStyle(initials_el).backgroundColor);
 
         // Change MUC avatar and check that it reflects

+ 1 - 1
src/plugins/rosterview/tests/add-contact-modal.js

@@ -79,7 +79,7 @@ describe("The 'Add Contact' widget", function () {
         await u.waitUntil(() => modal.querySelector('.suggestion-box li'), 1000);
         expect(modal.querySelectorAll('.suggestion-box li').length).toBe(1);
         const suggestion = modal.querySelector('.suggestion-box li');
-        expect(suggestion.textContent).toBe('Marty McFly <marty@mcfly.net>');
+        expect(suggestion.textContent.trim()).toBe('Marty McFly <marty@mcfly.net>');
 
         const el = u.ancestor(suggestion, 'converse-autocomplete');
         el.auto_complete.select(suggestion);