1919 *
2020 */
2121
22- /*global describe, it, expect, beforeAll, afterAll, awaits, awaitsFor */
22+ /*global describe, it, expect, beforeAll, beforeEach, afterEach, afterAll, awaits, awaitsFor */
2323
2424define ( 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