2017-07-12 15:12:40 +00:00
|
|
|
|
( function ( M ) {
|
2019-02-07 16:34:18 +00:00
|
|
|
|
var OverlayManager = M.require( 'mobile.startup' ).OverlayManager,
|
2019-07-02 21:10:10 +00:00
|
|
|
|
NotificationBadge = require( '../../../resources/skins.minerva.scripts/NotificationBadge.js' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
|
|
QUnit.module( 'Minerva NotificationBadge', {
|
2018-09-11 13:13:41 +00:00
|
|
|
|
beforeEach: function () {
|
2019-03-18 22:04:54 +00:00
|
|
|
|
this.OverlayManager = OverlayManager.getSingleton();
|
2017-07-12 15:12:40 +00:00
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
|
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-11-28 19:46:55 +00:00
|
|
|
|
notificationCountRaw: 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' );
|
2018-09-11 13:13:41 +00:00
|
|
|
|
assert.strictEqual( 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 );
|
2018-09-11 13:13:41 +00:00
|
|
|
|
assert.strictEqual( badge.options.notificationCountRaw, 100, 'Number is capped to 100.' );
|
2017-10-18 18:28:37 +00:00
|
|
|
|
} );
|
|
|
|
|
|
2018-09-12 21:04:18 +00:00
|
|
|
|
QUnit.test( '#setCount (Eastern Arabic numerals)', function ( assert ) {
|
|
|
|
|
var badge;
|
|
|
|
|
|
|
|
|
|
this.sandbox.stub( mw.language, 'convertNumber' )
|
|
|
|
|
.withArgs( 2 ).returns( '۲' )
|
|
|
|
|
.withArgs( 5 ).returns( '۵' );
|
2019-07-02 21:10:10 +00:00
|
|
|
|
this.sandbox.stub( mw, 'message' )
|
|
|
|
|
.withArgs( 'echo-badge-count', '۵' ).returns( { text: function () { return '۵'; } } )
|
|
|
|
|
.withArgs( 'echo-badge-count', '۲' ).returns( { text: function () { return '۲'; } } );
|
2018-09-12 21:04:18 +00:00
|
|
|
|
|
|
|
|
|
badge = new NotificationBadge( {
|
2017-10-18 18:28:37 +00:00
|
|
|
|
overlayManager: this.OverlayManager,
|
2017-11-28 19:46:55 +00:00
|
|
|
|
el: $( '<div><a title="n" href="/" class="notification-unseen"><div class="circle" ><span data-notification-count="2">۲</span></div></a></div>' )
|
2017-10-18 18:28:37 +00:00
|
|
|
|
} );
|
2018-09-11 13:13:41 +00:00
|
|
|
|
assert.strictEqual( badge.options.notificationCountRaw, 2,
|
2017-10-18 18:28:37 +00:00
|
|
|
|
'Number is parsed from Eastern Arabic numerals' );
|
2018-09-11 13:13:41 +00:00
|
|
|
|
assert.strictEqual( badge.options.notificationCountString, '۲',
|
2017-10-18 18:28:37 +00:00
|
|
|
|
'Number will be rendered in Eastern Arabic numerals' );
|
|
|
|
|
badge.setCount( 5 );
|
2018-09-11 13:13:41 +00:00
|
|
|
|
assert.strictEqual( badge.options.notificationCountString, '۵',
|
2017-10-18 18:28:37 +00:00
|
|
|
|
'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-11-28 19:46:55 +00:00
|
|
|
|
notificationCountRaw: 0,
|
2017-07-12 15:12:40 +00:00
|
|
|
|
overlayManager: this.OverlayManager,
|
|
|
|
|
hasNotifications: false,
|
|
|
|
|
hasUnseenNotifications: false
|
|
|
|
|
} );
|
2018-09-11 13:13:41 +00:00
|
|
|
|
assert.strictEqual( badge.$el.find( '.mw-ui-icon' ).length, 1, 'A bell icon is visible' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
} );
|
|
|
|
|
|
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-11-28 19:46:55 +00:00
|
|
|
|
notificationCountRaw: 2,
|
2017-07-12 15:12:40 +00:00
|
|
|
|
overlayManager: this.OverlayManager,
|
|
|
|
|
hasNotifications: true,
|
|
|
|
|
hasUnseenNotifications: true
|
|
|
|
|
} );
|
|
|
|
|
// Badge resets counter to zero
|
|
|
|
|
badge.setCount( 0 );
|
2018-09-11 13:13:41 +00:00
|
|
|
|
assert.strictEqual( badge.$el.find( '.mw-ui-icon' ).length, 0, 'The bell icon is not visible' );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
badge.markAsSeen();
|
2018-09-11 13:13:41 +00:00
|
|
|
|
assert.strictEqual( badge.$el.find( '.notification-unseen' ).length, 0,
|
2017-07-12 15:12:40 +00:00
|
|
|
|
'Unseen class disappears after markAsSeen called.' );
|
|
|
|
|
} );
|
|
|
|
|
}( mw.mobileFrontend ) );
|