2017-07-12 15:12:40 +00:00
|
|
|
|
( function ( M ) {
|
|
|
|
|
var OverlayManager = M.require( 'mobile.startup/OverlayManager' ),
|
|
|
|
|
NotificationBadge = M.require( 'skins.minerva.notifications/NotificationBadge' );
|
|
|
|
|
|
|
|
|
|
QUnit.module( 'Minerva NotificationBadge', {
|
|
|
|
|
setup: function () {
|
|
|
|
|
this.router = require( 'mediawiki.router' );
|
|
|
|
|
this.OverlayManager = new OverlayManager( this.router );
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
|
2017-08-31 13:44:58 +00:00
|
|
|
|
QUnit.test( '#setCount', function ( assert ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
|
var initialClassExpectationsMet,
|
|
|
|
|
badge = new NotificationBadge( {
|
|
|
|
|
overlayManager: this.OverlayManager,
|
|
|
|
|
hasNotifications: true,
|
|
|
|
|
hasUnseenNotifications: true,
|
2017-10-18 18:28:37 +00:00
|
|
|
|
notificationCountRawRaw: 5
|
2017-07-12 15:12:40 +00:00
|
|
|
|
} );
|
|
|
|
|
initialClassExpectationsMet = badge.$el.find( '.mw-ui-icon' ).length === 0 &&
|
|
|
|
|
badge.$el.find( '.zero' ).length === 0;
|
|
|
|
|
|
|
|
|
|
badge.setCount( 0 );
|
|
|
|
|
assert.ok( initialClassExpectationsMet, 'No icon and no zero class' );
|
|
|
|
|
assert.ok( badge.$el.find( '.zero' ).length === 1, 'A zero class is present on the badge' );
|
2017-10-18 18:28:37 +00:00
|
|
|
|
badge.setCount( 105 );
|
|
|
|
|
assert.ok( badge.options.notificationCountRawRaw, 100,
|
|
|
|
|
'Number is capped to 100.' );
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
QUnit.test( '#setCount (Eastern Arabic numerals)', function ( assert ) {
|
|
|
|
|
var badge = new NotificationBadge( {
|
|
|
|
|
overlayManager: this.OverlayManager,
|
|
|
|
|
el: $( '<div><a title="n" href="/" class="notification-unseen"><div class="circle"><span>۲</span></div></a></div>' )
|
|
|
|
|
} );
|
|
|
|
|
assert.ok( badge.options.notificationCountRawRaw, 2,
|
|
|
|
|
'Number is parsed from Eastern Arabic numerals' );
|
|
|
|
|
assert.ok( badge.options.notificationCountRawRawString, '۲',
|
|
|
|
|
'Number will be rendered in Eastern Arabic numerals' );
|
|
|
|
|
badge.setCount( 5 );
|
|
|
|
|
assert.ok( badge.options.notificationCountRawRawString, '۵',
|
|
|
|
|
'Number will be rendered in Eastern Arabic numerals' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
} );
|
|
|
|
|
|
2017-08-31 13:44:58 +00:00
|
|
|
|
QUnit.test( '#render [hasUnseenNotifications]', function ( assert ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
|
var badge = new NotificationBadge( {
|
2017-10-18 18:28:37 +00:00
|
|
|
|
notificationCountRawRaw: 0,
|
2017-07-12 15:12:40 +00:00
|
|
|
|
overlayManager: this.OverlayManager,
|
|
|
|
|
hasNotifications: false,
|
|
|
|
|
hasUnseenNotifications: false
|
|
|
|
|
} );
|
|
|
|
|
assert.ok( badge.$el.find( '.mw-ui-icon' ).length === 1, 'A bell icon is visible' );
|
|
|
|
|
} );
|
|
|
|
|
|
2017-08-31 13:44:58 +00:00
|
|
|
|
QUnit.test( '#markAsSeen', function ( assert ) {
|
2017-07-12 15:12:40 +00:00
|
|
|
|
var badge = new NotificationBadge( {
|
2017-10-18 18:28:37 +00:00
|
|
|
|
notificationCountRawRaw: 2,
|
2017-07-12 15:12:40 +00:00
|
|
|
|
overlayManager: this.OverlayManager,
|
|
|
|
|
hasNotifications: true,
|
|
|
|
|
hasUnseenNotifications: true
|
|
|
|
|
} );
|
|
|
|
|
// Badge resets counter to zero
|
|
|
|
|
badge.setCount( 0 );
|
|
|
|
|
assert.ok( badge.$el.find( '.mw-ui-icon' ).length === 0, 'The bell icon is not visible' );
|
|
|
|
|
badge.markAsSeen();
|
|
|
|
|
assert.ok( badge.$el.find( '.notification-unseen' ).length === 0,
|
|
|
|
|
'Unseen class disappears after markAsSeen called.' );
|
|
|
|
|
} );
|
|
|
|
|
}( mw.mobileFrontend ) );
|