Sumit has uploaded a new change for review. https://gerrit.wikimedia.org/r/232195
Change subject: WikidataPageBanner improve qunit test ...................................................................... WikidataPageBanner improve qunit test Followup to I856690b82cacd295147f89a1f740ecac56c3176c. Adds more test cases to test_ext.WikidataPageBanner.positionBanner.js. Bug: T109319 Change-Id: I1a7bbb07fcc1ddde77572423885f0245f661c3bc --- M tests/qunit/ext.WikidataPageBanner.positionBanner/test_ext.WikidataPageBanner.positionBanner.js 1 file changed, 46 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataPageBanner refs/changes/95/232195/1 diff --git a/tests/qunit/ext.WikidataPageBanner.positionBanner/test_ext.WikidataPageBanner.positionBanner.js b/tests/qunit/ext.WikidataPageBanner.positionBanner/test_ext.WikidataPageBanner.positionBanner.js index 1d4be5b..e6463bc 100644 --- a/tests/qunit/ext.WikidataPageBanner.positionBanner/test_ext.WikidataPageBanner.positionBanner.js +++ b/tests/qunit/ext.WikidataPageBanner.positionBanner/test_ext.WikidataPageBanner.positionBanner.js @@ -1,6 +1,6 @@ ( function ( mw, $ ) { QUnit.module( 'ext.WikidataPageBanner.positionBanner', QUnit.newMwEnvironment() ); - QUnit.test( 'testFocus', 6, function( assert ) { + QUnit.test( 'testFocus', 10, function( assert ) { this.$wpbBannerImageContainer = $( '<div/>', { width: 600, height: 300 @@ -15,21 +15,60 @@ this.$wpbBannerImage.data( 'pos-x', 0 ); this.$wpbBannerImage.data( 'pos-y', 0 ); mw.wpb.positionBanner( this.$wpbBannerImageContainer ); - assert.equal( this.$wpbBannerImage.css( 'margin-left' ), '-150px' ); - assert.equal( this.$wpbBannerImage.css( 'margin-top' ), '-100px' ); + assert.equal( this.$wpbBannerImage.css( 'margin-left' ), '-150px', + 'Banner left should shift -150px for focus' ); + assert.equal( this.$wpbBannerImage.css( 'margin-top' ), '-100px', + 'Banner top should shift -100px for focus' ); // set test focus points + // this case tests the case where origin is ignored because a positive margin would appear this.$wpbBannerImage.data( 'pos-x', -1 ); this.$wpbBannerImage.data( 'pos-y', -1 ); mw.wpb.positionBanner( this.$wpbBannerImageContainer ); - assert.equal( this.$wpbBannerImage.css( 'margin-left' ), '0px' ); - assert.equal( this.$wpbBannerImage.css( 'margin-top' ), '0px' ); + assert.equal( this.$wpbBannerImage.css( 'margin-left' ), '0px', + 'Banner left should not leave positive margin for focus' ); + assert.equal( this.$wpbBannerImage.css( 'margin-top' ), '0px', + 'Banner top should not leave positive margin for focus' ); // set test focus points this.$wpbBannerImage.data( 'pos-x', 0.5 ); this.$wpbBannerImage.data( 'pos-y', undefined ); mw.wpb.positionBanner( this.$wpbBannerImageContainer ); - assert.equal( this.$wpbBannerImage.css( 'margin-left' ), '-300px' ); - assert.equal( this.$wpbBannerImage.css( 'margin-top' ), '0px' ); + assert.equal( this.$wpbBannerImage.css( 'margin-left' ), '-300px', + 'Banner left should shift -300px for focus' ); + assert.equal( this.$wpbBannerImage.css( 'margin-top' ), '0px', + 'Banner top should not leave positive margin for focus' ); + + this.$wpbBannerImageContainer = $( '<div/>', { + width: 1500, + height: 300 + } ); + this.$wpbBannerImage = $( '<img/>', { + 'class': 'wpb-banner-image', + width: 1900, + height: 400 + } ); + this.$wpbBannerImageContainer.append( this.$wpbBannerImage ); + // set test focus points + // position in vertical direction is ignored after a limit because of too much negative + // margin + this.$wpbBannerImage.data( 'pos-x', 0 ); + this.$wpbBannerImage.data( 'pos-y', 1 ); + mw.wpb.positionBanner( this.$wpbBannerImageContainer ); + assert.equal( this.$wpbBannerImage.css( 'margin-left' ), '-200px', + 'Banner left should shift -390px for focus' ); + assert.equal( this.$wpbBannerImage.css( 'margin-top' ), '-100px', + 'Banner top should shift -100px only for to not leave too much negative margin' ); + + // set test focus points + // Position in vertical direction is ignored because of positive margin + this.$wpbBannerImage.data( 'pos-x', 0.2 ); + this.$wpbBannerImage.data( 'pos-y', -1 ); + mw.wpb.positionBanner( this.$wpbBannerImageContainer ); + assert.equal( this.$wpbBannerImage.css( 'margin-left' ), '-390px', + 'Banner left should shift -240px for focus' ); + assert.equal( this.$wpbBannerImage.css( 'margin-top' ), '0px', + 'Banner top should not leave positive margin for focus' ); + } ); } )( mediaWiki, jQuery ); -- To view, visit https://gerrit.wikimedia.org/r/232195 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1a7bbb07fcc1ddde77572423885f0245f661c3bc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikidataPageBanner Gerrit-Branch: master Gerrit-Owner: Sumit <asthana.sumi...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits