Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions tests/automation/cta_donations.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { englishStrippedStr } from '../localization/englishStrippedStr';
import { CTA } from './locators';
import { test_Alice_1W } from './setup/sessionTest';
import { mockDBCreationTime } from './utilities/time_travel';
import {
checkCTAStrings,
hasElementPoppedUpThatShouldnt,
} from './utilities/utils';

test_Alice_1W(
'Donate CTA, DB age >= 7 days',
async ({ aliceWindow1 }) => {
await checkCTAStrings(
aliceWindow1,
englishStrippedStr('donateSessionHelp').toString(),
englishStrippedStr('donateSessionDescription').toString(),
[
englishStrippedStr('donate').toString(),
englishStrippedStr('maybeLater').toString(),
],
);
},
{
dbCreationTimestampMs: mockDBCreationTime({
days: -7,
minutes: -2,
}),
},
);

test_Alice_1W(
'Donate CTA, DB age < 7 days',
async ({ aliceWindow1 }) => {
await Promise.all([
hasElementPoppedUpThatShouldnt(
aliceWindow1,
CTA.heading.strategy,
CTA.heading.selector,
),
hasElementPoppedUpThatShouldnt(
aliceWindow1,
CTA.description.strategy,
CTA.description.selector,
),
hasElementPoppedUpThatShouldnt(
aliceWindow1,
CTA.confirmButton.strategy,
CTA.confirmButton.selector,
),
hasElementPoppedUpThatShouldnt(
aliceWindow1,
CTA.cancelButton.strategy,
CTA.cancelButton.selector,
),
]);
},
{
dbCreationTimestampMs: mockDBCreationTime({
days: -6,
hours: -23,
minutes: -58,
}),
},
);
37 changes: 23 additions & 14 deletions tests/automation/enforce_localized_str.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,24 @@ function getExpectedStringFromKey(
| { key: TokenPluralWithArgs; count: number }
| { key: TokenSimpleNoArgs | TokenSimpleWithArgs },
) {
if (isPluralToken(args.key)) {
if (!('count' in args)) {
throw new Error(
`getExpectedStringFromKey: ${args.key} is a plural form and expected count to be set`,
);
if ('count' in args && isPluralToken(args.key)) {
const count = args.count;

switch (args.key) {
// plurals are centralized here
case 'deleteMessageDeleted':
return count === 1 ? 'Message deleted' : 'Messages deleted';
case 'deleteMessage':
return count === 1 ? 'Delete Message' : 'Delete Messages';
case 'deleteMessageConfirm':
return count === 1
? 'Are you sure you want to delete this message?'
: 'Are you sure you want to delete these messages?';
default:
return null;
}
}
switch (args.key) {
// plurals are centralized here
case 'deleteMessageDeleted':
return args.count === 1 ? 'Message deleted' : 'Messages deleted';
case 'deleteMessage':
return args.count === 1 ? 'Delete Message' : 'Delete Messages';
case 'deleteMessageConfirm':
return args.count === 1
? 'Are you sure you want to delete this message?'
: 'Are you sure you want to delete these messages?';
case 'accept':
return 'Accept';
case 'sessionClearData':
Expand Down Expand Up @@ -283,6 +284,14 @@ function getExpectedStringFromKey(
return 'You cannot go back further. In order to stop loading your account, Session needs to quit.';
case 'quitButton':
return 'Quit';
case 'donateSessionHelp':
return 'Session Needs Your Help';
case 'donateSessionDescription':
return 'Powerful forces are trying to weaken privacy, but we can’t continue this fight alone. Donating helps keep Session secure, independent, and online.';
case 'donate':
return 'Donate';
case 'maybeLater':
return 'Maybe Later';
default:
// returning null means we don't have an expected string yet for this key.
// This will make the test fail
Expand Down
11 changes: 11 additions & 0 deletions tests/automation/locators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ export class Settings extends Locator {
);
}

export class CTA extends Locator {
static readonly cancelButton = this.testId('cta-cancel-button');
static readonly confirmButton = this.testId('cta-confirm-button');
static readonly description = this.testId('cta-body');
static readonly heading = this.testId('cta-heading');

static feature(index: number): StrategyExtractionObj {
return this.testId(`cta-list-item-${index}` as DataTestId);
}
}

export class Global extends Locator {
static readonly backButton = this.testId('back-button');
static readonly cancelButton = this.testId('session-confirm-cancel-button');
Expand Down
30 changes: 25 additions & 5 deletions tests/automation/setup/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const MULTI_PREFIX = 'test-integration-';
const multisAvailable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let electronPids: Array<number> = [];

export type TestContext = {
dbCreationTimestampMs?: number;
};

export function getAppRootPath() {
if (isEmpty(process.env.SESSION_DESKTOP_ROOT)) {
throw new Error(
Expand All @@ -18,7 +22,7 @@ export function getAppRootPath() {
return process.env.SESSION_DESKTOP_ROOT as string;
}

const openElectronAppOnly = async (multi: string) => {
const openElectronAppOnly = async (multi: string, context?: TestContext) => {
process.env.MULTI = `${multi}`;
// using a v4 uuid, as timestamps to the ms are sometimes the same (when a bunch of workers are started)
const uniqueId = v4();
Expand All @@ -28,6 +32,22 @@ const openElectronAppOnly = async (multi: string) => {
process.env.LOCAL_DEVNET_SEED_URL = 'http://seed2.getsession.org:38157/';
// process.env.LOCAL_DEVNET_SEED_URL = 'http://sesh-net:1280'

// Inject custom env vars if provided
if (context?.dbCreationTimestampMs) {
process.env.DB_CREATION_TIMESTAMP_MS = String(
context.dbCreationTimestampMs,
);
const humanReadable = new Date(
context.dbCreationTimestampMs,
).toLocaleString('en-AU');
console.info(
` DB Creation Timestamp: ${process.env.DB_CREATION_TIMESTAMP_MS} (${humanReadable})`,
);
} else {
// Cleanup for tests without context
delete process.env.DB_CREATION_TIMESTAMP_MS;
}

console.info(` ${process.env.LOCAL_DEVNET_SEED_URL}`);
console.info(` NON CI RUN`);
console.info(' NODE_ENV', process.env.NODE_ENV);
Expand Down Expand Up @@ -66,8 +86,8 @@ const openElectronAppOnly = async (multi: string) => {

const logBrowserConsole = false;

const openAppAndWait = async (multi: string) => {
const electronApp = await openElectronAppOnly(multi);
const openAppAndWait = async (multi: string, context?: TestContext) => {
const electronApp = await openElectronAppOnly(multi, context);
// Get the first window that the app opens, wait if necessary.
const window = await electronApp.firstWindow();
window.on('console', (msg) => {
Expand All @@ -83,7 +103,7 @@ const openAppAndWait = async (multi: string) => {
return window;
};

export async function openApp(windowsToCreate: number) {
export async function openApp(windowsToCreate: number, context?: TestContext) {
if (windowsToCreate >= multisAvailable.length) {
throw new Error(`Do you really need ${multisAvailable.length} windows?!`);
}
Expand All @@ -96,7 +116,7 @@ export async function openApp(windowsToCreate: number) {
for (let index = 0; index < array.length; index++) {
const element = array[index];
// eslint-disable-next-line no-await-in-loop
const openedWindow = await openAppAndWait(`${element}`);
const openedWindow = await openAppAndWait(`${element}`, context);
toRet.push(openedWindow);
}
console.log(
Expand Down
49 changes: 33 additions & 16 deletions tests/automation/setup/sessionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { linkedDevice } from '../utilities/linked_device';
import { forceCloseAllWindows } from './closeWindows';
import { createGroup } from './create_group';
import { newUser } from './new_user';
import { openApp, resetTrackedElectronPids } from './open';
import { openApp, resetTrackedElectronPids, TestContext } from './open';

// This is not ideal, most of our test needs to open a specific number of windows and close them once the test is done or failed.
// This file contains a bunch of utility function to use to open those windows and clean them afterwards.
Expand Down Expand Up @@ -44,11 +44,11 @@ function sessionTest<T extends CountWindows, N extends Tuple<Page, T>>(
testName: string,
testCallback: (windows: N, testInfo: TestInfo) => Promise<void>,
count: T,
context?: TestContext,
) {
return test(testName, async ({}, testinfo) => {
resetTrackedElectronPids();
const windows = await openApp(count);

const windows = await openApp(count, context);
try {
if (windows.length !== count) {
throw new Error(
Expand All @@ -71,15 +71,17 @@ function sessionTest<T extends CountWindows, N extends Tuple<Page, T>>(
export function sessionTestOneWindow(
testName: string,
testCallback: (windows: Tuple<Page, 1>, testInfo: TestInfo) => Promise<void>,
context?: TestContext,
) {
return sessionTest(testName, testCallback, 1);
return sessionTest(testName, testCallback, 1, context);
}

export function sessionTestTwoWindows(
testName: string,
testCallback: ([windowA, windowB]: [Page, Page]) => Promise<void>,
context?: TestContext,
) {
return sessionTest(testName, testCallback, 2);
return sessionTest(testName, testCallback, 2, context);
}

export function sessionTestThreeWindows(
Expand All @@ -89,8 +91,9 @@ export function sessionTestThreeWindows(
Page,
Page,
]) => Promise<void>,
context?: TestContext,
) {
return sessionTest(testName, testCallback, 3);
return sessionTest(testName, testCallback, 3, context);
}

/**
Expand Down Expand Up @@ -121,7 +124,13 @@ function sessionTestGeneric<
links,
grouped,
waitForNetwork = true,
}: { links?: Links; grouped?: Grouped; waitForNetwork?: boolean },
context,
}: {
links?: Links;
grouped?: Grouped;
waitForNetwork?: boolean;
context?: TestContext;
},
testCallback: (
details: {
users: Tuple<User, UserCount>;
Expand All @@ -135,7 +144,7 @@ function sessionTestGeneric<
const userNames: Tuple<string, 4> = ['Alice', 'Bob', 'Charlie', 'Dracula'];

return test(testName, async ({}, testinfo) => {
const mainWindows = await openApp(userCount);
const mainWindows = await openApp(userCount, context);
const linkedWindows: Array<Page> = [];

try {
Expand Down Expand Up @@ -208,11 +217,12 @@ export function test_Alice_1W_no_network(
details: WithAlice & WithAliceWindow1,
testInfo: TestInfo,
) => Promise<void>,
context?: TestContext,
) {
return sessionTestGeneric(
testname,
1,
{ waitForNetwork: false },
{ waitForNetwork: false, context },
({ mainWindows, users }, testInfo) => {
return testCallback(
{
Expand All @@ -231,11 +241,12 @@ export function test_Alice_1W(
details: WithAlice & WithAliceWindow1,
testInfo: TestInfo,
) => Promise<void>,
context?: TestContext,
) {
return sessionTestGeneric(
testname,
1,
{ waitForNetwork: true },
{ waitForNetwork: true, context },
({ mainWindows, users }, testInfo) => {
return testCallback(
{
Expand All @@ -258,11 +269,12 @@ export function test_Alice_2W(
details: WithAlice & WithAliceWindow1 & WithAliceWindow2,
testInfo: TestInfo,
) => Promise<void>,
context?: TestContext,
) {
return sessionTestGeneric(
testname,
1,
{ links: [1] },
{ links: [1], context },
({ mainWindows, users, linkedWindows }, testInfo) => {
return testCallback(
{
Expand All @@ -287,11 +299,12 @@ export function test_Alice_1W_Bob_1W(
details: WithAlice & WithAliceWindow1 & WithBob & WithBobWindow1,
testInfo: TestInfo,
) => Promise<void>,
context?: TestContext,
) {
return sessionTestGeneric(
testname,
2,
{},
{ context },
({ mainWindows, users }, testInfo) => {
return testCallback(
{
Expand Down Expand Up @@ -321,11 +334,12 @@ export function test_Alice_2W_Bob_1W(
WithBobWindow1,
testInfo: TestInfo,
) => Promise<void>,
context?: TestContext,
) {
return sessionTestGeneric(
testname,
2,
{ links: [1] },
{ links: [1], context },
({ mainWindows, users, linkedWindows }, testInfo) => {
return testCallback(
{
Expand Down Expand Up @@ -359,11 +373,12 @@ export function test_group_Alice_1W_Bob_1W_Charlie_1W(
WithGroupCreated,
testInfo: TestInfo,
) => Promise<void>,
context?: TestContext,
) {
return sessionTestGeneric(
testname,
3,
{ grouped: [1, 2, 3] },
{ grouped: [1, 2, 3], context },
({ mainWindows, users, groupCreated }, testInfo) => {
return testCallback(
{
Expand Down Expand Up @@ -400,11 +415,12 @@ export function test_group_Alice_2W_Bob_1W_Charlie_1W(
WithGroupCreated,
testInfo: TestInfo,
) => Promise<void>,
context?: TestContext,
) {
return sessionTestGeneric(
testname,
3,
{ grouped: [1, 2, 3], links: [1] },
{ grouped: [1, 2, 3], links: [1], context },
({ mainWindows, users, groupCreated, linkedWindows }, testInfo) => {
return testCallback(
{
Expand Down Expand Up @@ -445,11 +461,12 @@ export function test_group_Alice_1W_Bob_1W_Charlie_1W_Dracula_1W(

testInfo: TestInfo,
) => Promise<void>,
context?: TestContext,
) {
return sessionTestGeneric(
testname,
4,
{ grouped: [1, 2, 3] },
{ grouped: [1, 2, 3], context },
({ mainWindows, users, groupCreated }, testInfo) => {
return testCallback(
{
Expand Down
Loading
Loading