Skip to content

Commit e70c8c3

Browse files
authored
Merge pull request #45 from session-foundation/feat/pre-pro-tests
2 parents 640954f + 8d54f53 commit e70c8c3

6 files changed

Lines changed: 201 additions & 2 deletions

File tree

tests/automation/enforce_localized_str.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ function getExpectedStringFromKey(
259259
return "You don't have any conversations yet";
260260
case 'onboardingHitThePlusButton':
261261
return 'Hit the plus button to start a chat, create a group, or join an official community!';
262-
262+
case 'modalMessageTooLongTitle':
263+
return 'Message Too Long';
264+
case 'modalMessageTooLongDescription':
265+
return 'Please shorten your message to {limit} characters or less.';
263266
default:
264267
// returning null means we don't have an expected string yet for this key.
265268
// This will make the test fail

tests/automation/locators/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ export class Settings extends Locator {
159159
);
160160
static readonly confirmPasswordInput = this.testId('password-input-confirm');
161161
static readonly enableCalls = this.testId('enable-calls-settings-row');
162+
static readonly enableCommunityMessageRequests = this.testId(
163+
'enable-communities-message-requests-settings-row',
164+
);
162165
static readonly enableMicrophone = this.testId(
163166
'enable-microphone-settings-row',
164167
);

tests/automation/message_checks.spec.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
trustUser,
2525
} from './utilities/send_media';
2626
import {
27+
checkModalStrings,
2728
clickOn,
2829
clickOnElement,
2930
clickOnMatchingText,
@@ -255,3 +256,106 @@ sessionTestTwoWindows(
255256
console.log(timesArray);
256257
},
257258
);
259+
260+
// Message length limit tests (pre-pro)
261+
const maxChars = 2000;
262+
const countdownThreshold = 1800;
263+
264+
const messageLengthTestCases = [
265+
{
266+
length: 1799,
267+
char: 'a',
268+
shouldSend: true,
269+
},
270+
{
271+
length: 1800,
272+
char: 'b',
273+
shouldSend: true,
274+
},
275+
{
276+
length: 2000,
277+
char: 'c',
278+
shouldSend: true,
279+
},
280+
{
281+
length: 2001,
282+
char: 'd',
283+
shouldSend: false,
284+
},
285+
];
286+
287+
messageLengthTestCases.forEach((testCase) => {
288+
test_Alice_1W_Bob_1W(
289+
`Message length limit (${testCase.length} chars)`,
290+
async ({ alice, aliceWindow1, bob, bobWindow1 }) => {
291+
await createContact(aliceWindow1, bobWindow1, alice, bob);
292+
const expectedCount =
293+
testCase.length < countdownThreshold
294+
? null
295+
: (maxChars - testCase.length).toString();
296+
const message = testCase.char.repeat(testCase.length);
297+
// Type the message
298+
await typeIntoInput(
299+
aliceWindow1,
300+
'message-input-text-area',
301+
message,
302+
true, // Paste because otherwise Playwright times out
303+
);
304+
305+
// Check countdown behavior
306+
if (expectedCount) {
307+
await waitForTestIdWithText(
308+
aliceWindow1,
309+
'tooltip-character-count',
310+
expectedCount,
311+
);
312+
} else {
313+
// Verify countdown tooltip is not present
314+
try {
315+
await waitForElement(
316+
aliceWindow1,
317+
'data-testid',
318+
'tooltip-character-count',
319+
1000,
320+
);
321+
throw new Error(
322+
`Countdown should not be visible for messages under ${countdownThreshold} chars`,
323+
);
324+
} catch (e) {
325+
// Expected - countdown should not exist
326+
console.log('Countdown not present as expected');
327+
}
328+
}
329+
330+
// Try to send
331+
await clickOn(aliceWindow1, Conversation.sendMessageButton);
332+
333+
if (testCase.shouldSend) {
334+
// Message should appear in Alice's window
335+
await Promise.all(
336+
[aliceWindow1, bobWindow1].map(async (w) => {
337+
await waitForTextMessage(w, message);
338+
}),
339+
);
340+
} else {
341+
// Message Too Long modal
342+
await checkModalStrings(
343+
aliceWindow1,
344+
englishStrippedStr('modalMessageTooLongTitle').toString(),
345+
englishStrippedStr('modalMessageTooLongDescription')
346+
.withArgs({ limit: maxChars.toLocaleString('en-AU') }) // Force "2,000" instead of "2000"
347+
.toString(),
348+
);
349+
await clickOn(aliceWindow1, Global.confirmButton);
350+
351+
// Verify message didn't send
352+
try {
353+
await waitForTextMessage(aliceWindow1, message, 2000);
354+
throw new Error('Message should not have been sent');
355+
} catch (e) {
356+
console.log(`Message didn't send as expected`);
357+
}
358+
}
359+
},
360+
);
361+
});

