Skip to content

Commit f8d4e61

Browse files
committed
Use trim() to fix failing tests
1 parent d7e7b6f commit f8d4e61

File tree

9 files changed

+51
-52
lines changed

9 files changed

+51
-52
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe("Ad-hoc commands", function () {
6666
</iq>`));
6767

6868
const heading = await u.waitUntil(() => adhoc_form.querySelector('.list-group-item.active'));
69-
expect(heading.textContent).toBe('Commands found:');
69+
expect(heading.textContent.trim()).toBe('Commands found:');
7070

7171
const items = adhoc_form.querySelectorAll('.list-group-item:not(.active)');
7272
expect(items.length).toBe(7);
@@ -181,7 +181,7 @@ describe("Ad-hoc commands", function () {
181181
</iq>`));
182182

183183
const heading = await u.waitUntil(() => adhoc_form.querySelector('.list-group-item.active'));
184-
expect(heading.textContent).toBe('Commands found:');
184+
expect(heading.textContent.trim()).toBe('Commands found:');
185185

186186
const items = adhoc_form.querySelectorAll('.list-group-item:not(.active)');
187187
expect(items.length).toBe(1);
@@ -222,7 +222,7 @@ describe("Ad-hoc commands", function () {
222222
const form = await u.waitUntil(() => adhoc_form.querySelector('form form'));
223223
const alert = form.querySelector('div.alert');
224224
expect(u.isVisible(alert)).toBe(true);
225-
expect(alert.textContent).toBe(uptime_text);
225+
expect(alert.textContent.trim()).toBe(uptime_text);
226226

227227
const inputs = form.querySelectorAll('input[type="button"]');
228228
expect(inputs.length).toBe(0);
@@ -271,7 +271,7 @@ describe("Ad-hoc commands", function () {
271271
</iq>`));
272272

273273
const heading = await u.waitUntil(() => adhoc_form.querySelector('.list-group-item.active'));
274-
expect(heading.textContent).toBe('Commands found:');
274+
expect(heading.textContent.trim()).toBe('Commands found:');
275275

276276
const items = adhoc_form.querySelectorAll('.list-group-item:not(.active)');
277277
expect(items.length).toBe(1);
@@ -396,7 +396,7 @@ describe("Ad-hoc commands", function () {
396396
</iq>`));
397397

398398
const heading = await u.waitUntil(() => adhoc_form.querySelector('.list-group-item.active'));
399-
expect(heading.textContent).toBe('Commands found:');
399+
expect(heading.textContent.trim()).toBe('Commands found:');
400400

401401
const items = adhoc_form.querySelectorAll('.list-group-item:not(.active)');
402402
expect(items.length).toBe(1);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe("A Chat Message", function () {
2424
await u.waitUntil(() => view.querySelectorAll('.chat-msg__text').length === 1);
2525

2626
let el = view.querySelector('converse-chat-message converse-avatar .avatar-initials');
27-
expect(el.textContent).toBe('RM');
27+
expect(el.textContent.trim()).toBe('RM');
2828
expect(getComputedStyle(el).backgroundColor).toBe('rgb(198, 84, 0)');
2929

3030
// Test messages from other user
@@ -43,14 +43,14 @@ describe("A Chat Message", function () {
4343
el = view.querySelector(
4444
`converse-chat-message div[data-from="${contact_jid}"] converse-avatar .avatar-initials`
4545
);
46-
expect(el.textContent).toBe('M');
46+
expect(el.textContent.trim()).toBe('M');
4747
expect(getComputedStyle(el).backgroundColor).toBe('rgb(195, 0, 249)');
4848

4949
// Change contact nickname and see that it reflects
5050
const contact = await api.contacts.get(contact_jid);
5151
contact.set('nickname', 'Wizzard');
5252

53-
await u.waitUntil(() => el.textContent === 'W');
53+
await u.waitUntil(() => el.textContent.trim() === 'W');
5454

5555
// Change own nickname and see that it reflects
5656
const own_jid = _converse.session.get('jid');

src/plugins/chatview/tests/messages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("A Chat Message", function () {
2626
await u.waitUntil(() => view.querySelectorAll('converse-chat-message').length === 2);
2727
await u.waitUntil(() => view.querySelector('converse-chat-message:last-child .chat-msg__text')?.textContent === 'This message will be new');
2828
const last_msg_el = view.querySelector('converse-chat-message:last-child');
29-
expect(last_msg_el.firstElementChild?.textContent).toBe('New messages');
29+
expect(last_msg_el.firstElementChild?.textContent.trim()).toBe('New messages');
3030
}));
3131

3232

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,23 @@ describe("The nickname autocomplete feature", function () {
5252

5353
const first_child = view.querySelector('.suggestion-box__results li:first-child');
5454
const first_child_avatar = first_child.querySelector('converse-avatar');
55-
expect(first_child_avatar.textContent).toBe('D');
56-
expect(first_child.textContent).toBe('D dick');
55+
expect(first_child_avatar.textContent.trim()).toBe('D');
56+
expect(first_child.textContent.trim()).toBe('D dick');
5757

5858
const second_child = view.querySelector('.suggestion-box__results li:nth-child(2)');
5959
const second_child_avatar = second_child.querySelector('converse-avatar');
60-
expect(second_child_avatar.textContent).toBe('H');
61-
expect(second_child.textContent).toBe('H harry');
60+
expect(second_child_avatar.textContent.trim()).toBe('H');
61+
expect(second_child.textContent.trim()).toBe('H harry');
6262

6363
const third_child = view.querySelector('.suggestion-box__results li:nth-child(3)');
6464
const third_child_avatar = third_child.querySelector('converse-avatar');
65-
expect(third_child_avatar.textContent).toBe('J');
66-
expect(third_child.textContent).toBe('J jane');
65+
expect(third_child_avatar.textContent.trim()).toBe('J');
66+
expect(third_child.textContent.trim()).toBe('J jane');
6767

6868
const fourth_child = view.querySelector('.suggestion-box__results li:nth-child(4)');
6969
const fourth_child_avatar = fourth_child.querySelector('converse-avatar');
70-
expect(fourth_child_avatar.textContent).toBe('T');
71-
expect(fourth_child.textContent).toBe('T tom');
70+
expect(fourth_child_avatar.textContent.trim()).toBe('T');
71+
expect(fourth_child.textContent.trim()).toBe('T tom');
7272
}));
7373

7474
it("shows all autocompletion options when the user presses @ right after a new line",
@@ -120,23 +120,23 @@ describe("The nickname autocomplete feature", function () {
120120
await u.waitUntil(() => view.querySelectorAll('.suggestion-box__results li').length === 4);
121121
const first_child = view.querySelector('.suggestion-box__results li:first-child');
122122
const first_child_avatar = first_child.querySelector('converse-avatar');
123-
expect(first_child_avatar.textContent).toBe('D');
124-
expect(first_child.textContent).toBe('D dick');
123+
expect(first_child_avatar.textContent.trim()).toBe('D');
124+
expect(first_child.textContent.trim()).toBe('D dick');
125125

126126
const second_child = view.querySelector('.suggestion-box__results li:nth-child(2)');
127127
const second_child_avatar = second_child.querySelector('converse-avatar');
128-
expect(second_child_avatar.textContent).toBe('H');
129-
expect(second_child.textContent).toBe('H harry');
128+
expect(second_child_avatar.textContent.trim()).toBe('H');
129+
expect(second_child.textContent.trim()).toBe('H harry');
130130

131131
const third_child = view.querySelector('.suggestion-box__results li:nth-child(3)');
132132
const third_child_avatar = third_child.querySelector('converse-avatar');
133-
expect(third_child_avatar.textContent).toBe('J');
134-
expect(third_child.textContent).toBe('J jane');
133+
expect(third_child_avatar.textContent.trim()).toBe('J');
134+
expect(third_child.textContent.trim()).toBe('J jane');
135135

136136
const fourth_child = view.querySelector('.suggestion-box__results li:nth-child(4)');
137137
const fourth_child_avatar = fourth_child.querySelector('converse-avatar');
138-
expect(fourth_child_avatar.textContent).toBe('T');
139-
expect(fourth_child.textContent).toBe('T tom');
138+
expect(fourth_child_avatar.textContent.trim()).toBe('T');
139+
expect(fourth_child.textContent.trim()).toBe('T tom');
140140
}));
141141

142142
it("shows all autocompletion options when the user presses @ right after an allowed character",
@@ -190,23 +190,23 @@ describe("The nickname autocomplete feature", function () {
190190
await u.waitUntil(() => view.querySelectorAll('.suggestion-box__results li').length === 4);
191191
const first_child = view.querySelector('.suggestion-box__results li:first-child');
192192
const first_child_avatar = first_child.querySelector('converse-avatar');
193-
expect(first_child_avatar.textContent).toBe('D');
194-
expect(first_child.textContent).toBe('D dick');
193+
expect(first_child_avatar.textContent.trim()).toBe('D');
194+
expect(first_child.textContent.trim()).toBe('D dick');
195195

196196
const second_child = view.querySelector('.suggestion-box__results li:nth-child(2)');
197197
const second_child_avatar = second_child.querySelector('converse-avatar');
198-
expect(second_child_avatar.textContent).toBe('H');
199-
expect(second_child.textContent).toBe('H harry');
198+
expect(second_child_avatar.textContent.trim()).toBe('H');
199+
expect(second_child.textContent.trim()).toBe('H harry');
200200

201201
const third_child = view.querySelector('.suggestion-box__results li:nth-child(3)');
202202
const third_child_avatar = third_child.querySelector('converse-avatar');
203-
expect(third_child_avatar.textContent).toBe('J');
204-
expect(third_child.textContent).toBe('J jane');
203+
expect(third_child_avatar.textContent.trim()).toBe('J');
204+
expect(third_child.textContent.trim()).toBe('J jane');
205205

206206
const fourth_child = view.querySelector('.suggestion-box__results li:nth-child(4)');
207207
const fourth_child_avatar = fourth_child.querySelector('converse-avatar');
208-
expect(fourth_child_avatar.textContent).toBe('T');
209-
expect(fourth_child.textContent).toBe('T tom');
208+
expect(fourth_child_avatar.textContent.trim()).toBe('T');
209+
expect(fourth_child.textContent.trim()).toBe('T tom');
210210
}));
211211

212212
it("should order by query index position and length", mock.initConverse(

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Groupchats', () => {
1212

1313
const view = _converse.chatboxviews.get(muc_jid);
1414
const avatar = view.querySelector('.chat-head converse-avatar .avatar-initials');
15-
expect(avatar.textContent).toBe('L');
15+
expect(avatar.textContent.trim()).toBe('L');
1616
expect(getComputedStyle(avatar).backgroundColor).toBe('rgb(0, 135, 113)');
1717

1818
// eslint-disable-next-line max-len
@@ -103,7 +103,7 @@ describe('Groupchats', () => {
103103
);
104104

105105
const initials_el = avatar_el.querySelector('.avatar-initials');
106-
expect(initials_el.textContent).toBe('AC');
106+
expect(initials_el.textContent.trim()).toBe('AC');
107107
await u.waitUntil(() => getComputedStyle(initials_el).backgroundColor === 'rgb(75, 103, 255)');
108108
avatar_el.click();
109109

@@ -112,28 +112,28 @@ describe('Groupchats', () => {
112112

113113
const modal_avatar_el = modal.querySelector('converse-avatar');
114114
const modal_initials_el = modal_avatar_el.querySelector('.avatar-initials');
115-
expect(modal_initials_el.textContent).toBe('AC');
115+
expect(modal_initials_el.textContent.trim()).toBe('AC');
116116
expect(getComputedStyle(modal_initials_el).backgroundColor).toBe('rgb(75, 103, 255)');
117117

118118
let els = modal.querySelectorAll('p.room-info');
119119
expect(els[0].textContent).toBe('Name: A Dark Cave');
120120

121-
expect(els[1].querySelector('strong').textContent).toBe('XMPP address:');
121+
expect(els[1].querySelector('strong').textContent.trim()).toBe('XMPP address:');
122122
expect(els[1].querySelector('converse-texture').textContent.trim()).toBe(
123123
'xmpp:coven@chat.shakespeare.lit?join'
124124
);
125125
expect(els[2].querySelector('strong').textContent).toBe('Description:');
126-
expect(els[2].querySelector('converse-texture').textContent).toBe('This is the description');
126+
expect(els[2].querySelector('converse-texture').textContent.trim()).toBe('This is the description');
127127

128128
expect(els[3].textContent).toBe('Online users: 1');
129129
const features_list = modal.querySelector('.features-list');
130-
expect(features_list.textContent.replace(/(\n|\s{2,})/g, '')).toBe(
130+
expect(features_list.textContent.replace(/(\n|\s{2,})/g, '').trim()).toBe(
131131
'Password protected - This groupchat requires a password before entry' +
132132
'Hidden - This groupchat is not publicly searchable' +
133133
'Open - Anyone can join this groupchat' +
134134
'Temporary - This groupchat will disappear once the last person leaves ' +
135135
'Not anonymous - All other groupchat participants can see your XMPP address' +
136-
'Not moderated - Participants entering this groupchat can write right away '
136+
'Not moderated - Participants entering this groupchat can write right away'
137137
);
138138
presence = stx`
139139
<presence to="romeo@montague.lit/_converse.js-29092160"
@@ -154,13 +154,13 @@ describe('Groupchats', () => {
154154

155155
els = modal.querySelectorAll('p.room-info');
156156
expect(els[0].textContent).toBe('Name: A Dark Cave');
157-
expect(els[1].querySelector('strong').textContent).toBe('XMPP address:');
157+
expect(els[1].querySelector('strong').textContent.trim()).toBe('XMPP address:');
158158
expect(els[1].querySelector('converse-texture').textContent.trim()).toBe(
159159
'xmpp:coven@chat.shakespeare.lit?join'
160160
);
161-
expect(els[2].querySelector('strong').textContent).toBe('Description:');
162-
expect(els[2].querySelector('converse-texture').textContent).toBe('This is the description');
163-
expect(els[3].querySelector('strong').textContent).toBe('Topic:');
161+
expect(els[2].querySelector('strong').textContent.trim()).toBe('Description:');
162+
expect(els[2].querySelector('converse-texture').textContent.trim()).toBe('This is the description');
163+
expect(els[3].querySelector('strong').textContent.trim()).toBe('Topic:');
164164
await u.waitUntil(
165165
() => els[3].querySelector('converse-texture').textContent === 'Hatching dark plots'
166166
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ describe("Groupchats", function () {
18311831
let features_shown = Array.from(features_list.children).map((e) => e.textContent);
18321832
expect(features_shown.length).toBe(5);
18331833

1834-
expect(features_shown.join(' ')).toBe(
1834+
expect(features_shown.join(' ').trim()).toBe(
18351835
'Password protected - This groupchat requires a password before entry '+
18361836
'Open - Anyone can join this groupchat '+
18371837
'Temporary - This groupchat will disappear once the last person leaves '+

src/plugins/profile/tests/profile.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ describe("The Controlbox", function () {
88
it("shows the user's configured nickname",
99
mock.initConverse([], { blacklisted_plugins: ['converse-vcard'], nickname: 'nicky'},
1010
async function (_converse) {
11-
1211
mock.openControlBox(_converse);
1312
const el = await u.waitUntil(() => document.querySelector('converse-user-profile .username'));
14-
expect(el.textContent).toBe('nicky');
13+
expect(el.textContent.trim()).toBe('nicky');
1514
}));
1615
});
1716
});

src/plugins/roomslist/tests/roomslist.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ describe("A groupchat shown in the groupchats list", function () {
163163
expect(avatar_el).toBeDefined();
164164

165165
let initials_el = rooms_list.querySelector('converse-avatar .avatar-initials');
166-
expect(initials_el.textContent).toBe('C');
166+
expect(initials_el.textContent.trim()).toBe('C');
167167
expect(getComputedStyle(initials_el).backgroundColor).toBe('rgb(75, 103, 255)');
168168

169169
const muc_el = _converse.chatboxviews.get(muc_jid);
170170
let muc_initials_el = muc_el.querySelector('converse-muc-heading converse-avatar .avatar-initials');
171-
expect(muc_initials_el.textContent).toBe(initials_el.textContent);
171+
expect(muc_initials_el.textContent.trim()).toBe(initials_el.textContent);
172172
expect(getComputedStyle(muc_initials_el).backgroundColor).toBe(getComputedStyle(initials_el).backgroundColor);
173173

174174
// Change MUC name
@@ -243,11 +243,11 @@ describe("A groupchat shown in the groupchats list", function () {
243243
await u.waitUntil(() => new Promise(success => muc_el.model.features.on('change', success)));
244244

245245
initials_el = rooms_list.querySelector('converse-avatar .avatar-initials');
246-
expect(initials_el.textContent).toBe('NN');
246+
expect(initials_el.textContent.trim()).toBe('NN');
247247
expect(getComputedStyle(initials_el).backgroundColor).toBe('rgb(75, 103, 255)');
248248

249249
muc_initials_el = muc_el.querySelector('converse-muc-heading converse-avatar .avatar-initials');
250-
expect(muc_initials_el.textContent).toBe(initials_el.textContent);
250+
expect(muc_initials_el.textContent.trim()).toBe(initials_el.textContent);
251251
expect(getComputedStyle(muc_initials_el).backgroundColor).toBe(getComputedStyle(initials_el).backgroundColor);
252252

253253
// Change MUC avatar and check that it reflects

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe("The 'Add Contact' widget", function () {
7979
await u.waitUntil(() => modal.querySelector('.suggestion-box li'), 1000);
8080
expect(modal.querySelectorAll('.suggestion-box li').length).toBe(1);
8181
const suggestion = modal.querySelector('.suggestion-box li');
82-
expect(suggestion.textContent).toBe('Marty McFly <marty@mcfly.net>');
82+
expect(suggestion.textContent.trim()).toBe('Marty McFly <marty@mcfly.net>');
8383

8484
const el = u.ancestor(suggestion, 'converse-autocomplete');
8585
el.auto_complete.select(suggestion);

0 commit comments

Comments
 (0)