Merge "Tests: Migrate changeListeners/footerLink.test.js to node-qunit"

This commit is contained in:
jenkins-bot 2017-02-23 09:39:22 +00:00 committed by Gerrit Code Review
commit 178d429679
2 changed files with 103 additions and 87 deletions

View file

@ -0,0 +1,103 @@
var footerLink = require( '../../../src/changeListeners/footerLink' );
// Since footerLink manipulates the DOM, this test is, by necessity, an
// integration test.
QUnit.module( 'ext.popups/changeListeners/footerLink @integration', {
setup: function () {
var boundActions = {};
// Stub internal usage of mw.message
mediaWiki.message = function ( str ) {
return {
text: function () { return str; }
};
};
boundActions.showSettings = this.showSettingsSpy = this.sandbox.spy();
this.$footer = $( '<ul>' )
.attr( 'id', 'footer-places' )
.appendTo( document.body );
this.footerLinkChangeListener = footerLink( boundActions );
this.state = {
settings: {
shouldShowFooterLink: true
}
};
// A helper method, which should make the following tests more easily
// readable.
this.whenLinkPreviewsBoots = function () {
this.footerLinkChangeListener( undefined, this.state );
};
this.getLink = function () {
return this.$footer.find( 'li' );
};
},
teardown: function () {
this.$footer.remove();
}
} );
QUnit.test( 'it should append the link to the footer menu', function ( assert ) {
var $link;
assert.expect( 2 );
this.whenLinkPreviewsBoots();
$link = this.getLink();
assert.strictEqual( $link.length, 1 );
assert.equal(
$link.css( 'display' ),
'list-item',
'Creating the link and showing/hiding it aren\'t exclusive.'
);
} );
QUnit.test( 'it should show and hide the link', function ( assert ) {
var $link,
prevState;
assert.expect( 2 );
this.whenLinkPreviewsBoots();
$link = this.getLink();
assert.equal(
$link.css( 'display' ),
'list-item',
'Link is visible'
);
// ---
prevState = $.extend( true, {}, this.state );
this.state.settings.shouldShowFooterLink = false;
this.footerLinkChangeListener( prevState, this.state );
assert.equal(
$link.css( 'display' ),
'none',
'Link is NOT visible'
);
} );
QUnit.test( 'it should call the showSettings bound action creator', function ( assert ) {
var $link;
assert.expect( 1 );
this.whenLinkPreviewsBoots();
$link = this.getLink();
$link.click();
assert.ok( this.showSettingsSpy.called );
} );

View file

@ -1,87 +0,0 @@
( function ( mw, $ ) {
// Since mw.popups.changeListeners.footerLink manipulates the DOM, this test
// is, by necessity, an integration test.
QUnit.module( 'ext.popups/changeListeners/footerLink @integration', {
setup: function () {
var boundActions = {},
that = this;
boundActions.showSettings = that.showSettingsSpy = that.sandbox.spy();
that.$footer = $( '<ul>' )
.attr( 'id', 'footer-places' )
.appendTo( document.body );
that.footerLinkChangeListener =
mw.popups.changeListeners.footerLink( boundActions );
that.state = {
settings: {
shouldShowFooterLink: true
}
};
// A helper method, which should make the following tests more easily
// readable.
that.whenLinkPreviewsBoots = function () {
that.footerLinkChangeListener( undefined, that.state );
};
},
teardown: function () {
this.$footer.remove();
}
} );
QUnit.test( 'it should append the link to the footer menu', function ( assert ) {
var $link;
assert.expect( 2 );
this.whenLinkPreviewsBoots();
$link = this.$footer.find( 'li a' );
assert.strictEqual( $link.length, 1 );
assert.ok(
$link.is( ':visible' ),
'Creating the link and showing/hiding it aren\'t exclusive.'
);
} );
QUnit.test( 'it should show and hide the link', function ( assert ) {
var $link,
prevState;
assert.expect( 2 );
this.whenLinkPreviewsBoots();
$link = this.$footer.find( 'li a' );
assert.ok( $link.is( ':visible' ) );
// ---
prevState = $.extend( true, {}, this.state );
this.state.settings.shouldShowFooterLink = false;
this.footerLinkChangeListener( prevState, this.state );
assert.notOk( $link.is( ':visible' ) );
} );
QUnit.test( 'it should call the showSettings bound action creator', function ( assert ) {
var $link;
assert.expect( 1 );
this.whenLinkPreviewsBoots();
$link = this.$footer.find( 'li a' );
$link.click();
assert.ok( this.showSettingsSpy.called );
} );
}( mediaWiki, jQuery ) );