Browse Source

Improved create project test

- Added editing to test
- Added variables for other values
Jose Olarte III 3 months ago
parent
commit
3262f0ee64
  1. 48
      test-playwright/20-create-project.spec.ts

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

@ -2,6 +2,8 @@ import { test, expect } from '@playwright/test';
import { importUser } from './testUtils';
test('Create new project, then search for it', async ({ page }) => {
test.slow();
// Generate a random string of 16 characters
let randomString = Math.random().toString(36).substring(2, 18);
@ -14,10 +16,32 @@ test('Create new project, then search for it', async ({ page }) => {
// Standard texts
const standardTitle = '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
const finalTitle = standardTitle + finalRandomString;
const finalDescription = standardDescription + finalRandomString;
const editedTitle = finalTitle + standardEdit;
const editedDescription = finalDescription + standardEdit;
// Import user 00
await importUser(page, '00');
@ -26,11 +50,11 @@ test('Create new project, then search for it', async ({ page }) => {
await page.goto('./projects');
await page.getByRole('link', { name: 'Projects', exact: true }).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('Website').fill('https://example.com');
await page.getByPlaceholder('Start Date').fill('2025-12-01');
await page.getByPlaceholder('Start Time').fill('12:00');
await page.getByPlaceholder('Website').fill(standardWebsite);
await page.getByPlaceholder('Start Date').fill(finalDate);
await page.getByPlaceholder('Start Time').fill(finalTime);
await page.getByRole('button', { name: 'Save Project' }).click();
// Check texts
@ -47,4 +71,20 @@ test('Create new project, then search for it', async ({ page }) => {
await page.getByPlaceholder('Search…').fill(finalRandomString);
await page.locator('#QuickSearch button').click();
await expect(page.locator('ul#listDiscoverResults li.border-b:nth-child(1)')).toContainText(finalRandomString);
// 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);
});
Loading…
Cancel
Save