' ).css( 'height', 50 ).appendTo( $container ),
fakeLocalStorage = { getItem : $.noop, setItem : $.noop },
scroller = new mw.mmv.ui.MetadataPanelScroller( $container, $aboveFold, fakeLocalStorage),
keydown = $.Event( 'keydown' );
stubScrollFunctions( this.sandbox, scroller );
this.sandbox.stub( fakeLocalStorage, 'setItem' );
// First phase of the test: up and down arrows
scroller.hasAnimatedMetadata = false;
scroller.attach();
assert.strictEqual( $.scrollTo().scrollTop(), 0, 'scrollTo scrollTop should be set to 0' );
assert.ok( !fakeLocalStorage.setItem.called, 'The metadata hasn\'t been open yet, no entry in localStorage' );
keydown.which = 38; // Up arrow
scroller.keydown( keydown );
this.clock.tick( scroller.toggleScrollDuration );
assert.ok( fakeLocalStorage.setItem.calledWithExactly( 'mmv.hasOpenedMetadata', true ), 'localStorage knows that the metadata has been open' );
keydown.which = 40; // Down arrow
scroller.keydown( keydown );
this.clock.tick( scroller.toggleScrollDuration );
assert.strictEqual( $.scrollTo().scrollTop(), 0,
'scrollTo scrollTop should be set to 0 after pressing down arrow' );
scroller.$dragIcon.click();
this.clock.tick( scroller.toggleScrollDuration );
scroller.$dragIconBottom.click();
this.clock.tick( scroller.toggleScrollDuration );
assert.strictEqual( $.scrollTo().scrollTop(), 0,
'scrollTo scrollTop should be set to 0 after clicking the chevron twice' );
// 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( $.scrollTo().scrollTop(), 0, 'Page scrollTop should be set to 0' );
// Scroll down to check that the scrollTop memory doesn't affect prev/next (bug 59861)
$.scrollTo( 20, 0 );
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( $.scrollTo().scrollTop(), 20, 'Page scrollTop should be set to 20' );
scroller.unattach();
} );
QUnit.test( 'Metadata scroll logging', 6, function ( assert ) {
var $qf = $( '#qunit-fixture' ),
$container = $( '
' ).css( 'height', 100 ).appendTo( $qf ),
$aboveFold = $( '
' ).css( 'height', 50 ).appendTo( $container ),
scroller = new mw.mmv.ui.MetadataPanelScroller( $container, $aboveFold ),
keydown = $.Event( 'keydown' );
stubScrollFunctions( this.sandbox, scroller );
this.sandbox.stub( mw.mmv.actionLogger, 'log' );
keydown.which = 38; // Up arrow
scroller.keydown( keydown );
this.clock.tick( scroller.toggleScrollDuration );
assert.ok( mw.mmv.actionLogger.log.calledWithExactly( 'metadata-open' ), 'Opening keypress logged' );
mw.mmv.actionLogger.log.reset();
keydown.which = 38; // Up arrow
scroller.keydown( keydown );
this.clock.tick( scroller.toggleScrollDuration );
assert.ok( mw.mmv.actionLogger.log.calledWithExactly( 'metadata-close' ), 'Closing keypress logged' );
mw.mmv.actionLogger.log.reset();
keydown.which = 40; // Down arrow
scroller.keydown( keydown );
this.clock.tick( scroller.toggleScrollDuration );
assert.ok( mw.mmv.actionLogger.log.calledWithExactly( 'metadata-open' ), 'Opening keypress logged' );
mw.mmv.actionLogger.log.reset();
keydown.which = 40; // Down arrow
scroller.keydown( keydown );
this.clock.tick( scroller.toggleScrollDuration );
assert.ok( mw.mmv.actionLogger.log.calledWithExactly( 'metadata-close' ), 'Closing keypress logged' );
mw.mmv.actionLogger.log.reset();
scroller.$dragIcon.click();
this.clock.tick( scroller.toggleScrollDuration );
assert.ok( mw.mmv.actionLogger.log.calledWithExactly( 'metadata-open' ), 'Opening click logged' );
mw.mmv.actionLogger.log.reset();
scroller.$dragIconBottom.click();
this.clock.tick( scroller.toggleScrollDuration );
assert.ok( mw.mmv.actionLogger.log.calledWithExactly( 'metadata-close' ), 'Closing click logged' );
mw.mmv.actionLogger.log.reset();
} );
}( mediaWiki, jQuery ) );