Skip to content

Commit 388ec2d

Browse files
authored
Merge pull request #7 from Bilb/fix-test-with-groups
fix: fix the non-groups test for the groups changes
2 parents 7dd7bb9 + 85c2045 commit 388ec2d

File tree

10 files changed

+99
-77
lines changed

10 files changed

+99
-77
lines changed

sessionReporter.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ class SessionReporter implements Reporter {
9999

100100
console.warn('stderr:');
101101
result.stderr.map((t) => process.stderr.write(t.toString()));
102+
103+
if (result.error) {
104+
if (result.error.message) {
105+
console.warn('\nmessage:');
106+
process.stderr.write(result.error.message.toString());
107+
}
108+
if (result.error.stack) {
109+
console.warn('\nstack:');
110+
process.stderr.write(result.error.stack.toString());
111+
}
112+
}
102113
} else {
103114
console.log(
104115
`${getChalkColorForStatus(result)(

tests/automation/group_testing.spec.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
waitForTestIdWithText,
1010
} from './utilities/utils';
1111
// import { leaveGroup } from './utilities/leave_group';
12-
import { sleepFor } from '../promise_utils';
12+
import { doForAll, sleepFor } from '../promise_utils';
1313
import { newUser } from './setup/new_user';
1414
import {
1515
sessionTestThreeWindows,
@@ -18,7 +18,6 @@ import {
1818
} from './setup/sessionTest';
1919
import { createContact } from './utilities/create_contact';
2020
import { leaveGroup } from './utilities/leave_group';
21-
import { shortenWithBrackets } from '../pubkey';
2221
import { englishStrippedStr } from '../locale/localizedString';
2322

2423
// Note: Note using the group fixture here as we want to test it thoroughly
@@ -85,26 +84,19 @@ test_group_Alice_1W_Bob_1W_Charlie_1W_Dracula_1W(
8584
aliceWindow1,
8685
englishStrippedStr('okay').toString(),
8786
);
88-
await waitForTestIdWithText(
89-
aliceWindow1,
90-
'group-update-message',
91-
englishStrippedStr('legacyGroupMemberNew')
92-
.withArgs({ name: dracula.userName })
93-
.toString(),
94-
);
95-
await waitForTestIdWithText(
96-
bobWindow1,
97-
'group-update-message',
98-
englishStrippedStr('legacyGroupMemberNew')
99-
.withArgs({ name: shortenWithBrackets(dracula.accountid) })
100-
.toString(),
101-
);
102-
await waitForTestIdWithText(
103-
charlieWindow1,
104-
'group-update-message',
105-
englishStrippedStr('legacyGroupMemberNew')
106-
.withArgs({ name: shortenWithBrackets(dracula.accountid) })
107-
.toString(),
87+
// even if Bob and Charlie do not know Dracula's name,
88+
// Alice sets Dracula's name in the group members that every one will use as a fallback
89+
await doForAll(
90+
async (w) => {
91+
return waitForTestIdWithText(
92+
w,
93+
'group-update-message',
94+
englishStrippedStr('groupMemberNew')
95+
.withArgs({ name: dracula.userName })
96+
.toString(),
97+
);
98+
},
99+
[aliceWindow1, bobWindow1, charlieWindow1],
108100
);
109101
await clickOnElement({
110102
window: draculaWindow1,

tests/automation/linked_device_user.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ test_Alice_2W_Bob_1W(
276276
await hasTextMessageBeenDeleted(aliceWindow1, unsentMessage, 1000);
277277
await waitForMatchingText(
278278
bobWindow1,
279-
englishStrippedStr('deleteMessageDeleted')
280-
.withArgs({ count: 1 })
281-
.toString(),
279+
englishStrippedStr('deleteMessageDeletedGlobally').toString(),
282280
);
283281
// linked device for deleted message
284282
await hasTextMessageBeenDeleted(aliceWindow2, unsentMessage, 1000);

tests/automation/message_checks.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,7 @@ test_Alice_1W_Bob_1W(
262262
await sleepFor(1000);
263263
await waitForMatchingText(
264264
bobWindow1,
265-
englishStrippedStr('deleteMessageDeleted')
266-
.withArgs({ count: 1 })
267-
.toString(),
265+
englishStrippedStr('deleteMessageDeletedGlobally').toString(),
268266
);
269267
},
270268
);

tests/automation/message_checks_groups.spec.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { englishStrippedStr } from '../locale/localizedString';
2-
import { sleepFor } from '../promise_utils';
2+
import { doForAll, sleepFor } from '../promise_utils';
33
import { test_group_Alice_1W_Bob_1W_Charlie_1W } from './setup/sessionTest';
44
import { sendMessage } from './utilities/message';
55
import { replyTo } from './utilities/reply_message';
@@ -252,15 +252,11 @@ test_group_Alice_1W_Bob_1W_Charlie_1W(
252252
await sleepFor(1000);
253253
await waitForMatchingText(
254254
bobWindow1,
255-
englishStrippedStr('deleteMessageDeleted')
256-
.withArgs({ count: 1 })
257-
.toString(),
255+
englishStrippedStr('deleteMessageDeletedGlobally').toString(),
258256
);
259257
await waitForMatchingText(
260258
charlieWindow1,
261-
englishStrippedStr('deleteMessageDeleted')
262-
.withArgs({ count: 1 })
263-
.toString(),
259+
englishStrippedStr('deleteMessageDeletedGlobally').toString(),
264260
);
265261
},
266262
);
@@ -293,9 +289,19 @@ test_group_Alice_1W_Bob_1W_Charlie_1W(
293289
.withArgs({ count: 1 })
294290
.toString(),
295291
);
296-
await hasTextMessageBeenDeleted(aliceWindow1, deletedMessage, 5000);
297-
// Should still be there for user B and C
298-
await waitForMatchingText(bobWindow1, deletedMessage);
299-
await waitForMatchingText(charlieWindow1, deletedMessage);
292+
await doForAll(
293+
async (w) => {
294+
if (w !== aliceWindow1) {
295+
// we should have the "This message was deleted" placeholder only where the change wasn't made
296+
await waitForMatchingText(
297+
w,
298+
englishStrippedStr('deleteMessageDeletedGlobally').toString(),
299+
);
300+
}
301+
// the message should be gone on all windows
302+
await hasTextMessageBeenDeleted(w, deletedMessage, 5000);
303+
},
304+
[aliceWindow1, bobWindow1, charlieWindow1],
305+
);
300306
},
301307
);

tests/automation/setup/create_group.ts

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import {
77
clickOnTestIdWithText,
88
typeIntoInput,
99
waitForTestIdWithText,
10-
waitForTextMessage,
10+
waitForTextMessages,
1111
} from '../utilities/utils';
1212
import { englishStrippedStr } from '../../locale/localizedString';
13+
import { doForAll } from '../../promise_utils';
1314

1415
export const createGroup = async (
1516
userName: string,
@@ -21,8 +22,10 @@ export const createGroup = async (
2122
windowC: Page,
2223
): Promise<Group> => {
2324
const group: Group = { userName, userOne, userTwo, userThree };
24-
const emptyStateGroupText = englishStrippedStr('groupNoMessages')
25-
.withArgs({ group_name: group.userName })
25+
const groupUpdateInviteControlText = englishStrippedStr(
26+
'groupInviteYouAndMoreNew',
27+
)
28+
.withArgs({ count: 2 })
2629
.toString();
2730

2831
const messageAB = `${userOne.userName} to ${userTwo.userName}`;
@@ -67,7 +70,7 @@ export const createGroup = async (
6770
// Select user C
6871
await clickOnMatchingText(windowA, userThree.userName);
6972
// Click Next
70-
await clickOnTestIdWithText(windowA, 'next-button');
73+
await clickOnTestIdWithText(windowA, 'create-group-button');
7174
// Check group was successfully created
7275
await clickOnMatchingText(windowB, group.userName);
7376
await waitForTestIdWithText(
@@ -76,38 +79,29 @@ export const createGroup = async (
7679
group.userName,
7780
);
7881
// Make sure the empty state is in windowA
82+
// Updated in group v2
7983
await waitForTestIdWithText(
8084
windowA,
81-
'empty-conversation-notification',
82-
emptyStateGroupText,
85+
'group-update-message',
86+
groupUpdateInviteControlText,
8387
);
8488

85-
await Promise.all([
86-
(async () => {
87-
// Navigate to group in window B
88-
await clickOnTestIdWithText(windowB, 'message-section');
89+
// Make sure the empty state is in windowB & windowC
90+
await doForAll(
91+
async (w) => {
92+
// Navigate to group in the window
93+
await clickOnTestIdWithText(w, 'message-section');
8994
// Click on test group
90-
await clickOnMatchingText(windowB, group.userName);
91-
// Make sure the empty state is in windowB
95+
await clickOnMatchingText(w, group.userName);
96+
// Make sure the empty state is in w
9297
return waitForTestIdWithText(
93-
windowB,
94-
'empty-conversation-notification',
95-
emptyStateGroupText,
98+
w,
99+
'group-update-message',
100+
groupUpdateInviteControlText,
96101
);
97-
})(),
98-
(async () => {
99-
// Navigate to group in window C
100-
await clickOnTestIdWithText(windowC, 'message-section');
101-
// Click on test group
102-
await clickOnMatchingText(windowC, group.userName);
103-
// Make sure the empty state is in windowC
104-
return waitForTestIdWithText(
105-
windowC,
106-
'empty-conversation-notification',
107-
emptyStateGroupText,
108-
);
109-
})(),
110-
]);
102+
},
103+
[windowB, windowC],
104+
);
111105

112106
// Send message in group chat from user A
113107
await sendMessage(windowA, msgAToGroup);
@@ -125,16 +119,13 @@ export const createGroup = async (
125119
// Verify that each messages was received by the other two accounts
126120

127121
// windowA should see the message from B and the message from C
128-
await waitForTextMessage(windowA, msgBToGroup);
129-
await waitForTextMessage(windowA, msgCToGroup);
122+
await waitForTextMessages(windowA, [msgBToGroup, msgCToGroup]);
130123

131124
// windowB should see the message from A and the message from C
132-
await waitForTextMessage(windowB, msgAToGroup);
133-
await waitForTextMessage(windowB, msgCToGroup);
125+
await waitForTextMessages(windowB, [msgAToGroup, msgCToGroup]);
134126

135127
// windowC must see the message from A and the message from B
136-
await waitForTextMessage(windowC, msgAToGroup);
137-
await waitForTextMessage(windowC, msgBToGroup);
128+
await waitForTextMessages(windowC, [msgAToGroup, msgBToGroup]);
138129

139130
// Focus screen
140131
// await clickOnTestIdWithText(windowB, 'scroll-to-bottom-button');

tests/automation/setup/sessionTest.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable no-empty-pattern */
22
/* eslint-disable @typescript-eslint/array-type */
3+
import chalk from 'chalk';
4+
35
import { Page, TestInfo, test } from '@playwright/test';
46
import { Group, User } from '../types/testing';
57
import { linkedDevice } from '../utilities/linked_device';
@@ -148,8 +150,9 @@ function sessionTestGeneric<
148150
for (let index = 0; index < links.length; index++) {
149151
const link = links[index];
150152
console.info(
151-
'linking a window with ',
152-
users[link - 1].recoveryPassword,
153+
`linking a window with "${chalk.green(
154+
users[link - 1].recoveryPassword,
155+
)}"`,
153156
);
154157
const linked = await linkedDevice(users[link - 1].recoveryPassword);
155158
linkedWindows.push(linked);

