mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-23 23:44:53 +00:00
Fix issue with tab visibility
Danny noticed a bug where if both tabs have unread notifications, then when opening the overlay and clicking on the alerts tab, the user would be reverted back to the messages tab. Test stops this from happening again. Change-Id: I6bbbbf61251957336de8856201412fa3569ab22d
This commit is contained in:
parent
24e8a34c50
commit
bee2fe3af1
|
@ -185,10 +185,6 @@
|
|||
};
|
||||
|
||||
EchoOverlay.prototype = {
|
||||
/**
|
||||
* @var string the name of the tab that is currently active
|
||||
*/
|
||||
activeTabName: 'alert',
|
||||
/**
|
||||
* @var array a list of EchoOverlayTabs
|
||||
*/
|
||||
|
@ -275,7 +271,7 @@
|
|||
_showTabList: function( tab ) {
|
||||
var $lists = this.$el.find( '.mw-echo-notifications' ).hide();
|
||||
|
||||
this.activeTabName = tab.name;
|
||||
this._activeTab = tab;
|
||||
$lists.each( function() {
|
||||
if ( $( this ).data( 'tab' ).name === tab.name ) {
|
||||
$( this ).show();
|
||||
|
@ -316,7 +312,7 @@
|
|||
self._showTabList( $this.data( 'tab' ) );
|
||||
} )
|
||||
.data( 'tab', echoTab )
|
||||
.addClass( echoTab.name === self.activeTabName ? 'mw-ui-active' : 'mw-ui-quiet' )
|
||||
.addClass( echoTab.name === self._activeTab.name ? 'mw-ui-active' : 'mw-ui-quiet' )
|
||||
.text( label ).appendTo( $li );
|
||||
} );
|
||||
return $ul;
|
||||
|
@ -333,7 +329,7 @@
|
|||
_getTitleElement: function() {
|
||||
var $title = $( '<div>' ).addClass( 'mw-echo-overlay-title' )
|
||||
.append( this._getTabsElement() );
|
||||
this._showTabList( this.tabs[0] );
|
||||
this._showTabList( this._activeTab );
|
||||
return $title;
|
||||
},
|
||||
|
||||
|
@ -366,7 +362,7 @@
|
|||
self.tabs.push( tab );
|
||||
self.notificationCount.all += notifications[tabOptions.name].index.length;
|
||||
} );
|
||||
this.activeTabName = this.tabs[0].name;
|
||||
this._activeTab = this.tabs[0];
|
||||
|
||||
$overlay.prepend( this._getTitleElement() );
|
||||
$overlay.append( this._getFooterElement() );
|
||||
|
|
|
@ -279,4 +279,29 @@
|
|||
'Check the label has a count in it and reflects the total unread and not the shown unread' );
|
||||
assert.strictEqual( $overlay.find( '.mw-echo-unread' ).length, 8, 'There are 8 unread notifications.' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Switching tabs visibility', 4, function( assert ) {
|
||||
var $overlay;
|
||||
|
||||
this.sandbox.stub( mw.echo.overlay, 'api', new this.ApiStub( 2 ) );
|
||||
mw.echo.overlay.buildOverlay( function( $o ) {
|
||||
// put in dom so we can do visibility tests
|
||||
$overlay = $o.appendTo( '#qunit-fixture' );
|
||||
} );
|
||||
|
||||
// Test initial state
|
||||
assert.strictEqual( $overlay.find( '.mw-echo-notifications' ).eq( 0 ).is( ':visible' ),
|
||||
true, 'First tab is visible.' );
|
||||
assert.strictEqual( $overlay.find( '.mw-echo-notifications' ).eq( 1 ).is( ':visible' ),
|
||||
false, 'Second tab starts hidden.' );
|
||||
|
||||
// Switch to second tab
|
||||
$overlay.find( '.mw-echo-overlay-title li a' ).eq( 1 ).trigger( 'click' );
|
||||
|
||||
// check new tab visibility
|
||||
assert.strictEqual( $overlay.find( '.mw-echo-notifications' ).eq( 0 ).is( ':visible' ),
|
||||
false, 'First tab is now hidden.' );
|
||||
assert.strictEqual( $overlay.find( '.mw-echo-notifications' ).eq( 1 ).is( ':visible' ),
|
||||
true, 'Second tab is now visible.' );
|
||||
} );
|
||||
}( jQuery, mediaWiki ) );
|
||||
|
|
Loading…
Reference in a new issue