mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-12-01 17:26:36 +00:00
7c34b47993
Correct some options names and make minor adjustments to the
constructor function
Bug: T181348
Change-Id: Ia9fe9d2923b895d3dc530280e3987e27c88d3282
(cherry picked from commit 89909ccf53
)
70 lines
2.6 KiB
JavaScript
70 lines
2.6 KiB
JavaScript
( 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 );
|
||
}
|
||
} );
|
||
|
||
QUnit.test( '#setCount', function ( assert ) {
|
||
var initialClassExpectationsMet,
|
||
badge = new NotificationBadge( {
|
||
overlayManager: this.OverlayManager,
|
||
hasNotifications: true,
|
||
hasUnseenNotifications: true,
|
||
notificationCountRaw: 5
|
||
} );
|
||
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' );
|
||
badge.setCount( 105 );
|
||
assert.ok( badge.options.notificationCountRaw, 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 data-notification-count="2">۲</span></div></a></div>' )
|
||
} );
|
||
assert.ok( badge.options.notificationCountRaw, 2,
|
||
'Number is parsed from Eastern Arabic numerals' );
|
||
assert.ok( badge.options.notificationCountString, '۲',
|
||
'Number will be rendered in Eastern Arabic numerals' );
|
||
badge.setCount( 5 );
|
||
assert.ok( badge.options.notificationCountString, '۵',
|
||
'Number will be rendered in Eastern Arabic numerals' );
|
||
} );
|
||
|
||
QUnit.test( '#render [hasUnseenNotifications]', function ( assert ) {
|
||
var badge = new NotificationBadge( {
|
||
notificationCountRaw: 0,
|
||
overlayManager: this.OverlayManager,
|
||
hasNotifications: false,
|
||
hasUnseenNotifications: false
|
||
} );
|
||
assert.ok( badge.$el.find( '.mw-ui-icon' ).length === 1, 'A bell icon is visible' );
|
||
} );
|
||
|
||
QUnit.test( '#markAsSeen', function ( assert ) {
|
||
var badge = new NotificationBadge( {
|
||
notificationCountRaw: 2,
|
||
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 ) );
|