forked from trent_larson/crowd-funder-for-time-pwa
refactor invite link & add test
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { deleteContact, generateEthrUser, importUser } from './testUtils';
|
||||
import { deleteContact, generateAndRegisterEthrUser, importUser } from './testUtils';
|
||||
|
||||
test('Check activity feed', async ({ page }) => {
|
||||
// Load app homepage
|
||||
@@ -112,12 +112,12 @@ test('Confirm test API setting (may fail if you are running your own Time Safari
|
||||
|
||||
test('Check User 0 can register a random person', async ({ page }) => {
|
||||
await importUser(page, '00');
|
||||
const newDid = await generateEthrUser(page);
|
||||
const newDid = await generateAndRegisterEthrUser(page);
|
||||
expect(newDid).toContain('did:ethr:');
|
||||
|
||||
await page.goto('./');
|
||||
await page.getByRole('heading', { name: 'Unnamed/Unknown' }).click();
|
||||
await page.getByPlaceholder('What was given').fill('Access!');
|
||||
await page.getByPlaceholder('What was given').fill('Gave me access!');
|
||||
await page.getByRole('button', { name: 'Sign & Send' }).click();
|
||||
await expect(page.getByText('That gift was recorded.')).toBeVisible();
|
||||
// now ensure that alert goes away
|
||||
|
||||
32
test-playwright/05-invite.spec.ts
Normal file
32
test-playwright/05-invite.spec.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { deleteContact, generateNewEthrUser, generateRandomString, importUser, switchToUser } from './testUtils';
|
||||
|
||||
test('Check User 0 can invite someone', async ({ page }) => {
|
||||
const newDid = await generateNewEthrUser(page);
|
||||
|
||||
await importUser(page, '00');
|
||||
await page.goto('./invite-one');
|
||||
await page.locator('button > svg.fa-plus').click();
|
||||
const neighborNum = await generateRandomString(5);
|
||||
await page.getByPlaceholder('Notes', { exact: true }).fill(`Neighbor ${neighborNum}`);
|
||||
// get the expiration date input and set to 14 days from now
|
||||
const expirationDate = new Date(Date.now() + 14 * 24 * 60 * 60 * 1000);
|
||||
await page.locator('input[type="date"]').fill(expirationDate.toISOString().split('T')[0]);
|
||||
await page.locator('button:has-text("Save")').click();
|
||||
await expect(page.locator('div[role="alert"] button:has-text("Yes")')).toBeHidden();
|
||||
|
||||
// check that the invite is in the list
|
||||
const newInviteLine = await page.locator(`td:has-text("Neighbor ${neighborNum}")`);
|
||||
await expect(newInviteLine).toBeVisible();
|
||||
// retrieve the link from the title
|
||||
const inviteLink = await newInviteLine.getAttribute('data-testId');
|
||||
await expect(inviteLink).not.toBeNull();
|
||||
|
||||
// become the new user and accept the invite
|
||||
await switchToUser(page, newDid);
|
||||
await page.goto(inviteLink as string);
|
||||
await page.getByPlaceholder('Name', { exact: true }).fill(`My pal User #0`);
|
||||
await page.locator('button:has-text("Save")').click();
|
||||
await expect(page.locator('button:has-text("Save")')).toBeHidden();
|
||||
await expect(page.locator(`li:has-text("My pal User #0")`)).toBeVisible();
|
||||
});
|
||||
@@ -49,7 +49,7 @@ test('Create new project, then search for it', async ({ page }) => {
|
||||
// Create new project
|
||||
await page.goto('./projects');
|
||||
await page.getByRole('link', { name: 'Projects', exact: true }).click();
|
||||
await page.getByRole('button').click();
|
||||
await page.locator('button > svg.fa-plus').click();
|
||||
await page.getByPlaceholder('Idea Name').fill(finalTitle);
|
||||
await page.getByPlaceholder('Description').fill(finalDescription);
|
||||
await page.getByPlaceholder('Website').fill(standardWebsite);
|
||||
|
||||
@@ -34,10 +34,15 @@ export async function importUser(page: Page, id?: string): Promise<string> {
|
||||
|
||||
// This is to switch to someone already in the identity table. It doesn't include registration.
|
||||
export async function switchToUser(page: Page, did: string): Promise<void> {
|
||||
await page.goto('./account');
|
||||
await page.getByRole('heading', { name: 'Advanced' }).click();
|
||||
await page.getByRole('link', { name: 'Switch Identifier' }).click();
|
||||
await page.getByRole('code', { name: did }).click();
|
||||
// await page.goto('./account');
|
||||
// await page.getByRole('heading', { name: 'Advanced' }).click();
|
||||
// await page.getByRole('link', { name: 'Switch Identifier' }).click();
|
||||
await page.goto('./identity-switcher');
|
||||
const didElem = await page.locator(`code:has-text("${did}")`);
|
||||
await didElem.isVisible();
|
||||
await didElem.click();
|
||||
// wait for the switch to happen and the account page to fully load
|
||||
await page.getByTestId('didWrapper').locator('code:has-text("did:")');
|
||||
}
|
||||
|
||||
function createContactName(did: string): string {
|
||||
@@ -56,17 +61,21 @@ export async function deleteContact(page: Page, did: string): Promise<void> {
|
||||
await expect(page.locator('div[role="alert"] button:has-text("Yes")')).toBeHidden();
|
||||
}
|
||||
|
||||
// Generate a new random user and register them.
|
||||
// Note that this makes 000 the active user. Use switchToUser to switch to this DID.
|
||||
export async function generateEthrUser(page: Page): Promise<string> {
|
||||
export async function generateNewEthrUser(page: Page): Promise<string> {
|
||||
await page.goto('./start');
|
||||
await page.getByTestId('newSeed').click();
|
||||
await expect(page.locator('span:has-text("Created")')).toBeVisible();
|
||||
|
||||
await page.goto('./account');
|
||||
// wait until the DID shows on the page in the 'did' element
|
||||
const didElem = await page.getByTestId('didWrapper').locator('code:has-text("did:")');
|
||||
const newDid = await didElem.innerText();
|
||||
return newDid;
|
||||
}
|
||||
|
||||
// Generate a new random user and register them.
|
||||
// Note that this makes 000 the active user. Use switchToUser to switch to this DID.
|
||||
export async function generateAndRegisterEthrUser(page: Page): Promise<string> {
|
||||
const newDid = await generateNewEthrUser(page);
|
||||
|
||||
await importUser(page, '000'); // switch to user 000
|
||||
|
||||
|
||||
Reference in New Issue
Block a user