Compare commits

...

15 Commits

Author SHA1 Message Date
Jose Olarte III 03a3964cbd Merge branch 'master' into test-playwright 3 months ago
Trent Larson acf04792be change tests assuming result will be at top 3 months ago
Jose Olarte III 3262f0ee64 Improved create project test 3 months ago
Jose Olarte III 69473a826f Removed test.slow() 3 months ago
Jose Olarte III 51eb45353e Moved common functions to testUtils 3 months ago
Jose Olarte III b1875b5812 Remove unneeded timeouts 3 months ago
Jose Olarte III bd27d8a10f Merge branch 'master' into test-playwright 3 months ago
Jose Olarte III c076ce5b44 Remove PWA test 3 months ago
Jose Olarte III 915d51dc2f In-progress: PWA install test 3 months ago
Jose Olarte III b1d61251dc Merge branch 'master' into test-playwright 3 months ago
Jose Olarte III a9aeeeb51e Playwright: Record 10 gives 3 months ago
Jose Olarte III d679d0c804 Merge branch 'master' into test-playwright 3 months ago
Jose Olarte III c4a8026276 DONE: create 10 projects 4 months ago
Jose Olarte III 10fad9c167 Merge branch 'master' into test-playwright 4 months ago
Jose Olarte III 084fb09971 IN-PROGRESS: create 10 projects 4 months ago
  1. 55
      test-playwright/20-create-project.spec.ts
  2. 45
      test-playwright/25-create-project-x10.spec.ts
  3. 43
      test-playwright/33-record-gift-x10.spec.ts
  4. 30
      test-playwright/testUtils.ts

55
test-playwright/20-create-project.spec.ts

