forked from jsnbuchanan/crowd-funder-for-time-pwa
- 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.
117 lines
5.7 KiB
TypeScript
117 lines
5.7 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { switchToUser, getTestUserData } from './testUtils';
|
|
|
|
test('New offers for another user', async ({ 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();
|
|
|
|
// 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(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
|
|
await expect(page.locator('div[role="alert"] span:has-text("Success")')).toBeVisible();
|
|
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
|
|
|
|
// show buttons to make offers directly to people
|
|
await page.getByRole('button').filter({ hasText: /See Actions/i }).click();
|
|
|
|
// make an offer directly to user 1
|
|
// Generate a random string of 3 characters, skipping the "0." at the beginning
|
|
const randomString1 = Math.random().toString(36).substring(2, 5);
|
|
await page.getByTestId('offerButton').click();
|
|
await page.getByTestId('inputDescription').fill(`help of ${randomString1} from #000`);
|
|
await page.getByTestId('inputOfferAmount').fill('1');
|
|
await page.getByRole('button', { name: 'Sign & Send' }).click();
|
|
await expect(page.getByText('That offer was recorded.')).toBeVisible();
|
|
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
|
|
|
|
// make another offer to user 1
|
|
const randomString2 = Math.random().toString(36).substring(2, 5);
|
|
await page.getByTestId('offerButton').click();
|
|
await page.getByTestId('inputDescription').fill(`help of ${randomString2} from #000`);
|
|
await page.getByTestId('inputOfferAmount').fill('3');
|
|
await page.getByRole('button', { name: 'Sign & Send' }).click();
|
|
await expect(page.getByText('That offer was recorded.')).toBeVisible();
|
|
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
|
|
|
|
// 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');
|
|
|
|
// click on the number of new offers to go to the list page
|
|
await offerNumElem.click();
|
|
|
|
await expect(page.getByText('New Offers To You', { exact: true })).toBeVisible();
|
|
await page.getByTestId('showOffersToUser').locator('div > svg.fa-chevron-right').click();
|
|
// note that they show in reverse chronologicalorder
|
|
await expect(page.getByText(`help of ${randomString2} from #000`)).toBeVisible();
|
|
await expect(page.getByText(`help of ${randomString1} from #000`)).toBeVisible();
|
|
|
|
// click on the latest offer to keep it as "unread"
|
|
await page.hover(`li:has-text("help of ${randomString2} from #000")`);
|
|
// await page.locator('li').filter({ hasText: `help of ${randomString2} from #000` }).click();
|
|
// await page.locator('div').filter({ hasText: /keep all above/ }).click();
|
|
// now find the "Click to keep all above as new offers" after that list item and click it
|
|
const liElem = page.locator('li').filter({ hasText: `help of ${randomString2} from #000` });
|
|
await liElem.hover();
|
|
const keepAboveAsNew = await liElem.locator('div').filter({ hasText: /keep all above/ });
|
|
|
|
await keepAboveAsNew.click();
|
|
|
|
// now see that only one offer is shown as new
|
|
await page.goto('./');
|
|
offerNumElem = page.getByTestId('newDirectOffersActivityNumber');
|
|
await expect(offerNumElem).toHaveText('1');
|
|
await offerNumElem.click();
|
|
await expect(page.getByText('New Offer To You', { exact: true })).toBeVisible();
|
|
await page.getByTestId('showOffersToUser').locator('div > svg.fa-chevron-right').click();
|
|
|
|
// now see that no offers are shown as new
|
|
await page.goto('./');
|
|
// wait until the list with ID listLatestActivity has at least one visible item
|
|
await page.locator('#listLatestActivity li').first().waitFor({ state: 'visible' });
|
|
await expect(page.getByTestId('newDirectOffersActivityNumber')).toBeHidden();
|
|
});
|