chore: update integration tests to use generic open and close function
parent
a551d4d7cc
commit
52291ff524
@ -1,70 +1,63 @@
|
||||
import { _electron, test } from '@playwright/test';
|
||||
import { beforeAllClean } from './setup/beforeEach';
|
||||
import { sendNewMessage } from './utilities/send_message';
|
||||
import { logIn } from './setup/log_in';
|
||||
import { userA, userB, userC, userD, userE } from './setup/test_user';
|
||||
import { openApp } from './setup/open';
|
||||
// FIXME enable this test again once we fixed it
|
||||
// sessionTestFiveWindows(
|
||||
// 'Group upkeep - should be skipped',
|
||||
// async ([windowA, windowB, windowC, windowD, windowE]) => {
|
||||
// await Promise.all([
|
||||
// logIn(windowA, userA.recoveryPhrase),
|
||||
// logIn(windowB, userB.recoveryPhrase),
|
||||
// logIn(windowC, userC.recoveryPhrase),
|
||||
// logIn(windowD, userD.recoveryPhrase),
|
||||
// logIn(windowE, userE.recoveryPhrase),
|
||||
// ]);
|
||||
// // Send message from test users to all of it's contacts to maintain contact status
|
||||
|
||||
test.beforeEach(beforeAllClean);
|
||||
|
||||
test.skip('Group upkeep', async () => {
|
||||
const [windowA, windowB, windowC, windowD, windowE] = await openApp(5);
|
||||
|
||||
await Promise.all([
|
||||
logIn(windowA, userA.recoveryPhrase),
|
||||
logIn(windowB, userB.recoveryPhrase),
|
||||
logIn(windowC, userC.recoveryPhrase),
|
||||
logIn(windowD, userD.recoveryPhrase),
|
||||
logIn(windowE, userE.recoveryPhrase),
|
||||
]);
|
||||
// Send message from test users to all of it's contacts to maintain contact status
|
||||
|
||||
// Send message from user A to Whale(TC1)
|
||||
await sendNewMessage(
|
||||
windowA,
|
||||
userB.sessionid,
|
||||
`${userA.userName} -> ${userB.userName}: ${Date.now()}`
|
||||
);
|
||||
// Send message from Whale to user A
|
||||
await sendNewMessage(
|
||||
windowB,
|
||||
userA.sessionid,
|
||||
`${userB.userName} -> ${userA.userName} : ${Date.now()}`
|
||||
);
|
||||
// Send message from user A to Dragon(TC2)
|
||||
await sendNewMessage(
|
||||
windowA,
|
||||
userC.sessionid,
|
||||
`${userA.userName} -> ${userC.userName}: ${Date.now()}`
|
||||
);
|
||||
// Send message from Dragon to user A
|
||||
await sendNewMessage(
|
||||
windowC,
|
||||
userA.sessionid,
|
||||
`${userC.userName} -> ${userA.userName} : ${Date.now()}`
|
||||
);
|
||||
// Send message from user A to Fish(TC3)
|
||||
await sendNewMessage(
|
||||
windowA,
|
||||
userD.sessionid,
|
||||
`${userA.userName} -> ${userD.userName}: ${Date.now()}`
|
||||
);
|
||||
// Send message from Fish to user A
|
||||
await sendNewMessage(
|
||||
windowD,
|
||||
userA.sessionid,
|
||||
`${userD.userName} -> ${userA.userName} : ${Date.now()}`
|
||||
);
|
||||
// Send message from user A to Gopher(TC4)
|
||||
await sendNewMessage(
|
||||
windowA,
|
||||
userE.sessionid,
|
||||
`${userA.userName} -> ${userD.userName}: ${Date.now()}`
|
||||
);
|
||||
// Send message from Gopher to user A
|
||||
await sendNewMessage(
|
||||
windowE,
|
||||
userA.sessionid,
|
||||
`${userD.userName} -> ${userA.userName} : ${Date.now()}`
|
||||
);
|
||||
});
|
||||
// // Send message from user A to Whale(TC1)
|
||||
// await sendNewMessage(
|
||||
// windowA,
|
||||
// userB.sessionid,
|
||||
// `${userA.userName} -> ${userB.userName}: ${Date.now()}`
|
||||
// );
|
||||
// // Send message from Whale to user A
|
||||
// await sendNewMessage(
|
||||
// windowB,
|
||||
// userA.sessionid,
|
||||
// `${userB.userName} -> ${userA.userName} : ${Date.now()}`
|
||||
// );
|
||||
// // Send message from user A to Dragon(TC2)
|
||||
// await sendNewMessage(
|
||||
// windowA,
|
||||
// userC.sessionid,
|
||||
// `${userA.userName} -> ${userC.userName}: ${Date.now()}`
|
||||
// );
|
||||
// // Send message from Dragon to user A
|
||||
// await sendNewMessage(
|
||||
// windowC,
|
||||
// userA.sessionid,
|
||||
// `${userC.userName} -> ${userA.userName} : ${Date.now()}`
|
||||
// );
|
||||
// // Send message from user A to Fish(TC3)
|
||||
// await sendNewMessage(
|
||||
// windowA,
|
||||
// userD.sessionid,
|
||||
// `${userA.userName} -> ${userD.userName}: ${Date.now()}`
|
||||
// );
|
||||
// // Send message from Fish to user A
|
||||
// await sendNewMessage(
|
||||
// windowD,
|
||||
// userA.sessionid,
|
||||
// `${userD.userName} -> ${userA.userName} : ${Date.now()}`
|
||||
// );
|
||||
// // Send message from user A to Gopher(TC4)
|
||||
// await sendNewMessage(
|
||||
// windowA,
|
||||
// userE.sessionid,
|
||||
// `${userA.userName} -> ${userD.userName}: ${Date.now()}`
|
||||
// );
|
||||
// // Send message from Gopher to user A
|
||||
// await sendNewMessage(
|
||||
// windowE,
|
||||
// userA.sessionid,
|
||||
// `${userD.userName} -> ${userA.userName} : ${Date.now()}`
|
||||
// );
|
||||
// }
|
||||
// );
|
||||
|
@ -0,0 +1,81 @@
|
||||
import { Page, test } from '@playwright/test';
|
||||
import { beforeAllClean, forceCloseAllWindows } from './beforeEach';
|
||||
import { openApp } 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.
|
||||
// Note: those function only keep track (and close) the windows they open. If you open a new window or need to close and reopen an existing one, this won't take of it.
|
||||
|
||||
type Tuple<T, N extends number> = N extends N
|
||||
? number extends N
|
||||
? T[]
|
||||
: _TupleOf<T, N, []>
|
||||
: never;
|
||||
type _TupleOf<T, N extends number, R extends unknown[]> = R['length'] extends N
|
||||
? R
|
||||
: _TupleOf<T, N, [T, ...R]>;
|
||||
|
||||
type CountWindows = 1 | 2 | 3 | 4 | 5;
|
||||
|
||||
async function sessionTest<T extends CountWindows, N extends Tuple<Page, T>>(
|
||||
testName: string,
|
||||
testCallback: (windows: N) => Promise<void>,
|
||||
count: T
|
||||
) {
|
||||
return test(testName, async () => {
|
||||
beforeAllClean();
|
||||
const windows = await openApp(count);
|
||||
|
||||
try {
|
||||
if (windows.length !== count) {
|
||||
throw new Error(`openApp should have opened ${count} windows but did not.`);
|
||||
}
|
||||
await testCallback(windows as N);
|
||||
} catch (e) {
|
||||
throw e;
|
||||
} finally {
|
||||
try {
|
||||
await forceCloseAllWindows(windows);
|
||||
} catch (e) {
|
||||
console.error(`forceCloseAllWindows of ${testName} failed with: `, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function sessionTestOneWindow(
|
||||
testName: string,
|
||||
testCallback: (windows: Tuple<Page, 1>) => Promise<void>
|
||||
) {
|
||||
return sessionTest(testName, testCallback, 1);
|
||||
}
|
||||
|
||||
export async function sessionTestTwoWindows(
|
||||
testName: string,
|
||||
testCallback: ([windowA, windowB]: [Page, Page]) => Promise<void>
|
||||
) {
|
||||
return sessionTest(testName, testCallback, 2);
|
||||
}
|
||||
|
||||
export async function sessionTestThreeWindows(
|
||||
testName: string,
|
||||
testCallback: ([windowA, windowB, windowC]: [Page, Page, Page]) => Promise<void>
|
||||
) {
|
||||
return sessionTest(testName, testCallback, 3);
|
||||
}
|
||||
|
||||
export async function sessionTestFourWindows(
|
||||
testName: string,
|
||||
testCallback: ([windowA, windowB, windowC, windowD]: [Page, Page, Page, Page]) => Promise<void>
|
||||
) {
|
||||
return sessionTest(testName, testCallback, 4);
|
||||
}
|
||||
|
||||
export async function sessionTestFiveWindows(
|
||||
testName: string,
|
||||
testCallback: ([windowA, windowB, windowC, windowD]: [Page, Page, Page, Page, Page]) => Promise<
|
||||
void
|
||||
>
|
||||
) {
|
||||
return sessionTest(testName, testCallback, 5);
|
||||
}
|
@ -1,11 +1,6 @@
|
||||
import { test } from '@playwright/test';
|
||||
import { beforeAllClean } from './setup/beforeEach';
|
||||
import { openApp } from './setup/open';
|
||||
import { clickOnMatchingText } from './utilities/utils';
|
||||
import { sessionTestOneWindow } from './setup/sessionTest';
|
||||
|
||||
test.beforeEach(beforeAllClean);
|
||||
|
||||
test('Tiny test', async () => {
|
||||
const [windowA] = await openApp(1);
|
||||
sessionTestOneWindow('Tiny test', async ([windowA]) => {
|
||||
await clickOnMatchingText(windowA, 'Create Session ID');
|
||||
});
|
||||
|
@ -1 +0,0 @@
|
||||
//
|
Loading…
Reference in New Issue