@ -2,6 +2,8 @@ import { test, expect } from '@playwright/test';
import { importUser } from './testUtils'; import { importUser } from './testUtils';
test('Create new project, then search for it', async ({ page }) => { test('Create new project, then search for it', async ({ page }) => {
test.slow();
// Generate a random string of 16 characters // Generate a random string of 16 characters
let randomString = Math.random().toString(36).substring(2, 18); let randomString = Math.random().toString(36).substring(2, 18);
@ -14,26 +16,45 @@ test('Create new project, then search for it', async ({ page }) => {
// Standard texts // Standard texts
const standardTitle = 'Idea '; const standardTitle = 'Idea ';
const standardDescription = 'Description of Idea '; const standardDescription = 'Description of Idea ';
const standardEdit = ' EDITED';
const standardWebsite = 'https://example.com';
const editedWebsite = 'https://example.com/edited';
// Set dates
const today = new Date();
const oneMonthAhead = new Date(today.setDate(today.getDate() + 30));
const twoMonthsAhead = new Date(today.setDate(today.getDate() + 30));
const finalDate = oneMonthAhead.toISOString().split('T')[0];
const editedDate = twoMonthsAhead.toISOString().split('T')[0];
// Set times
const now = new Date();
const oneHourAhead = new Date(now.setHours(now.getHours() + 1));
const twoHoursAhead = new Date(now.setHours(now.getHours() + 1));
const finalHour = oneHourAhead.getHours().toString().padStart(2, '0');
const editedHour = twoHoursAhead.getHours().toString().padStart(2, '0');
const finalMinute = oneHourAhead.getMinutes().toString().padStart(2, '0');
const finalTime = `${finalHour}:${finalMinute}`;
const editedTime = `${editedHour}:${finalMinute}`;
// Combine texts with the random string // Combine texts with the random string
const finalTitle = standardTitle + finalRandomString; const finalTitle = standardTitle + finalRandomString;
const finalDescription = standardDescription + finalRandomString; const finalDescription = standardDescription + finalRandomString;
const editedTitle = finalTitle + standardEdit;
const editedDescription = finalDescription + standardEdit;
// Import user 00 // Import user 00
await importUser(page, '00'); await importUser(page, '00');
// Pause for 5 seconds
await page.waitForTimeout(5000); // I have to wait, otherwise the (+) button to add a new project doesn't appear
// Create new project // Create new project
await page.goto('./projects'); await page.goto('./projects');
await page.getByRole('link', { name: 'Projects', exact: true }).click(); await page.getByRole('link', { name: 'Projects', exact: true }).click();
await page.getByRole('button').click(); await page.getByRole('button').click();
await page.getByPlaceholder('Idea Name').fill(finalTitle); // Add random suffix await page.getByPlaceholder('Idea Name').fill(finalTitle);
await page.getByPlaceholder('Description').fill(finalDescription); await page.getByPlaceholder('Description').fill(finalDescription);
await page.getByPlaceholder('Website').fill('https://example.com'); await page.getByPlaceholder('Website').fill(standardWebsite);
await page.getByPlaceholder('Start Date').fill('2025-12-01'); await page.getByPlaceholder('Start Date').fill(finalDate);
await page.getByPlaceholder('Start Time').fill('12:00'); await page.getByPlaceholder('Start Time').fill(finalTime);
await page.getByRole('button', { name: 'Save Project' }).click(); await page.getByRole('button', { name: 'Save Project' }).click();
// Check texts // Check texts
@ -43,11 +64,27 @@ test('Create new project, then search for it', async ({ page }) => {
// Search for newly-created project in /projects // Search for newly-created project in /projects
await page.goto('./projects'); await page.goto('./projects');
await page.getByRole('link', { name: 'Projects', exact: true }).click(); await page.getByRole('link', { name: 'Projects', exact: true }).click();
await expect(page.locator('ul#listProjects li.border-b:nth-child(1)')).toContainText(finalRandomString); // Assumes newest project always appears first in the Projects tab list await expect(page.locator('ul#listProjects li').filter({ hasText: finalTitle })).toBeVisible();
// Search for newly-created project in /discover // Search for newly-created project in /discover
await page.goto('./discover'); await page.goto('./discover');
await page.getByPlaceholder('Search…').fill(finalRandomString); await page.getByPlaceholder('Search…').fill(finalRandomString);
await page.locator('#QuickSearch button').click(); await page.locator('#QuickSearch button').click();
await expect(page.locator('ul#listDiscoverResults li.border-b:nth-child(1)')).toContainText(finalRandomString); await expect(page.locator('ul#listDiscoverResults li').filter({ hasText: finalTitle })).toBeVisible();
// Edit the project
await page.locator('a').filter({ hasText: finalTitle }).first().click();
await page.getByRole('button', { name: 'Edit' }).click();
await expect(page.getByPlaceholder('Idea Name')).toHaveValue(finalTitle); // Check that textfield value has loaded before proceeding
await page.getByPlaceholder('Idea Name').fill(editedTitle);
await page.getByPlaceholder('Description').fill(editedDescription);
await page.getByPlaceholder('Website').fill(editedWebsite);
await page.getByPlaceholder('Start Date').fill(editedDate);
await page.getByPlaceholder('Start Time').fill(editedTime);
await page.getByRole('button', { name: 'Save Project' }).click();
// Check edits
await expect(page.locator('h2')).toContainText(editedTitle);
await page.getByText('Read More').click();
await expect(page.locator('#Content')).toContainText(editedDescription);
}); });

45
test-playwright/25-create-project-x10.spec.ts

@ -0,0 +1,45 @@
import { test, expect } from '@playwright/test';
import { importUser, createUniqueStringsArray } from './testUtils';
test('Create 10 new projects', async ({ page }) => {
const projectCount = 10;
// Standard texts
const standardTitle = "Idea ";
const standardDescription = "Description of Idea ";
// Title and description arrays
const finalTitles = [];
const finalDescriptions = [];
// Create an array of unique strings
const uniqueStrings = await createUniqueStringsArray(projectCount);
// Populate arrays with titles and descriptions
for (let i = 0; i < projectCount; i++) {
let loopTitle = standardTitle + uniqueStrings[i];
finalTitles.push(loopTitle);
let loopDescription = standardDescription + uniqueStrings[i];
finalDescriptions.push(loopDescription);
}
// Import user 00
await importUser(page, '00');
// Create new projects
for (let i = 0; i < projectCount; i++) {
await page.goto('./projects');
await page.getByRole('link', { name: 'Projects', exact: true }).click();
await page.getByRole('button').click();
await page.getByPlaceholder('Idea Name').fill(finalTitles[i]); // Add random suffix
await page.getByPlaceholder('Description').fill(finalDescriptions[i]);
await page.getByPlaceholder('Website').fill('https://example.com');
await page.getByPlaceholder('Start Date').fill('2025-12-01');
await page.getByPlaceholder('Start Time').fill('12:00');
await page.getByRole('button', { name: 'Save Project' }).click();
// Check texts
await expect(page.locator('h2')).toContainText(finalTitles[i]);
await expect(page.locator('#Content')).toContainText(finalDescriptions[i]);
}
});

43
test-playwright/33-record-gift-x10.spec.ts

@ -0,0 +1,43 @@
import { test, expect } from '@playwright/test';
import { importUser, createUniqueStringsArray, createRandomNumbersArray } from './testUtils';
test('Record 10 new gifts', async ({ page }) => {
const giftCount = 10;
// Standard text
const standardTitle = "Gift ";
// Field value arrays
const finalTitles = [];
const finalNumbers = [];
// Create arrays for field input
const uniqueStrings = await createUniqueStringsArray(giftCount);
const randomNumbers = await createRandomNumbersArray(giftCount);
// Populate array with titles
for (let i = 0; i < giftCount; i++) {
let loopTitle = standardTitle + uniqueStrings[i];
finalTitles.push(loopTitle);
let loopNumber = randomNumbers[i];
finalNumbers.push(loopNumber);
}
// Import user 00
await importUser(page, '00');
// Record new gifts
for (let i = 0; i < giftCount; i++) {
// Record something given
await page.goto('./');
await page.getByRole('heading', { name: 'Unnamed/Unknown' }).click();
await page.getByPlaceholder('What was given').fill(finalTitles[i]);
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();
// Refresh home view and check gift
await page.goto('./');
await expect(page.locator('li').filter({ hasText: finalTitles[i] })).toBeVisible();
}
});

30
test-playwright/testUtils.ts

@ -66,3 +66,33 @@ export async function generateEthrUser(page: Page): Promise<string> {
return newDid; return newDid;
} }
// Function to generate a random string of specified length
export async function generateRandomString(length: number): Promise<string> {
return Math.random().toString(36).substring(2, 2 + length);
}
// Function to create an array of unique strings
export async function createUniqueStringsArray(count: number): Promise<string[]> {
const stringsArray = [];
const stringLength = 16;
for (let i = 0; i < count; i++) {
let randomString = await generateRandomString(stringLength);
stringsArray.push(randomString);
}
return stringsArray;
}
// Function to create an array of two-digit non-zero numbers
export async function createRandomNumbersArray(count: number): Promise<number[]> {
const numbersArray = [];
for (let i = 0; i < count; i++) {
let randomNumber = Math.floor(Math.random() * 99) + 1;
numbersArray.push(randomNumber);
}
return numbersArray;
}
Loading…
Cancel
Save