Skip to content

Commit fd719c9

Browse files
committed
chore: support for pro flags in app notifications
1 parent 4ace005 commit fd719c9

File tree

3 files changed

+77
-9
lines changed

3 files changed

+77
-9
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"WELCOME_DEVELOPER": {
3+
"PRO_EDITION_ONLY" : false,
34
"DANGER_SHOW_ON_EVERY_BOOT" : false,
45
"HTML_CONTENT": "<div>Welcome to Phoenix Code dev community! Click here to <a class='notification_ack' href='https://discord.com/invite/rBpTBPttca'> chat with our Discord Community.</a></div>",
56
"FOR_VERSIONS": ">=3.0.0",
67
"PLATFORM" : "all"
78
}
8-
}
9+
}

src/extensionsIntegrated/InAppNotifications/banner.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ define(function (require, exports, module) {
8080
* A sample notifications is as follows:
8181
* {
8282
* "SAMPLE_NOTIFICATION_NAME": {
83+
* "PRO_EDITION_ONLY" : false,
8384
* "DANGER_SHOW_ON_EVERY_BOOT" : false,
8485
* "HTML_CONTENT": "<div>hello world <a class='notification_ack'>Click to acknowledge.</a></div>",
8586
* "FOR_VERSIONS": "1.x || >=2.5.0 || 5.0.0 - 7.2.3",
@@ -91,16 +92,17 @@ define(function (require, exports, module) {
9192
* or there is an html element with class `notification_ack`.
9293
*
9394
* 1. `SAMPLE_NOTIFICATION_NAME` : This is a unique ID. It is used to check if the notification was shown to user.
94-
* 2. `DANGER_SHOW_ON_EVERY_BOOT` : (Default false) Setting this to true will cause the
95+
* 2. `PRO_EDITION_ONLY` : (Default false) Setting this to true will not show the notification on community editions
96+
* 3. `DANGER_SHOW_ON_EVERY_BOOT` : (Default false) Setting this to true will cause the
9597
* notification to be shown on every boot. This is bad ux and only be used if there is a critical security issue
9698
* that we want the version not to be used.
97-
* 3. `HTML_CONTENT`: The actual html content to show to the user. It can have an optional `notification_ack` class.
99+
* 4. `HTML_CONTENT`: The actual html content to show to the user. It can have an optional `notification_ack` class.
98100
* Setting this class will cause the notification to be shown once a day until the user explicitly clicks
99101
* on any html element with class `notification_ack` or explicitly click the close button.
100102
* If such a class is not present, then the notification is shown only once ever.
101-
* 4. `FOR_VERSIONS` : [Semver compatible version filter](https://www.npmjs.com/package/semver).
103+
* 5. `FOR_VERSIONS` : [Semver compatible version filter](https://www.npmjs.com/package/semver).
102104
* The notification will be shown to all versions satisfying this.
103-
* 5. `PLATFORM`: A comma seperated list of all platforms in which the message will be shown.
105+
* 6. `PLATFORM`: A comma seperated list of all platforms in which the message will be shown.
104106
* allowed values are: `mac,win,linux,allDesktop,firefox,chrome,safari,allBrowser,all`
105107
* @param notifications
106108
* @returns {false|*}
@@ -113,6 +115,7 @@ define(function (require, exports, module) {
113115

114116
const _InAppBannerShownAndDone = PreferencesManager.getViewState(
115117
IN_APP_NOTIFICATIONS_BANNER_SHOWN_STATE);
118+
const isProEdition = Phoenix.pro && Phoenix.pro.commitID;
116119

117120
for(const notificationID of Object.keys(notifications)){
118121
if(!_InAppBannerShownAndDone[notificationID]) {
@@ -126,6 +129,9 @@ define(function (require, exports, module) {
126129
if(customFilterCallback && !(await customFilterCallback(notification, notificationID))){
127130
continue;
128131
}
132+
if(!isProEdition && notification.PRO_EDITION_ONLY){
133+
continue;
134+
}
129135
if(!notification.DANGER_SHOW_ON_EVERY_BOOT){
130136
// One time notification. mark as shown and never show again
131137
// all notifications are one time, we track metrics for each notification separately

test/spec/Extn-InAppNotifications-integ-test.js

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*/
2121

22-
/*global describe, it, expect, beforeAll, afterAll, awaits, awaitsFor */
22+
/*global describe, it, expect, beforeAll, beforeEach, afterEach, afterAll, awaits, awaitsFor */
2323

2424
define(function (require, exports, module) {
2525
// Recommended to avoid reloading the integration test window Phoenix instance for each test.
@@ -28,7 +28,7 @@ define(function (require, exports, module) {
2828

2929
const testPath = SpecRunnerUtils.getTestPath("/spec/JSUtils-test-files");
3030

31-
let testWindow, banner;
31+
let testWindow, banner, originalPhoenixPro;
3232

3333

3434
describe("integration:In App notification banner integration tests", function () {
@@ -40,6 +40,16 @@ define(function (require, exports, module) {
4040
await SpecRunnerUtils.loadProjectInTestWindow(testPath);
4141
}, 30000);
4242

43+
beforeEach(function () {
44+
// Save original Phoenix.pro before each test
45+
originalPhoenixPro = testWindow.Phoenix.pro;
46+
});
47+
48+
afterEach(function () {
49+
// Restore Phoenix.pro after each test (even if test fails)
50+
testWindow.Phoenix.pro = originalPhoenixPro;
51+
});
52+
4353
async function _waitForBannerShown() {
4454
await awaitsFor(function () {
4555
return testWindow.$('#notification-bar').is(":visible");
@@ -52,16 +62,20 @@ define(function (require, exports, module) {
5262
await SpecRunnerUtils.closeTestWindow();
5363
}, 30000);
5464

55-
function getRandomNotification(platform, showOnEveryBoot=false, ack = false) {
65+
function getRandomNotification(platform, showOnEveryBoot=false, ack = false, proOnly = false) {
5666
const notification = {};
5767
const id = crypto.randomUUID();
5868
const ackClass = ack? "notification_ack" : '';
59-
notification[id] = {
69+
const notificationObj = {
6070
"DANGER_SHOW_ON_EVERY_BOOT": showOnEveryBoot,
6171
"HTML_CONTENT": `<div id='${id}' class="${ackClass}">random notification ${platform} with id ${id}, DANGER_SHOW_ON_EVERY_BOOT: ${showOnEveryBoot}, ack:${ack}</div>`,
6272
"FOR_VERSIONS": ">=3.0.0",
6373
"PLATFORM": platform || "all"
6474
};
75+
if (proOnly) {
76+
notificationObj.PRO_EDITION_ONLY = true;
77+
}
78+
notification[id] = notificationObj;
6579
return {notification, id: `#${id}`};
6680
}
6781

@@ -189,6 +203,53 @@ define(function (require, exports, module) {
189203
expect(testWindow.$(id).length).toEqual(0);
190204
});
191205

206+
it("Should show PRO_EDITION_ONLY notification in pro edition", async function () {
207+
banner.cleanNotificationBanner();
208+
209+
// Mock pro edition
210+
testWindow.Phoenix.pro = { commitID: "test-pro-commit" };
211+
212+
const {notification, id} = getRandomNotification("all", true, false, true);
213+
banner._renderNotifications(notification);
214+
215+
expect(testWindow.$(id).length).toEqual(1);
216+
217+
banner.cleanNotificationBanner();
218+
});
219+
220+
it("Should not show PRO_EDITION_ONLY notification in community edition", async function () {
221+
banner.cleanNotificationBanner();
222+
223+
// Mock community edition
224+
testWindow.Phoenix.pro = null;
225+
226+
const {notification, id} = getRandomNotification("all", true, false, true);
227+
banner._renderNotifications(notification);
228+
await awaits(50);
229+
230+
expect(testWindow.$(id).length).toEqual(0);
231+
232+
banner.cleanNotificationBanner();
233+
});
234+
235+
it("Should show non-PRO_EDITION_ONLY notification in all editions", async function () {
236+
const {notification, id} = getRandomNotification("all", true, false, false);
237+
238+
// Test in pro edition
239+
banner.cleanNotificationBanner();
240+
testWindow.Phoenix.pro = { commitID: "test-pro-commit" };
241+
banner._renderNotifications(notification);
242+
expect(testWindow.$(id).length).toEqual(1);
243+
banner.cleanNotificationBanner();
244+
expect(testWindow.$(id).length).toEqual(0);
245+
246+
// Test in community edition
247+
testWindow.Phoenix.pro = null;
248+
banner._renderNotifications(notification);
249+
expect(testWindow.$(id).length).toEqual(1);
250+
banner.cleanNotificationBanner();
251+
});
252+
192253
it("Should apply custom filter to block notification", async function () {
193254
banner.cleanNotificationBanner();
194255
banner.registerCustomFilter(async () => false);

0 commit comments

Comments
 (0)