You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.2 KiB

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 ";
const standardWebsite = 'https://example.com';
// 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);
}
// Set date
const today = new Date();
const oneMonthAhead = new Date(today.setDate(today.getDate() + 30));
const standardDate = oneMonthAhead.toISOString().split('T')[0];
// Set time
const now = new Date();
const futureTime = new Date(now.setHours(now.getHours() + 1));
const standardHour = futureTime.getHours().toString().padStart(2, '0');
const standardMinute = futureTime.getMinutes().toString().padStart(2, '0');
const standardTime = `${standardHour}:${standardMinute}`;
// 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(standardWebsite);
await page.getByPlaceholder('Start Date').fill(standardDate);
await page.getByPlaceholder('Start Time').fill(standardTime);
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]);
}
});