forked from jsnbuchanan/crowd-funder-for-time-pwa
fix: clean up "register random person" test
- Remove redundant "import User Zero" action - Remove out-of-scope actions from test (sending a gift to an unrelated entity, deleting the contact) - Update imports based on changes
This commit is contained in:
@@ -69,8 +69,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { test, expect } from '@playwright/test';
|
import { test, expect } from '@playwright/test';
|
||||||
import { UNNAMED_ENTITY_NAME } from '../src/constants/entities';
|
import { createContactName, generateNewEthrUser, importUser } from './testUtils';
|
||||||
import { deleteContact, generateAndRegisterEthrUser, importUser } from './testUtils';
|
|
||||||
import { NOTIFY_CONTACT_INVALID_DID } from '../src/constants/notifications';
|
import { NOTIFY_CONTACT_INVALID_DID } from '../src/constants/notifications';
|
||||||
|
|
||||||
test('Check activity feed - check that server is running', async ({ page }) => {
|
test('Check activity feed - check that server is running', async ({ page }) => {
|
||||||
@@ -185,35 +184,20 @@ test('Check invalid DID shows error and redirects', async ({ page }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Check User 0 can register a random person', async ({ page }) => {
|
test('Check User 0 can register a random person', async ({ page }) => {
|
||||||
await importUser(page, '00');
|
const newDid = await generateNewEthrUser(page); // generate a new user
|
||||||
const newDid = await generateAndRegisterEthrUser(page);
|
|
||||||
expect(newDid).toContain('did:ethr:');
|
|
||||||
|
|
||||||
await page.goto('./');
|
await importUser(page, "00"); // switch to User Zero
|
||||||
await page.getByTestId('closeOnboardingAndFinish').click();
|
|
||||||
await page.getByRole('button', { name: 'Person' }).click();
|
|
||||||
await page.getByRole('listitem').filter({ hasText: UNNAMED_ENTITY_NAME }).locator('svg').click();
|
|
||||||
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
|
|
||||||
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss alert
|
|
||||||
await expect(page.getByText('That gift was recorded.')).toBeHidden();
|
|
||||||
|
|
||||||
// now delete the contact to test that pages still do reasonable things
|
// As User Zero, add the new user as a contact
|
||||||
await deleteContact(page, newDid);
|
await page.goto('./contacts');
|
||||||
// go the activity page for this new person
|
const contactName = createContactName(newDid);
|
||||||
await page.goto('./did/' + encodeURIComponent(newDid));
|
await page.getByPlaceholder('URL or DID, Name, Public Key').fill(`${newDid}, ${contactName}`);
|
||||||
// maybe replace by: const popupPromise = page.waitForEvent('popup');
|
await expect(page.locator('button > svg.fa-plus')).toBeVisible();
|
||||||
let error;
|
await page.locator('button > svg.fa-plus').click();
|
||||||
try {
|
await expect(page.locator('div[role="alert"] h4:has-text("Success")')).toBeVisible(); // wait for info alert to be visible…
|
||||||
await page.waitForSelector('div[role="alert"]', { timeout: 2000 });
|
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // …and dismiss it
|
||||||
error = new Error('Error alert should not show.');
|
await expect(page.locator('div[role="alert"] button > svg.fa-xmark')).toBeHidden(); // ensure alert is gone
|
||||||
} catch (error) {
|
await page.locator('div[role="alert"] button:text-is("Yes")').click(); // Register new contact
|
||||||
// success
|
await page.locator('div[role="alert"] button:text-is("No, Not Now")').click(); // Dismiss export data prompt
|
||||||
} finally {
|
await expect(page.locator("li", { hasText: contactName })).toBeVisible();
|
||||||
if (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ export async function switchToUser(page: Page, did: string): Promise<void> {
|
|||||||
await page.getByTestId("didWrapper").locator('code:has-text("did:")');
|
await page.getByTestId("didWrapper").locator('code:has-text("did:")');
|
||||||
}
|
}
|
||||||
|
|
||||||
function createContactName(did: string): string {
|
export function createContactName(did: string): string {
|
||||||
return "User " + did.slice(11, 14);
|
return "User " + did.slice(11, 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,30 +144,6 @@ export async function generateNewEthrUser(page: Page): Promise<string> {
|
|||||||
return newDid;
|
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
|
|
||||||
|
|
||||||
await page.goto("./contacts");
|
|
||||||
const contactName = createContactName(newDid);
|
|
||||||
await page
|
|
||||||
.getByPlaceholder("URL or DID, Name, Public Key")
|
|
||||||
.fill(`${newDid}, ${contactName}`);
|
|
||||||
await page.locator("button > svg.fa-plus").click();
|
|
||||||
// register them
|
|
||||||
await page.locator('div[role="alert"] button:text-is("Yes")').click();
|
|
||||||
// wait for it to disappear because the next steps may depend on alerts being gone
|
|
||||||
await expect(
|
|
||||||
page.locator('div[role="alert"] button:text-is("Yes")')
|
|
||||||
).toBeHidden();
|
|
||||||
await expect(page.locator("li", { hasText: contactName })).toBeVisible();
|
|
||||||
|
|
||||||
return newDid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to generate a random string of specified length
|
// Function to generate a random string of specified length
|
||||||
export async function generateRandomString(length: number): Promise<string> {
|
export async function generateRandomString(length: number): Promise<string> {
|
||||||
return Math.random()
|
return Math.random()
|
||||||
|
|||||||
Reference in New Issue
Block a user