add tests for gives to & from projects

This commit is contained in:
2024-11-29 10:42:58 -07:00
parent 8db7ac3f6f
commit d621828d53
11 changed files with 75 additions and 11 deletions

View File

@@ -25,6 +25,7 @@ test('Record something given', async ({ page }) => {
await page.getByRole('spinbutton').fill(randomNonZeroNumber.toString());
await page.getByRole('button', { name: 'Sign & Send' }).click();
await expect(page.getByText('That gift was recorded.')).toBeVisible();
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
// Refresh home view and check gift
await page.goto('./');

View File

@@ -38,6 +38,7 @@ test('Record 9 new gifts', async ({ page }) => {
await page.getByRole('spinbutton').fill(finalNumbers[i].toString());
await page.getByRole('button', { name: 'Sign & Send' }).click();
await expect(page.getByText('That gift was recorded.')).toBeVisible();
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
// Refresh home view and check gift
await page.goto('./');

View File

@@ -28,7 +28,7 @@ test('Record item given from image-share', async ({ page }) => {
await page.getByRole('spinbutton').fill('2');
await page.getByRole('button', { name: 'Sign & Send' }).click();
await expect(page.getByText('That gift was recorded.')).toBeVisible();
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
// Refresh home view and check gift
await page.goto('./');

View File

@@ -0,0 +1,50 @@
import { test, expect, Page } from '@playwright/test';
import { importUser } from './testUtils';
async function testProjectGive(page: Page, selector: string) {
// Generate a random string of a few characters
const randomString = Math.random().toString(36).substring(2, 6);
// Generate a random non-zero single-digit number
const randomNonZeroNumber = Math.floor(Math.random() * 99) + 1;
// Standard title prefix
const standardTitle = 'Gift ';
// Combine title prefix with the random string
const finalTitle = standardTitle + randomString;
// find a project and enter a give to it and see that it shows
await importUser(page, '00');
await page.goto('./discover');
await page.getByTestId('closeOnboardingAndFinish').click();
await page.locator('ul#listDiscoverResults li:first-child a').click()
// wait for the project page to load
await page.waitForLoadState('networkidle');
// click the give button, inside the first div
await page.getByTestId(selector).locator('div:first-child div button').click();
await page.getByPlaceholder('What was given').fill(finalTitle);
await page.getByRole('spinbutton').fill(randomNonZeroNumber.toString());
await page.getByRole('button', { name: 'Sign & Send' }).click();
await expect(page.getByText('That gift was recorded.')).toBeVisible();
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
// refresh the page
await page.reload();
// check that the give is in the list
await page
.getByTestId(selector)
.locator('div ul li:first-child')
.filter({ hasText: finalTitle })
.isVisible();
}
test('Record a give to a project', async ({ page }) => {
await testProjectGive(page, 'gives-to');
});
test('Record a give from a project', async ({ page }) => {
await testProjectGive(page, 'gives-from');
});

View File

@@ -87,6 +87,7 @@ test('Add contact, record gift, confirm gift', async ({ page }) => {
await page.getByRole('button', { name: 'Confirm' }).click();
await page.getByRole('button', { name: 'Yes' }).click();
await expect(page.getByText('Confirmation submitted.')).toBeVisible();
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
// Refresh claim page, Confirm button should throw an alert because they already confirmed
await page.reload();
@@ -112,7 +113,7 @@ test('Without being registered, add contacts without registration', async ({ pag
});
test('Add contact, copy details, delete, and import various ways', async ({ page, context }) => {
test('Add contact, copy details, delete, and import from paste & from file', async ({ page, context }) => {
await importUser(page, '00');
// Add new contact
@@ -179,7 +180,7 @@ test('Add contact, copy details, delete, and import various ways', async ({ page
// check that there are more contacts
await expect(page.getByTestId('contactListItem')).toHaveCount(2);
// Import via the file backup-import
// Import via the file backup-import, with both new and existing contacts
await page.goto('./account');
await page.getByRole('heading', { name: 'Advanced' }).click();
const fileSelect = await page.locator('input[type="file"]')

View File

@@ -25,6 +25,7 @@ test('Record an offer', async ({ page }) => {
expect(page.getByRole('button', { name: 'Sign & Send' }));
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
// go to the offer and check the values
await page.goto('./projects');
@@ -57,6 +58,7 @@ test('Record an offer', async ({ page }) => {
await amount.fill(String(randomNonZeroNumber + 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
// go to the offer claim again and check the updated values
await page.goto('./projects');
@@ -107,4 +109,5 @@ test('Affirm delivery of an offer', async ({ page }) => {
await page.getByRole('spinbutton').fill('2');
await page.getByRole('button', { name: 'Sign & Send' }).click();
await expect(page.getByText('That gift was recorded.')).toBeVisible();
await page.locator('div[role="alert"] button > svg.fa-xmark').click(); // dismiss info alert
});

View File

@@ -1,8 +1,9 @@
import { expect, Page } from '@playwright/test';
// Import the seed and switch to the user based on the ID.
// '01' -> 111
// otherwise -> 000
// '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;