' ).css( 'height', 50 ).appendTo( $container ),
fakeLocalStorage = mw.mmv.testHelpers.createLocalStorage( {
getItem: this.sandbox.stub().returns( null ),
setItem: function () {}
} ),
scroller = new mw.mmv.ui.MetadataPanelScroller( $container, $aboveFold, fakeLocalStorage ),
keydown = $.Event( 'keydown' );
stubScrollFunctions( this.sandbox, scroller );
this.sandbox.stub( fakeLocalStorage.store, 'setItem' );
// First phase of the test: up and down arrows
scroller.hasAnimatedMetadata = false;
scroller.attach();
assert.strictEqual( $window.scrollTop(), 0, 'scrollTop should be set to 0' );
assert.strictEqual( fakeLocalStorage.store.setItem.called, false, 'The metadata hasn\'t been open yet, no entry in localStorage' );
keydown.which = 38; // Up arrow
scroller.keydown( keydown );
assert.strictEqual( fakeLocalStorage.store.setItem.calledWithExactly( 'mmv.hasOpenedMetadata', '1' ), true, 'localStorage knows that the metadata has been open' );
keydown.which = 40; // Down arrow
scroller.keydown( keydown );
assert.strictEqual( $window.scrollTop(), 0,
'scrollTop should be set to 0 after pressing down arrow' );
// Unattach lightbox from document
scroller.unattach();
// Second phase of the test: scroll memory
scroller.attach();
// To make sure that the details are out of view, the lightbox is supposed to scroll to the top when open
assert.strictEqual( $window.scrollTop(), 0, 'Page scrollTop should be set to 0' );
// Scroll down to check that the scrollTop memory doesn't affect prev/next (bug 59861)
$window.scrollTop( 20 );
this.clock.tick( 100 );
// This extra attach() call simulates the effect of prev/next seen in bug 59861
scroller.attach();
// The lightbox was already open at this point, the scrollTop should be left untouched
assert.strictEqual( $window.scrollTop(), 20, 'Page scrollTop should be set to 20' );
scroller.unattach();
} );
QUnit.test( 'Metadata scroll logging', function ( assert ) {
var $qf = $( '#qunit-fixture' ),
$container = $( '
' ).css( 'height', 100 ).appendTo( $qf ),
$aboveFold = $( '
' ).css( 'height', 50 ).appendTo( $container ),
localStorage = mw.mmv.testHelpers.getFakeLocalStorage(),
scroller = new mw.mmv.ui.MetadataPanelScroller( $container, $aboveFold, localStorage ),
keydown = $.Event( 'keydown' );
stubScrollFunctions( this.sandbox, scroller );
this.sandbox.stub( mw.mmv.actionLogger, 'log' );
keydown.which = 38; // Up arrow
scroller.keydown( keydown );
assert.strictEqual( mw.mmv.actionLogger.log.calledWithExactly( 'metadata-open' ), true, 'Opening keypress logged' );
mw.mmv.actionLogger.log.reset();
keydown.which = 38; // Up arrow
scroller.keydown( keydown );
assert.strictEqual( mw.mmv.actionLogger.log.calledWithExactly( 'metadata-close' ), true, 'Closing keypress logged' );
mw.mmv.actionLogger.log.reset();
keydown.which = 40; // Down arrow
scroller.keydown( keydown );
assert.strictEqual( mw.mmv.actionLogger.log.calledWithExactly( 'metadata-open' ), true, 'Opening keypress logged' );
mw.mmv.actionLogger.log.reset();
keydown.which = 40; // Down arrow
scroller.keydown( keydown );
assert.strictEqual( mw.mmv.actionLogger.log.calledWithExactly( 'metadata-close' ), true, 'Closing keypress logged' );
mw.mmv.actionLogger.log.reset();
} );
}() );