-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy path002-project-management.spec.ts
105 lines (88 loc) · 3.88 KB
/
002-project-management.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { test } from '@playwright/test';
import { v4 as uuidv4 } from 'uuid';
import type { Project } from 'common/api/osrdEditoastApi';
import projectData from './assets/operationStudies/project.json';
import HomePage from './pages/home-page-model';
import ProjectPage from './pages/project-page-model';
import { deleteApiRequest, getApiRequest, postApiRequest } from './utils/api-setup';
test.describe('Validate the Operational Study Project workflow', () => {
let project: Project;
test.beforeEach('Create a new project using the API', async ({ page }) => {
project = await postApiRequest('/api/projects/', {
...projectData,
name: `${projectData.name} ${uuidv4()}`, // Generate a unique name with UUID
budget: 1234567890, // Assign a predefined budget for testing
});
// Navigate to the Operational Studies projects page
await page.goto('/operational-studies/projects');
});
test.afterEach('Delete the project', async () => {
await deleteApiRequest(`/api/projects/${project.id}/`);
});
/** *************** Test 1 **************** */
test('Create a new project', async ({ page }) => {
const projectPage = new ProjectPage(page);
// Define a unique project name for the test
const projectName = `${projectData.name} ${uuidv4()}`;
// Create a new project using the project page model and json data
await projectPage.createOrUpdateProject({
name: projectName,
description: projectData.description,
objectives: projectData.objectives,
funders: projectData.funders,
budget: projectData.budget,
tags: projectData.tags,
});
// Validate that the project was created with the correct data
await projectPage.validateProjectData({
name: projectName,
description: projectData.description,
objectives: projectData.objectives,
funders: projectData.funders,
budget: projectData.budget,
tags: projectData.tags,
});
// Fetch all projects via the API and find the test project by name
const projects = await getApiRequest('/api/projects/');
const actualTestProject = projects.results.find((p: Project) => p.name === projectName);
// Delete the created project
await deleteApiRequest(`/api/projects/${actualTestProject.id}/`);
});
/** *************** Test 2 **************** */
test('Update an existing project', async ({ page }) => {
const homePage = new HomePage(page);
const projectPage = new ProjectPage(page);
// Open the created project by name using the project page model
await projectPage.openProjectByTestId(project.name);
// Update the project data and save it
await projectPage.createOrUpdateProject({
name: `${project.name} (updated)`,
description: `${project.description} (updated)`,
objectives: `${projectData.objectives} (updated)`,
funders: `${project.funders} (updated)`,
budget: '123456789',
tags: ['update-tag'],
isUpdate: true, // Indicate that this is an update
});
// Navigate back to the Operational Studies page via the home page
await homePage.goToHomePage();
await homePage.goToOperationalStudiesPage();
// Reopen the updated project and validate the updated data
await projectPage.openProjectByTestId(`${project.name} (updated)`);
await projectPage.validateProjectData({
name: `${project.name} (updated)`,
description: `${project.description} (updated)`,
objectives: `${projectData.objectives} (updated)`,
funders: `${project.funders} (updated)`,
budget: '123456789',
tags: ['update-tag'],
});
});
/** *************** Test 3 **************** */
test('Delete a project', async ({ page }) => {
const projectPage = new ProjectPage(page);
// Find the project by name and delete it using the page model
await projectPage.clickProjectByName(project.name);
await projectPage.deleteProject(project.name);
});
});