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');
|
||||
|
||||
Reference in New Issue
Block a user