forked from jsnbuchanan/crowd-funder-for-time-pwa
refactor: extract test user data and improve "New offers" test flow
- Extract test user data (seed phrases, DIDs, usernames) from importUser into separate getTestUserData function
- Refactor importUser to use getTestUserData internally, maintaining backward compatibility
- Update "New offers for another user" test to use new getTestUserData function
- Replace hardcoded seed phrase with programmatic retrieval using getTestUserData('00')
- Add proper TypeScript type annotations to array functions in testUtils
- Improve test maintainability by centralizing test user data management
This allows tests to access user data without executing import flow, providing more flexibility for test scenarios.
This commit is contained in:
@@ -1,15 +1,48 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { importUser, generateNewEthrUser, switchToUser } from './testUtils';
|
||||
import { switchToUser, getTestUserData } from './testUtils';
|
||||
|
||||
test('New offers for another user', async ({ page }) => {
|
||||
const user01Did = await generateNewEthrUser(page);
|
||||
await page.goto('./');
|
||||
|
||||
// Get the auto-created DID from the HomeView
|
||||
await page.waitForLoadState('networkidle');
|
||||
const autoCreatedDid = await page.getAttribute('#Content', 'data-active-did');
|
||||
console.log("[New offers for another user] Auto-created DID:", autoCreatedDid);
|
||||
|
||||
if (!autoCreatedDid) {
|
||||
throw new Error('Auto-created DID not found in HomeView');
|
||||
}
|
||||
|
||||
await page.getByTestId('closeOnboardingAndFinish').click();
|
||||
await expect(page.getByTestId('newDirectOffersActivityNumber')).toBeHidden();
|
||||
|
||||
await importUser(page, '00');
|
||||
// Navigate to AccountViewView to use the Identity Switcher
|
||||
await page.goto('./account');
|
||||
|
||||
// Click "Show Advanced Settings" to reveal the identity switcher
|
||||
await page.getByTestId('advancedSettings').click();
|
||||
|
||||
// Use the identity switcher to add User Zero
|
||||
await page.locator('#switch-identity-link').click();
|
||||
await page.locator('#start-link').click();
|
||||
|
||||
// Select "You have a seed" option
|
||||
await page.getByText('You have a seed').click();
|
||||
|
||||
// Get User Zero's seed phrase using the new method
|
||||
const userZeroData = getTestUserData('00');
|
||||
|
||||
// Enter User Zero's seed phrase
|
||||
await page.getByPlaceholder('Seed Phrase').fill(userZeroData.seedPhrase);
|
||||
|
||||
await page.getByRole('button', { name: 'Import' }).click();
|
||||
|
||||
// Wait for import to complete
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
// As User Zero, add the auto-created DID as a contact
|
||||
await page.goto('./contacts');
|
||||
await page.getByPlaceholder('URL or DID, Name, Public Key').fill(user01Did + ', A Friend');
|
||||
await page.getByPlaceholder('URL or DID, Name, Public Key').fill(autoCreatedDid + ', A Friend');
|
||||
await expect(page.locator('button > svg.fa-plus')).toBeVisible();
|
||||
await page.locator('button > svg.fa-plus').click();
|
||||
await page.locator('div[role="alert"] button:has-text("No")').click(); // don't register
|
||||
@@ -41,8 +74,8 @@ test('New offers for another user', async ({ page }) => {
|
||||
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
|
||||
await expect(page.locator('div[role="alert"] button > svg.fa-xmark')).toBeHidden(); // ensure alert is gone
|
||||
|
||||
// as user 1, go to the home page and check that two offers are shown as new
|
||||
await switchToUser(page, user01Did);
|
||||
// Switch back to the auto-created DID (the "another user") to see the offers
|
||||
await switchToUser(page, autoCreatedDid);
|
||||
await page.goto('./');
|
||||
let offerNumElem = page.getByTestId('newDirectOffersActivityNumber');
|
||||
await expect(offerNumElem).toHaveText('2');
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
import { expect, Page } from '@playwright/test';
|
||||
|
||||
// Import the seed and switch to the user based on the ID.
|
||||
// Get test user data based on the ID.
|
||||
// '01' -> user 111
|
||||
// otherwise -> user 000
|
||||
// (... which is a weird convention but I haven't taken the time to change it)
|
||||
export async function importUser(page: Page, id?: string): Promise<string> {
|
||||
let seedPhrase, userName, did;
|
||||
|
||||
// Set seed phrase and DID based on user ID
|
||||
export function getTestUserData(id?: string): { seedPhrase: string, userName: string, did: string } {
|
||||
switch(id) {
|
||||
case '01':
|
||||
seedPhrase = 'island fever beef wine urban aim vacant quit afford total poem flame service calm better adult neither color gaze forum month sister imitate excite';
|
||||
userName = 'User One';
|
||||
did = 'did:ethr:0x111d15564f824D56C7a07b913aA7aDd03382aA39';
|
||||
break;
|
||||
return {
|
||||
seedPhrase: 'island fever beef wine urban aim vacant quit afford total poem flame service calm better adult neither color gaze forum month sister imitate excite',
|
||||
userName: 'User One',
|
||||
did: 'did:ethr:0x111d15564f824D56C7a07b913aA7aDd03382aA39'
|
||||
};
|
||||
default: // to user 00
|
||||
seedPhrase = 'rigid shrug mobile smart veteran half all pond toilet brave review universe ship congress found yard skate elite apology jar uniform subway slender luggage';
|
||||
userName = 'User Zero';
|
||||
did = 'did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F';
|
||||
return {
|
||||
seedPhrase: 'rigid shrug mobile smart veteran half all pond toilet brave review universe ship congress found yard skate elite apology jar uniform subway slender luggage',
|
||||
userName: 'User Zero',
|
||||
did: 'did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Import the seed and switch to the user based on the ID.
|
||||
export async function importUser(page: Page, id?: string): Promise<string> {
|
||||
const userData = getTestUserData(id);
|
||||
const { seedPhrase, userName, did } = userData;
|
||||
|
||||
// Import ID
|
||||
await page.goto('./start');
|
||||
@@ -109,7 +115,7 @@ export async function generateRandomString(length: number): Promise<string> {
|
||||
|
||||
// Function to create an array of unique strings
|
||||
export async function createUniqueStringsArray(count: number): Promise<string[]> {
|
||||
const stringsArray = [];
|
||||
const stringsArray: string[] = [];
|
||||
const stringLength = 16;
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
@@ -122,7 +128,7 @@ export async function createUniqueStringsArray(count: number): Promise<string[]>
|
||||
|
||||
// Function to create an array of two-digit non-zero numbers
|
||||
export async function createRandomNumbersArray(count: number): Promise<number[]> {
|
||||
const numbersArray = [];
|
||||
const numbersArray: number[] = [];
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
let randomNumber = Math.floor(Math.random() * 99) + 1;
|
||||
|
||||
Reference in New Issue
Block a user