Skip to content

Commit f84150b

Browse files
Creating functions for prefix category #10
1 parent e15e2f3 commit f84150b

File tree

1 file changed

+181
-0
lines changed

1 file changed

+181
-0
lines changed

tests/RPM/utils/prefixFunctions.js

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
import { expect } from "@playwright/test";
2+
3+
4+
async function checkPrefix(page, prefixName, hasDescription){
5+
await page.waitForLoadState('load');
6+
7+
await page.locator('#create').click();
8+
await page.waitForTimeout(1000);
9+
10+
// Fill in the name and description if provided
11+
if (prefixName) {
12+
await page.locator('input[id=name]').fill(prefixName);
13+
}
14+
15+
if (hasDescription) {
16+
await page.locator('input[id=description]').fill(hasDescription);
17+
}
18+
19+
20+
21+
// Handling different conditions based on parameters
22+
if (!prefixName && hasDescription ) {
23+
await page.waitForLoadState('load');
24+
await page.waitForTimeout(1500);
25+
// Check if the save button is disabled and reload the page
26+
const saveButton = page.locator('button#save');
27+
await expect(saveButton).toBeDisabled();
28+
await page.reload()
29+
}
30+
31+
32+
else if (prefixName && !hasDescription ) {
33+
await page.waitForLoadState('load');
34+
await page.waitForTimeout(1500);
35+
// Check if the save button is enable and reload the page
36+
const saveButton = page.locator('button#save').click();
37+
await page.waitForTimeout(500);
38+
39+
await page.waitForSelector('.toast[data-testid=toast] .text-base');
40+
const toast = await page.locator('.toast[data-testid=toast]');
41+
42+
let expectedMessage = 'Prefix Category created.';
43+
await expect(await toast.locator('.text-base')).toHaveText(expectedMessage);
44+
await toast.locator('button').click(); // Close the toast
45+
await page.reload();
46+
}
47+
48+
49+
}
50+
51+
async function findPrefix(page, prefixName) {
52+
53+
await page.waitForLoadState('load');
54+
// Wait for 500 milliseconds
55+
await page.waitForTimeout(500);
56+
// Search for the variable
57+
await page.locator('#ExternalLinks-search').fill(prefixName);
58+
// Wait for 1000 milliseconds
59+
await page.waitForTimeout(1000);
60+
// Click on the Search button
61+
await page.click('form.flex > button:nth-child(2)');
62+
// Wait for 500 milliseconds
63+
await page.waitForTimeout(500);
64+
// Locate the correct row
65+
const row = page.locator('[id^=ExternalLinks-row-]');
66+
await expect(row).toHaveCount(1);
67+
// Wait for 500 milliseconds
68+
await page.waitForTimeout(500);
69+
// Get the index of the row
70+
const id = (await row.getAttribute('id'));
71+
const index = id.split('-')[2];
72+
// Check values for the row
73+
await expect(page.locator(`#ExternalLinks-name-${index}`)).toHaveText(prefixName);
74+
75+
}
76+
77+
async function deletePrefix(page) {
78+
// Click on the delete button
79+
await page.locator('[id^=delete-]').click();
80+
81+
// Wait until the modal appears
82+
await page.waitForSelector('.modal');
83+
84+
// Check the modal title and body text
85+
await expect(page.locator('.modal-header')).toHaveText('Delete Prefix Category');
86+
await expect(page.locator('.modal-body')).toContainText(`Are you sure you wish to delete Prefix Category ?`);
87+
88+
// Click the confirm button in the modal footer
89+
await page.locator('.modal-footer button.variant-filled').click();
90+
// Wait for 750 milliseconds
91+
await page.waitForTimeout(750);
92+
await page.reload()
93+
94+
}
95+
96+
async function createPrefix(page, prefixName) {
97+
98+
await page.waitForLoadState('load');
99+
100+
await page.locator('#create').click();
101+
await page.waitForTimeout(1000);
102+
// Fill in the name and description if provided
103+
104+
await page.locator('input[id=name]').fill(prefixName);
105+
106+
await page.locator('input[id=description]').fill("Test description");
107+
108+
// Check if the save button is enable and reload the page
109+
const saveButton = page.locator('button#save').click();
110+
await page.waitForTimeout(1000);
111+
112+
await page.waitForSelector('.toast[data-testid=toast] .text-base');
113+
const toast = await page.locator('.toast[data-testid=toast]');
114+
115+
let expectedMessage = 'Prefix Category created.';
116+
await expect(await toast.locator('.text-base')).toHaveText(expectedMessage);
117+
await toast.locator('button').click(); // Close the toast
118+
await page.reload();
119+
}
120+
121+
async function editPrefix(page,prefixName) {
122+
123+
// Click on the delete button
124+
await page.locator('[id^=edit-]').click();
125+
await page.locator('input[id=name]').fill(prefixName);
126+
// Wait for 500 milliseconds
127+
await page.locator('input[id=description]').fill("Edit description");
128+
await page.waitForTimeout(500);
129+
// Check if the save button is enable and reload the page
130+
const saveButton = page.locator('button#save').click();
131+
await page.waitForTimeout(1000);
132+
133+
await page.waitForSelector('.toast[data-testid=toast] .text-base');
134+
const toast = await page.locator('.toast[data-testid=toast]');
135+
136+
let expectedMessage = 'Prefix Category updated.';
137+
await expect(await toast.locator('.text-base')).toHaveText(expectedMessage);
138+
await toast.locator('button').click(); // Close the toast
139+
await page.reload();
140+
141+
}
142+
143+
async function findEditedPrefix(page, prefixName) {
144+
145+
await page.waitForLoadState('load');
146+
// Wait for 500 milliseconds
147+
await page.waitForTimeout(500);
148+
// Search for the variable
149+
await page.locator('#ExternalLinks-search').fill(prefixName);
150+
// Wait for 1000 milliseconds
151+
await page.waitForTimeout(1000);
152+
// Click on the Search button
153+
await page.click('form.flex > button:nth-child(2)');
154+
// Wait for 500 milliseconds
155+
await page.waitForTimeout(500);
156+
// Locate the correct row
157+
const row = page.locator('[id^=ExternalLinks-row-]');
158+
await expect(row).toHaveCount(1);
159+
// Wait for 500 milliseconds
160+
await page.waitForTimeout(500);
161+
// Get the index of the row
162+
const id = (await row.getAttribute('id'));
163+
const index = id.split('-')[2];
164+
// Check values for the row
165+
await expect(page.locator(`#ExternalLinks-name-${index}`)).toHaveText(prefixName);
166+
// Wait for 500 milliseconds
167+
await page.waitForTimeout(500);
168+
await expect(page.locator(`#ExternalLinks-description-${index}`)).toHaveText(
169+
'Edit description'
170+
);
171+
172+
}
173+
174+
module.exports = {
175+
checkPrefix,
176+
findPrefix,
177+
deletePrefix,
178+
createPrefix,
179+
editPrefix,
180+
findEditedPrefix
181+
};

0 commit comments

Comments
 (0)