tests/automation/message_requests.spec.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { expect } from '@playwright/test';
2+
13
import { englishStrippedStr } from '../localization/englishStrippedStr';
24
import {
35
Conversation,
@@ -7,13 +9,15 @@ import {
79
Settings,
810
} from './locators';
911
import { test_Alice_1W_Bob_1W } from './setup/sessionTest';
12+
import { joinCommunity } from './utilities/join_community';
1013
import { sendMessage } from './utilities/message';
1114
import { sendNewMessage } from './utilities/send_message';
1215
import {
1316
checkModalStrings,
1417
clickOn,
1518
clickOnMatchingText,
1619
clickOnWithText,
20+
grabTextFromElement,
1721
waitForMatchingText,
1822
waitForTestIdWithText,
1923
} from './utilities/utils';
@@ -164,3 +168,81 @@ test_Alice_1W_Bob_1W(
164168
);
165169
},
166170
);
171+
172+
test_Alice_1W_Bob_1W(
173+
'Community message requests on',
174+
async ({ alice, aliceWindow1, bob, bobWindow1 }) => {
175+
await clickOn(bobWindow1, LeftPane.settingsButton);
176+
await clickOn(bobWindow1, Settings.privacyMenuItem);
177+
await clickOn(bobWindow1, Settings.enableCommunityMessageRequests);
178+
await clickOn(bobWindow1, Global.modalCloseButton);
179+
await Promise.all([joinCommunity(aliceWindow1), joinCommunity(bobWindow1)]);
180+
const communityMsg = `I accept message requests + ${Date.now()}`;
181+
await sendMessage(bobWindow1, communityMsg);
182+
await clickOn(aliceWindow1, Conversation.scrollToBottomButton);
183+
// Using native methods to locate the author corresponding to the sent message
184+
await aliceWindow1
185+
.locator('.module-message__container', { hasText: communityMsg })
186+
.locator('..') // Go up to parent
187+
.locator('svg')
188+
.click();
189+
const elText = await grabTextFromElement(
190+
aliceWindow1,
191+
'data-testid',
192+
'account-id',
193+
);
194+
expect(elText).toMatch(/^15/);
195+
await clickOn(aliceWindow1, HomeScreen.newMessageAccountIDInput); // yes this is the actual locator for the 'Message' button
196+
await waitForTestIdWithText(
197+
aliceWindow1,
198+
'header-conversation-name',
199+
bob.userName,
200+
);
201+
const messageRequestMsg = `${alice.userName} to ${bob.userName}`;
202+
const messageRequestResponse = `${bob.userName} accepts message request`;
203+
await sendMessage(aliceWindow1, messageRequestMsg);
204+
await clickOn(bobWindow1, HomeScreen.messageRequestBanner);
205+
// Select message request from User A
206+
await clickOnWithText(
207+
bobWindow1,
208+
HomeScreen.conversationItemName,
209+
alice.userName,
210+
);
211+
await sendMessage(bobWindow1, messageRequestResponse);
212+
// Check config message of message request acceptance
213+
await waitForTestIdWithText(
214+
bobWindow1,
215+
'message-request-response-message',
216+
englishStrippedStr('messageRequestYouHaveAccepted')
217+
.withArgs({
218+
name: alice.userName,
219+
})
220+
.toString(),
221+
);
222+
},
223+
);
224+
test_Alice_1W_Bob_1W(
225+
'Community message requests off',
226+
async ({ aliceWindow1, bobWindow1 }) => {
227+
await Promise.all([joinCommunity(aliceWindow1), joinCommunity(bobWindow1)]);
228+
const communityMsg = `I do not accept message requests + ${Date.now()}`;
229+
await sendMessage(bobWindow1, communityMsg);
230+
await clickOn(aliceWindow1, Conversation.scrollToBottomButton);
231+
// Using native methods to locate the author corresponding to the sent message
232+
await aliceWindow1
233+
.locator('.module-message__container', { hasText: communityMsg })
234+
.locator('..') // Go up to parent
235+
.locator('svg')
236+
.click();
237+
const elText = await grabTextFromElement(
238+
aliceWindow1,
239+
'data-testid',
240+
'account-id',
241+
);
242+
expect(elText).toMatch(/^15/);
243+
const messageButton = aliceWindow1.getByTestId(
244+
HomeScreen.newMessageAccountIDInput.selector,
245+
);
246+
await expect(messageButton).toHaveClass(/disabled/);
247+
},
248+
);

tests/automation/types/testing.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export type DataTestId =
120120
| 'edit-profile-icon'
121121
| 'empty-conversation-notification'
122122
| 'enable-calls-settings-row'
123+
| 'enable-communities-message-requests-settings-row'
123124
| 'enable-microphone-settings-row'
124125
| 'enable-read-receipts-settings-row'
125126
| 'end-call'
@@ -186,6 +187,7 @@ export type DataTestId =
186187
| 'set-password-settings-button'
187188
| 'settings-section'
188189
| 'theme-section'
190+
| 'tooltip-character-count'
189191
| 'unblock-button-settings-screen'
190192
| 'update-group-info-name-input'
191193
| 'update-profile-info-name-input'

tests/automation/utilities/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ export async function typeIntoInput(
373373
window: Page,
374374
dataTestId: DataTestId,
375375
text: string,
376+
paste?: boolean, // typing long messages hits the runner timeout
376377
) {
377378
console.info(`typeIntoInput testId: ${dataTestId} : "${text}"`);
378379
const builtSelector = `css=[data-testid=${dataTestId}]`;
@@ -382,7 +383,11 @@ export async function typeIntoInput(
382383
await clickOn(window, locator);
383384
// reset the content to be empty before typing into the input
384385
await window.fill(builtSelector, '');
385-
return window.type(builtSelector, text);
386+
if (paste) {
387+
await window.fill(builtSelector, text);
388+
} else {
389+
await window.type(builtSelector, text);
390+
}
386391
}
387392

388393
export async function doesTextIncludeString(

0 commit comments

Comments
 (0)