tests/automation/types/testing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export type DataTestId =
126126
| 'messages-container'
127127
| 'chooser-new-group'
128128
| 'new-closed-group-name'
129-
| 'next-button'
129+
| 'create-group-button'
130130
| 'link-device'
131131
| 'group-name-input'
132132
| 'right-panel-group-name'

tests/automation/utilities/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ export async function waitForTextMessage(
9090
return el;
9191
}
9292

93+
export async function waitForTextMessages(
94+
window: Page,
95+
texts: Array<string>,
96+
maxWait?: number,
97+
) {
98+
return Promise.all(
99+
texts.map(async (t) => waitForTextMessage(window, t, maxWait)),
100+
);
101+
}
102+
93103
export async function waitForControlMessageWithText(
94104
window: Page,
95105
text: string,

tests/promise_utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Page } from '@playwright/test';
2+
13
export const sleepFor = async (ms: number, showLog = false) => {
24
if (showLog) {
35
// eslint-disable-next-line no-console
@@ -7,3 +9,14 @@ export const sleepFor = async (ms: number, showLog = false) => {
79
setTimeout(resolve, ms);
810
});
911
};
12+
13+
export async function doForAll<T>(
14+
fn: (window: Page) => Promise<T>,
15+
windows: Array<Page>,
16+
) {
17+
return Promise.all(
18+
windows.map(async (w) => {
19+
return fn(w);
20+
}),
21+
);
22+
}

0 commit comments

Comments
 (0)