Skip to content

Commit e6231a8

Browse files
Updated test helper for notification email using SMTP server (#334)
* Added api helper for smtp * Updated api helper for document notifications * Updated ui helper for document notification * Moved ui helper for restore button to UiBaseLocator * Bumped version of test helper * Fixed indentation --------- Co-authored-by: Andreas Zerbst <andr317c@live.dk>
1 parent d5b1c2f commit e6231a8

File tree

8 files changed

+75
-7
lines changed

8 files changed

+75
-7
lines changed

lib/helpers/ApiHelpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {LoginApiHelper} from "./LoginApiHelper";
3535
import {WebhookApiHelper} from "./WebhookApiHelper";
3636
import {MediaDeliveryApiHelper} from './differentAppSettingsHelpers/MediaDeliveryApiHelper';
3737
import {ContentDeliveryApiHelper} from "./differentAppSettingsHelpers/ContentDeliveryApiHelper";
38+
import {SmtpApiHelper} from './SmtpApiHelper';
3839

3940
export class ApiHelpers {
4041
baseUrl: string = umbracoConfig.environment.baseUrl;
@@ -73,6 +74,7 @@ export class ApiHelpers {
7374
webhook: WebhookApiHelper;
7475
mediaDeliveryApi: MediaDeliveryApiHelper;
7576
contentDeliveryApi: ContentDeliveryApiHelper;
77+
smtp: SmtpApiHelper;
7678

7779
constructor(page: Page) {
7880
this.page = page;
@@ -110,6 +112,7 @@ export class ApiHelpers {
110112
this.webhook = new WebhookApiHelper(this, this.page);
111113
this.mediaDeliveryApi = new MediaDeliveryApiHelper(this);
112114
this.contentDeliveryApi = new ContentDeliveryApiHelper(this);
115+
this.smtp = new SmtpApiHelper(this);
113116
}
114117

115118
async getAccessToken() {

lib/helpers/ContentUiHelper.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,4 +1794,10 @@ export class ContentUiHelper extends UiBaseLocators {
17941794
async isChooseButtonVisible(isVisible: boolean = true) {
17951795
await expect(this.chooseBtn).toBeVisible({visible: isVisible});
17961796
}
1797+
1798+
async clickDocumentNotificationOptionWithName(name: string) {
1799+
const notificationOptionLocator = this.page.locator('umb-document-notifications-modal [id$="' + name + '"]').locator('#toggle');
1800+
await expect(notificationOptionLocator).toBeVisible();
1801+
await notificationOptionLocator.click();
1802+
}
17971803
}

lib/helpers/DocumentApiHelper.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,5 +1637,22 @@ export class DocumentApiHelper {
16371637
entityType: 'document-property-value'
16381638
});
16391639
return await this.update(documentId, documentData);
1640-
}
1640+
}
1641+
1642+
async getNotifications(id: string) {
1643+
const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/document/' + id + '/notifications');
1644+
return await response.json();
1645+
}
1646+
1647+
async updatetNotifications(id: string, subscribedActionIds: string[] = []) {
1648+
const updateData = {
1649+
"subscribedActionIds": subscribedActionIds
1650+
};
1651+
return await this.api.put(this.api.baseUrl + '/umbraco/management/api/v1/document/' + id + '/notifications', updateData);
1652+
}
1653+
1654+
async doesNotificationExist(id: string, actionId: string) {
1655+
const notifications = await this.getNotifications(id);
1656+
return notifications.some((notification) => notification.actionId === actionId && notification.subscribed === true);
1657+
}
16411658
}

lib/helpers/MediaUiHelper.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export class MediaUiHelper extends UiBaseLocators {
88
private readonly mediaSearchTxt: Locator;
99
private readonly trashBtn: Locator;
1010
private readonly restoreThreeDotsBtn: Locator;
11-
private readonly restoreBtn: Locator;
1211
private readonly confirmEmptyRecycleBinBtn: Locator;
1312
private readonly mediaCreateBtn: Locator;
1413
private readonly mediaListHeader: Locator;
@@ -33,7 +32,6 @@ export class MediaUiHelper extends UiBaseLocators {
3332
this.mediaSearchTxt = page.getByLabel('Search', {exact: true});
3433
this.trashBtn = page.getByLabel(/^Trash()?$/);
3534
this.restoreThreeDotsBtn = page.getByRole('button', {name: 'Restore…'});
36-
this.restoreBtn = page.getByLabel('Restore', {exact: true});
3735
this.confirmEmptyRecycleBinBtn = page.locator('#confirm').getByLabel('Empty Recycle Bin', {exact: true});
3836
this.mediaCreateBtn = this.page.locator('umb-collection-toolbar').getByLabel('Create');
3937
this.mediaListView = this.page.locator('umb-media-table-collection-view');
@@ -87,7 +85,7 @@ export class MediaUiHelper extends UiBaseLocators {
8785
await this.clickActionsMenuForName(name);
8886
await this.restoreThreeDotsBtn.click();
8987
await this.page.waitForTimeout(1000);
90-
await this.restoreBtn.click();
88+
await this.clickRestoreButton();
9189
}
9290

9391
async waitForMediaToBeTrashed() {

lib/helpers/SmtpApiHelper.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {ApiHelpers} from "./ApiHelpers";
2+
3+
export class SmtpApiHelper {
4+
api: ApiHelpers;
5+
private smtpBaseUrl = 'http://localhost:5000'; // Default smtp4dev URL, can be configured
6+
7+
constructor(api: ApiHelpers) {
8+
this.api = api;
9+
}
10+
11+
async getAllEmails() {
12+
const response = await this.api.page.request.get(this.smtpBaseUrl + '/api/messages', {
13+
ignoreHTTPSErrors: true
14+
});
15+
return await response.json();
16+
}
17+
18+
async deleteAllEmails() {
19+
const response = await this.api.page.request.delete(this.smtpBaseUrl + '/api/messages/*', {
20+
ignoreHTTPSErrors: true
21+
});
22+
return response.status();
23+
}
24+
25+
async findEmailBySubject(subject: string) {
26+
const emails = await this.getAllEmails();
27+
const foundEmail = emails.results.find((email: any) =>
28+
email.subject && email.subject.toLowerCase().includes(subject.toLowerCase())
29+
);
30+
return foundEmail || null;
31+
}
32+
33+
async doesNotificationEmailWithSubjectExist(actionName: string, contentName: string) {
34+
const expectedSubject = `Notification about ${actionName} performed on ${contentName}`
35+
return this.findEmailBySubject(expectedSubject);
36+
}
37+
}

lib/helpers/UiBaseLocators.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export class UiBaseLocators {
158158
public readonly inputUploadField: Locator;
159159
public readonly entityItem: Locator;
160160
public readonly sectionLinks: Locator;
161+
public readonly restoreBtn: Locator;
161162
public readonly backOfficeMain: Locator;
162163

163164
constructor(page: Page) {
@@ -320,6 +321,7 @@ export class UiBaseLocators {
320321
this.imageCropperField = page.locator('umb-image-cropper-field');
321322
this.inputUploadField = page.locator('umb-input-upload-field').locator('#wrapperInner');
322323
this.entityItem = page.locator('umb-entity-item-ref');
324+
this.restoreBtn = page.getByLabel('Restore', {exact: true});
323325
this.backOfficeMain = page.locator('umb-backoffice-main');
324326
}
325327

@@ -1455,6 +1457,11 @@ export class UiBaseLocators {
14551457
await expect(this.page.getByTestId('workspace:view-link:' + alias)).toBeVisible({visible: isVisible});
14561458
}
14571459

1460+
async clickRestoreButton() {
1461+
await expect(this.restoreBtn).toBeVisible();
1462+
await this.restoreBtn.click();
1463+
}
1464+
14581465
async isInputDropzoneVisible(isVisible: boolean = true) {
14591466
await expect(this.inputDropzone).toBeVisible({visible: isVisible});
14601467
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@umbraco/playwright-testhelpers",
3-
"version": "17.0.10",
3+
"version": "17.0.11",
44
"description": "Test helpers for making playwright tests for Umbraco solutions",
55
"main": "dist/lib/index.js",
66
"files": [

0 commit comments

Comments
 (0)