1919 *
2020 */
2121
22- /*global describe, it, expect, beforeAll, afterAll, awaits, Phoenix */
22+ /*global describe, it, expect, beforeAll, afterAll, awaits, awaitsFor */
2323
2424define ( function ( require , exports , module ) {
2525 // Recommended to avoid reloading the integration test window Phoenix instance for each test.
@@ -40,6 +40,12 @@ define(function (require, exports, module) {
4040 await SpecRunnerUtils . loadProjectInTestWindow ( testPath ) ;
4141 } , 30000 ) ;
4242
43+ async function _waitForBannerShown ( ) {
44+ await awaitsFor ( function ( ) {
45+ return testWindow . $ ( '#notification-bar' ) . is ( ":visible" ) ;
46+ } , "banner to be shown" ) ;
47+ }
48+
4349 afterAll ( async function ( ) {
4450 testWindow = null ;
4551 // comment out below line if you want to debug the test window post running tests
@@ -182,5 +188,86 @@ define(function (require, exports, module) {
182188 banner . _renderNotifications ( notification ) ;
183189 expect ( testWindow . $ ( id ) . length ) . toEqual ( 0 ) ;
184190 } ) ;
191+
192+ it ( "Should apply custom filter to block notification" , async function ( ) {
193+ banner . cleanNotificationBanner ( ) ;
194+ banner . registerCustomFilter ( async ( ) => false ) ;
195+
196+ const { notification, id} = getRandomNotification ( "all" , true ) ;
197+ banner . _renderNotifications ( notification ) ;
198+ await awaits ( 50 ) ;
199+
200+ expect ( testWindow . $ ( '#notification-bar' ) . is ( ":visible" ) ) . toBe ( false ) ;
201+ expect ( testWindow . $ ( id ) . length ) . toEqual ( 0 ) ;
202+
203+ // Cleanup: remove custom filter
204+ banner . registerCustomFilter ( null ) ;
205+ } ) ;
206+
207+ it ( "Should apply custom filter to allow notification" , async function ( ) {
208+ banner . cleanNotificationBanner ( ) ;
209+ banner . registerCustomFilter ( async ( ) => true ) ;
210+
211+ const { notification, id} = getRandomNotification ( "all" , true ) ;
212+ banner . _renderNotifications ( notification ) ;
213+ await _waitForBannerShown ( ) ;
214+
215+ expect ( testWindow . $ ( id ) . length ) . toEqual ( 1 ) ;
216+
217+ // Cleanup
218+ banner . registerCustomFilter ( null ) ;
219+ banner . cleanNotificationBanner ( ) ;
220+ } ) ;
221+
222+ it ( "Should pass correct parameters to custom filter" , async function ( ) {
223+ banner . cleanNotificationBanner ( ) ;
224+ let receivedNotification , receivedID ;
225+
226+ const { notification} = getRandomNotification ( "all" , true ) ;
227+ const expectedID = Object . keys ( notification ) [ 0 ] ;
228+
229+ banner . registerCustomFilter ( async ( notif , notifID ) => {
230+ receivedNotification = notif ;
231+ receivedID = notifID ;
232+ return true ;
233+ } ) ;
234+
235+ banner . _renderNotifications ( notification ) ;
236+ await _waitForBannerShown ( ) ;
237+
238+ expect ( receivedID ) . toEqual ( expectedID ) ;
239+ expect ( receivedNotification ) . toEqual ( notification [ expectedID ] ) ;
240+
241+ // Cleanup
242+ banner . registerCustomFilter ( null ) ;
243+ banner . cleanNotificationBanner ( ) ;
244+ } ) ;
245+
246+ it ( "Should apply custom filter on reRenderNotifications" , async function ( ) {
247+ banner . cleanNotificationBanner ( ) ;
248+
249+ const { notification, id} = getRandomNotification ( "all" , true ) ;
250+
251+ // Set cache and render
252+ banner . _setBannerCache ( notification ) ;
253+ banner . _renderNotifications ( notification ) ;
254+ await _waitForBannerShown ( ) ;
255+ expect ( testWindow . $ ( id ) . length ) . toEqual ( 1 ) ;
256+
257+ banner . cleanNotificationBanner ( ) ;
258+
259+ // Set filter to block
260+ banner . registerCustomFilter ( async ( ) => false ) ;
261+
262+ // Re-render should not show notification due to filter
263+ banner . reRenderNotifications ( ) ;
264+ await awaits ( 50 ) ;
265+ expect ( testWindow . $ ( '#notification-bar' ) . is ( ":visible" ) ) . toBe ( false ) ;
266+ expect ( testWindow . $ ( id ) . length ) . toEqual ( 0 ) ;
267+
268+ // Cleanup
269+ banner . registerCustomFilter ( null ) ;
270+ banner . cleanNotificationBanner ( ) ;
271+ } ) ;
185272 } ) ;
186273} ) ;
0 commit comments