Skip to content

Commit aa95449

Browse files
Creating unique functions for external links management #9
1 parent 18dbecd commit aa95449

File tree

1 file changed

+213
-0
lines changed

1 file changed

+213
-0
lines changed
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
import { expect } from "@playwright/test";
2+
3+
4+
async function checkExternalLink(page, linkName, hasType, hasPrefix, hasURI) {
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 (linkName) {
12+
await page.locator('input[id=name]').fill(linkName);
13+
}
14+
15+
if (hasType) {
16+
17+
// Click the input element
18+
await page.click('#type');
19+
await page.waitForTimeout(500);
20+
await page.locator('.list-item .item:text("link")').click();
21+
}
22+
23+
if (hasPrefix) {
24+
// Click the input element
25+
await page.click('#prefix');
26+
await page.waitForTimeout(500);
27+
await page.locator('.list-item .item:text("dwc")').click();
28+
29+
}
30+
if (hasURI) {
31+
await page.locator('input[id=uri]').fill(hasURI);
32+
}
33+
34+
// Handling different conditions based on parameters
35+
if (linkName && hasType && !hasPrefix && !hasURI) {
36+
await page.waitForLoadState('load');
37+
await page.waitForTimeout(1500);
38+
// Check if the save button is disabled and reload the page
39+
const saveButton = page.locator('button#save');
40+
await expect(saveButton).toBeDisabled();
41+
await page.reload()
42+
}
43+
44+
else if (linkName && hasType && hasPrefix && !hasURI) {
45+
await page.waitForLoadState('load');
46+
await page.waitForTimeout(1500);
47+
// Check if the save button is disabled and reload the page
48+
const saveButton = page.locator('button#save');
49+
await expect(saveButton).toBeDisabled();
50+
await page.reload()
51+
}
52+
else if (linkName && !hasType && !hasPrefix && hasURI) {
53+
await page.waitForLoadState('load');
54+
await page.waitForTimeout(1500);
55+
// Check if the save button is enable and reload the page
56+
const saveButton = page.locator('button#save').click();
57+
await page.waitForTimeout(500);
58+
59+
await page.waitForSelector('.toast[data-testid=toast] .text-base');
60+
const toast = await page.locator('.toast[data-testid=toast]');
61+
62+
let expectedMessage = 'External link created.';
63+
await expect(await toast.locator('.text-base')).toHaveText(expectedMessage);
64+
await toast.locator('button').click(); // Close the toast
65+
await page.reload();
66+
}
67+
68+
69+
}
70+
71+
async function findExternalLink(page, linkName) {
72+
73+
await page.waitForLoadState('load');
74+
// Wait for 500 milliseconds
75+
await page.waitForTimeout(500);
76+
// Search for the variable
77+
await page.locator('#ExternalLinks-search').fill(linkName);
78+
// Wait for 1000 milliseconds
79+
await page.waitForTimeout(1000);
80+
// Click on the Search button
81+
await page.click('form.flex > button:nth-child(2)');
82+
// Wait for 500 milliseconds
83+
await page.waitForTimeout(500);
84+
// Locate the correct row
85+
const row = page.locator('[id^=ExternalLinks-row-]');
86+
await expect(row).toHaveCount(1);
87+
// Wait for 500 milliseconds
88+
await page.waitForTimeout(500);
89+
// Get the index of the row
90+
const id = (await row.getAttribute('id'));
91+
const index = id.split('-')[2];
92+
// Check values for the row
93+
await expect(page.locator(`#ExternalLinks-name-${index}`)).toHaveText(linkName);
94+
await expect(page.locator(`#ExternalLinks-uri-${index}`)).toHaveText(
95+
96+
);
97+
}
98+
99+
async function deleteExternalLink(page) {
100+
// Click on the delete button
101+
await page.locator('[id^=delete-]').click();
102+
103+
// Wait until the modal appears
104+
await page.waitForSelector('.modal');
105+
106+
// Check the modal title and body text
107+
await expect(page.locator('.modal-header')).toHaveText('Delete External Link');
108+
await expect(page.locator('.modal-body')).toContainText(`Are you sure you wish to delete external link ?`);
109+
110+
// Click the confirm button in the modal footer
111+
await page.locator('.modal-footer button.variant-filled').click();
112+
// Wait for 750 milliseconds
113+
await page.waitForTimeout(750);
114+
await page.reload()
115+
116+
}
117+
118+
async function createExternalLink(page, linkName) {
119+
120+
await page.waitForLoadState('load');
121+
122+
await page.locator('#create').click();
123+
await page.waitForTimeout(1000);
124+
// Fill in the name and description if provided
125+
126+
await page.locator('input[id=name]').fill(linkName);
127+
128+
await page.click('#type');
129+
await page.waitForTimeout(500);
130+
await page.locator('.list-item .item:text("link")').click();
131+
132+
await page.click('#prefix');
133+
await page.waitForTimeout(500);
134+
await page.locator('.list-item .item:text("dwc")').click();
135+
136+
await page.locator('input[id=uri]').fill("[email protected]");
137+
138+
// Check if the save button is enable and reload the page
139+
const saveButton = page.locator('button#save').click();
140+
await page.waitForTimeout(1000);
141+
142+
await page.waitForSelector('.toast[data-testid=toast] .text-base');
143+
const toast = await page.locator('.toast[data-testid=toast]');
144+
145+
let expectedMessage = 'External link created.';
146+
await expect(await toast.locator('.text-base')).toHaveText(expectedMessage);
147+
await toast.locator('button').click(); // Close the toast
148+
await page.reload();
149+
}
150+
151+
async function editExternalLink(page, linkName) {
152+
153+
// Click on the delete button
154+
await page.locator('[id^=edit-]').click();
155+
// Wait for 500 milliseconds
156+
await page.waitForTimeout(500);
157+
await page.locator('input[id=name]').fill(linkName);
158+
159+
await page.locator('input[id=uri]').fill('testing');
160+
await page.waitForTimeout(500);
161+
// Check if the save button is enable and reload the page
162+
const saveButton = page.locator('button#save').click();
163+
await page.waitForTimeout(1000);
164+
165+
await page.waitForSelector('.toast[data-testid=toast] .text-base');
166+
const toast = await page.locator('.toast[data-testid=toast]');
167+
168+
let expectedMessage = 'External link updated.';
169+
await expect(await toast.locator('.text-base')).toHaveText(expectedMessage);
170+
await toast.locator('button').click(); // Close the toast
171+
await page.reload();
172+
173+
}
174+
175+
async function findEditedExternalLink(page, linkName) {
176+
177+
await page.waitForLoadState('load');
178+
// Wait for 500 milliseconds
179+
await page.waitForTimeout(500);
180+
// Search for the variable
181+
await page.locator('#ExternalLinks-search').fill(linkName);
182+
// Wait for 1000 milliseconds
183+
await page.waitForTimeout(1000);
184+
// Click on the Search button
185+
await page.click('form.flex > button:nth-child(2)');
186+
// Wait for 500 milliseconds
187+
await page.waitForTimeout(500);
188+
// Locate the correct row
189+
const row = page.locator('[id^=ExternalLinks-row-]');
190+
await expect(row).toHaveCount(1);
191+
// Wait for 500 milliseconds
192+
await page.waitForTimeout(500);
193+
// Get the index of the row
194+
const id = (await row.getAttribute('id'));
195+
const index = id.split('-')[2];
196+
// Check values for the row
197+
await expect(page.locator(`#ExternalLinks-name-${index}`)).toHaveText(linkName);
198+
// Wait for 500 milliseconds
199+
await page.waitForTimeout(500);
200+
await expect(page.locator(`#ExternalLinks-uri-${index}`)).toHaveText(
201+
'testing'
202+
);
203+
204+
}
205+
206+
module.exports = {
207+
checkExternalLink,
208+
findExternalLink,
209+
deleteExternalLink,
210+
createExternalLink,
211+
editExternalLink,
212+
findEditedExternalLink
213+
};

0 commit comments

Comments
 (0)