From 262e5cc30fef91b53dc41d2dd70bfa404a77520c Mon Sep 17 00:00:00 2001 From: Jose Olarte III Date: Tue, 23 Jul 2024 21:26:05 +0800 Subject: [PATCH] More tests added --- .../00-check-activity-feed.spec.ts | 2 +- .../01-check-discover-results.spec.ts | 12 ++++ test-playwright/20-create-project.spec.ts | 2 +- .../21-create-project-search.spec.ts | 66 +++++++++++++++++++ test-playwright/30-record-gift.spec.ts | 46 +++++++++++++ 5 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 test-playwright/01-check-discover-results.spec.ts create mode 100644 test-playwright/21-create-project-search.spec.ts create mode 100644 test-playwright/30-record-gift.spec.ts diff --git a/test-playwright/00-check-activity-feed.spec.ts b/test-playwright/00-check-activity-feed.spec.ts index 0d5fd43..30e5ccc 100644 --- a/test-playwright/00-check-activity-feed.spec.ts +++ b/test-playwright/00-check-activity-feed.spec.ts @@ -1,6 +1,6 @@ import { test, expect } from '@playwright/test'; -test('test', async ({ page }) => { +test('Check activity feed', async ({ page }) => { // Load app homepage await page.goto('./'); diff --git a/test-playwright/01-check-discover-results.spec.ts b/test-playwright/01-check-discover-results.spec.ts new file mode 100644 index 0000000..222ea7b --- /dev/null +++ b/test-playwright/01-check-discover-results.spec.ts @@ -0,0 +1,12 @@ +import { test, expect } from '@playwright/test'; + +test('Check discover results', async ({ page }) => { + // Load Discover view + await page.goto('./discover'); + + // Check that initial 10 projects have been loaded + await page.locator('section#Content li.border-b:nth-child(10)'); + + // Scroll down a bit to trigger loading additional projects + await page.locator('section#Content li.border-b:nth-child(20)').scrollIntoViewIfNeeded(); +}); \ No newline at end of file diff --git a/test-playwright/20-create-project.spec.ts b/test-playwright/20-create-project.spec.ts index a9cf2c9..264f868 100644 --- a/test-playwright/20-create-project.spec.ts +++ b/test-playwright/20-create-project.spec.ts @@ -1,6 +1,6 @@ import { test, expect } from '@playwright/test'; -test('test', async ({ page }) => { +test('Create new project', async ({ page }) => { // Generate a random string of 16 characters let randomString = Math.random().toString(36).substring(2, 18); diff --git a/test-playwright/21-create-project-search.spec.ts b/test-playwright/21-create-project-search.spec.ts new file mode 100644 index 0000000..541f841 --- /dev/null +++ b/test-playwright/21-create-project-search.spec.ts @@ -0,0 +1,66 @@ +import { test, expect } from '@playwright/test'; + +test('Create new project, then search for it', async ({ page }) => { + // Generate a random string of 16 characters + let randomString = Math.random().toString(36).substring(2, 18); + + // In case the string is shorter than 16 characters, generate more characters until it is 16 characters long + while (randomString.length < 16) { + randomString += Math.random().toString(36).substring(2, 18); + } + const finalRandomString = randomString.substring(0, 16); + + // Standard texts + const standardTitle = "Idea "; + const standardDescription = "Description of Idea "; + + // Combine texts with the random string + const finalTitle = standardTitle + finalRandomString; + const finalDescription = standardDescription + finalRandomString; + + // Create new ID using seed phrase "rigid shrug mobile…" + await page.goto('./start'); + await page.getByText('You have a seed').click(); + await page.getByPlaceholder('Seed Phrase').click(); + await page.getByPlaceholder('Seed Phrase').fill('rigid shrug mobile smart veteran half all pond toilet brave review universe ship congress found yard skate elite apology jar uniform subway slender luggage'); + await page.getByRole('button', { name: 'Import' }).click(); + + // Set name + await page.getByRole('link', { name: 'Set Your Name' }).click(); + await page.getByPlaceholder('Name').click(); + await page.getByPlaceholder('Name').fill('User Zero'); + await page.getByRole('button', { name: 'Save Changes' }).click(); + + // Check DID + await expect(page.getByRole('code')).toContainText('did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F'); + + // 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 + await page.goto('./projects'); + await page.getByRole('link', { name: 'Projects', exact: true }).click(); + await page.getByRole('button').click(); + await page.getByPlaceholder('Idea Name').click(); + await page.getByPlaceholder('Idea Name').fill(finalTitle); // Add random suffix + await page.getByPlaceholder('Description').click(); + await page.getByPlaceholder('Description').fill(finalDescription); + await page.getByPlaceholder('Website').click(); + await page.getByPlaceholder('Website').fill('https://example.com'); + await page.getByPlaceholder('Start Date').click(); + await page.getByPlaceholder('Start Date').fill('2025-12-01'); + await page.getByPlaceholder('Start Time').click(); + await page.getByPlaceholder('Start Time').fill('12:00'); + await page.getByRole('button', { name: 'Save Project' }).click(); + + // Check texts + await expect(page.locator('h2')).toContainText(finalTitle); + await expect(page.locator('#Content')).toContainText(finalDescription); + + // Search for project that was just created + await page.goto('./discover'); + await page.waitForTimeout(5000); // Wait for a bit + await page.getByPlaceholder('Search…').fill(finalRandomString); + await page.locator('#QuickSearch button').click(); + await expect(page.locator('section#Content li.border-b:nth-child(1)')).toContainText(finalRandomString); +}); \ No newline at end of file diff --git a/test-playwright/30-record-gift.spec.ts b/test-playwright/30-record-gift.spec.ts new file mode 100644 index 0000000..3c4ba39 --- /dev/null +++ b/test-playwright/30-record-gift.spec.ts @@ -0,0 +1,46 @@ +import { test, expect } from '@playwright/test'; + +test('Record something given', async ({ page }) => { + // Generate a random string of 16 characters + let randomString = Math.random().toString(36).substring(2, 18); + + // In case the string is shorter than 16 characters, generate more characters until it is 16 characters long + while (randomString.length < 16) { + randomString += Math.random().toString(36).substring(2, 18); + } + const finalRandomString = randomString.substring(0, 16); + + // 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 + finalRandomString; + + // Create new ID using seed phrase "rigid shrug mobile…" + await page.goto('./start'); + await page.getByText('You have a seed').click(); + await page.getByPlaceholder('Seed Phrase').click(); + await page.getByPlaceholder('Seed Phrase').fill('rigid shrug mobile smart veteran half all pond toilet brave review universe ship congress found yard skate elite apology jar uniform subway slender luggage'); + await page.getByRole('button', { name: 'Import' }).click(); + + // Set name + await page.getByRole('link', { name: 'Set Your Name' }).click(); + await page.getByPlaceholder('Name').click(); + await page.getByPlaceholder('Name').fill('User Zero'); + await page.getByRole('button', { name: 'Save Changes' }).click(); + + // Check DID + await expect(page.getByRole('code')).toContainText('did:ethr:0x0000694B58C2cC69658993A90D3840C560f2F51F'); + + // Record something given + await page.goto('./'); + await page.getByRole('heading', { name: 'Unnamed/Unknown' }).click(); + await page.getByPlaceholder('What was given').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(); +}); \ No newline at end of file