From 854070aa39e8f35cbe48f8b29e8e133a20080bb0 Mon Sep 17 00:00:00 2001
From: Yash Rajpal <58601732+yash-rajpal@users.noreply.github.com>
Date: Wed, 17 Aug 2022 22:09:35 +0530
Subject: [PATCH] [FIX] Notification preferences not updated on save (#26461)
---
.../views/room/Header/ToolBox/ToolBox.tsx | 2 +-
.../components/NotificationByDevice.tsx | 1 +
.../server/modules/watchers/publishFields.ts | 3 ++
.../tests/e2e/channel-management.spec.ts | 20 +++++++++
.../home-flextab-notificationPreferences.ts | 41 +++++++++++++++++++
.../page-objects/fragments/home-flextab.ts | 12 ++++++
6 files changed, 78 insertions(+), 1 deletion(-)
create mode 100644 apps/meteor/tests/e2e/page-objects/fragments/home-flextab-notificationPreferences.ts
diff --git a/apps/meteor/client/views/room/Header/ToolBox/ToolBox.tsx b/apps/meteor/client/views/room/Header/ToolBox/ToolBox.tsx
index b54ce28b2611f..10dc9efe6b316 100644
--- a/apps/meteor/client/views/room/Header/ToolBox/ToolBox.tsx
+++ b/apps/meteor/client/views/room/Header/ToolBox/ToolBox.tsx
@@ -11,7 +11,7 @@ import { useToolboxContext } from '../../lib/Toolbox/ToolboxContext';
import { useTab, useTabBarOpen } from '../../providers/ToolboxProvider';
const renderMenuOption: OptionRenderer = ({ label: { title, icon }, ...props }: any): ReactNode => (
-
+
);
type ToolBoxProps = {
diff --git a/apps/meteor/client/views/room/contextualBar/NotificationPreferences/components/NotificationByDevice.tsx b/apps/meteor/client/views/room/contextualBar/NotificationPreferences/components/NotificationByDevice.tsx
index eb3ddf309a026..336152a9ca6f9 100644
--- a/apps/meteor/client/views/room/contextualBar/NotificationPreferences/components/NotificationByDevice.tsx
+++ b/apps/meteor/client/views/room/contextualBar/NotificationPreferences/components/NotificationByDevice.tsx
@@ -17,6 +17,7 @@ export const NotificationByDevice = ({ device, icon, children }: NotificationByD
}
+ data-qa-id={`${device}-notifications`}
>
{children}
diff --git a/apps/meteor/server/modules/watchers/publishFields.ts b/apps/meteor/server/modules/watchers/publishFields.ts
index 6de9272a28ee3..c3ea240507bbe 100644
--- a/apps/meteor/server/modules/watchers/publishFields.ts
+++ b/apps/meteor/server/modules/watchers/publishFields.ts
@@ -21,6 +21,9 @@ export const subscriptionFields = {
desktopNotifications: 1,
mobilePushNotifications: 1,
emailNotifications: 1,
+ desktopPrefOrigin: 1,
+ mobilePrefOrigin: 1,
+ emailPrefOrigin: 1,
unreadAlert: 1,
_updatedAt: 1,
blocked: 1,
diff --git a/apps/meteor/tests/e2e/channel-management.spec.ts b/apps/meteor/tests/e2e/channel-management.spec.ts
index 86b0b4bd90807..fcdb56f64f302 100644
--- a/apps/meteor/tests/e2e/channel-management.spec.ts
+++ b/apps/meteor/tests/e2e/channel-management.spec.ts
@@ -82,4 +82,24 @@ test.describe.serial('channel-management', () => {
await expect(page).toHaveURL(`/channel/NAME-EDITED-${targetChannel}`);
});
+
+ test('expect edit notification preferences of "targetChannel"', async () => {
+ await poHomeChannel.sidenav.openChat(targetChannel);
+ await poHomeChannel.tabs.btnMoreItems.click({ force: true });
+ await poHomeChannel.tabs.btnNotificationPreferences.click({ force: true });
+ await poHomeChannel.tabs.notificationPreferences.updateAllNotificaitonPreferences();
+ await poHomeChannel.tabs.notificationPreferences.btnSave.click();
+
+ await expect(poHomeChannel.toastSuccess).toBeVisible();
+ });
+
+ test('expect all notification preferences of "targetChannel" to be "Mentions"', async () => {
+ await poHomeChannel.sidenav.openChat(targetChannel);
+ await poHomeChannel.tabs.btnMoreItems.click({ force: true });
+ await poHomeChannel.tabs.btnNotificationPreferences.click({ force: true });
+
+ await expect(poHomeChannel.tabs.notificationPreferences.getPreferenceByDevice('Desktop')).toContainText('Mentions');
+ await expect(poHomeChannel.tabs.notificationPreferences.getPreferenceByDevice('Mobile')).toContainText('Mentions');
+ await expect(poHomeChannel.tabs.notificationPreferences.getPreferenceByDevice('Email')).toContainText('Mentions');
+ });
});
diff --git a/apps/meteor/tests/e2e/page-objects/fragments/home-flextab-notificationPreferences.ts b/apps/meteor/tests/e2e/page-objects/fragments/home-flextab-notificationPreferences.ts
new file mode 100644
index 0000000000000..2dd316268f3ca
--- /dev/null
+++ b/apps/meteor/tests/e2e/page-objects/fragments/home-flextab-notificationPreferences.ts
@@ -0,0 +1,41 @@
+import type { Locator, Page } from '@playwright/test';
+
+export class HomeFlextabNotificationPreferences {
+ private readonly page: Page;
+
+ constructor(page: Page) {
+ this.page = page;
+ }
+
+ get btnSave(): Locator {
+ return this.page.locator('//aside//button[contains(text(), "Save")]');
+ }
+
+ getPreferenceByDevice(device: string): Locator {
+ return this.page.locator(`//div[@id="${device}Alert"]`);
+ }
+
+ async selectDropdownById(text: string): Promise {
+ await this.page.locator(`//div[@id="${text}"]`).click();
+ }
+
+ async selectOptionByLabel(text: string): Promise {
+ await this.page.locator(`li.rcx-option >> text="${text}"`).click();
+ }
+
+ async selectDevice(text: string): Promise {
+ await this.page.locator(`[data-qa-id="${text}-notifications"]`).click();
+ }
+
+ async updateDevicePreference(device: string): Promise {
+ await this.selectDevice(device);
+ await this.selectDropdownById(`${device}Alert`);
+ await this.selectOptionByLabel('Mentions');
+ }
+
+ async updateAllNotificaitonPreferences(): Promise {
+ await this.updateDevicePreference('Desktop');
+ await this.updateDevicePreference('Mobile');
+ await this.updateDevicePreference('Email');
+ }
+}
diff --git a/apps/meteor/tests/e2e/page-objects/fragments/home-flextab.ts b/apps/meteor/tests/e2e/page-objects/fragments/home-flextab.ts
index 10e74dbe53d97..8823435b18968 100644
--- a/apps/meteor/tests/e2e/page-objects/fragments/home-flextab.ts
+++ b/apps/meteor/tests/e2e/page-objects/fragments/home-flextab.ts
@@ -1,6 +1,7 @@
import type { Locator, Page } from '@playwright/test';
import { HomeFlextabMembers } from './home-flextab-members';
+import { HomeFlextabNotificationPreferences } from './home-flextab-notificationPreferences';
import { HomeFlextabRoom } from './home-flextab-room';
export class HomeFlextab {
@@ -10,10 +11,13 @@ export class HomeFlextab {
readonly room: HomeFlextabRoom;
+ readonly notificationPreferences: HomeFlextabNotificationPreferences;
+
constructor(page: Page) {
this.page = page;
this.members = new HomeFlextabMembers(page);
this.room = new HomeFlextabRoom(page);
+ this.notificationPreferences = new HomeFlextabNotificationPreferences(page);
}
get btnTabMembers(): Locator {
@@ -24,6 +28,14 @@ export class HomeFlextab {
return this.page.locator('[data-qa-id=ToolBoxAction-info-circled]');
}
+ get btnMoreItems(): Locator {
+ return this.page.locator('[data-qa-id=ToolBox-Menu]');
+ }
+
+ get btnNotificationPreferences(): Locator {
+ return this.page.locator('[data-qa-id=ToolBoxAction-bell]');
+ }
+
get flexTabViewThreadMessage(): Locator {
return this.page.locator(
'div.thread-list.js-scroll-thread ul.thread [data-qa-type="message"]:last-child div.message-body-wrapper [data-qa-type="message-body"]',