QUnit.test('it should handle the API request failing',function(assert){
vargetDeferred=this.getDeferred=$.Deferred(),
api={
get:function(){
returngetDeferred.promise();
}
},
fetchPreview=mw.popups.createGateway(api),
done=assert.async(1);
fetchPreview('Foo').fail(function(){
assert.ok(true);
done();
});
getDeferred.reject();
});
QUnit.test('it should fail if the response is empty',function(assert){
varcases,
done;
cases=[
{},
{
query:{}
},
{
query:{
pages:[]
}
}
];
done=assert.async(cases.length);
$.each(cases,function(_,data){
varfetchPreview=createGateway(data);
fetchPreview('Foo').fail(function(){
assert.ok(true);
done();
});
});
});
QUnit.test('it should handle an API response',function(assert){
vardone=assert.async(1),
fetchPreview;
fetchPreview=createGateway({
batchcomplete:true,
query:{
pages:[{
contentmodel:'wikitext',
extract:'Richard Paul "Rick" Astley (/\u02c8r\u026ak \u02c8\u00e6stli/; born 6 February 1966) is an English singer, songwriter, musician, and radio personality. His 1987 song, "Never Gonna Give You Up" was a No. 1 hit single in 25 countries. By the time of his retirement in 1993, Astley had sold approximately 40 million records worldwide.\nAstley made a comeback in 2007, becoming an Internet phenomenon when his video "Never Gonna Give You Up" became integral to the meme known as "rickrolling". Astley was voted "Best Act Ever" by Internet users at the...',
extract:'Richard Paul "Rick" Astley is an English singer, songwriter, musician, and radio personality. His 1987 song, "Never Gonna Give You Up" was a No. 1 hit single in 25 countries. By the time of his retirement in 1993, Astley had sold approximately 40 million records worldwide.\nAstley made a comeback in 2007, becoming an Internet phenomenon when his video "Never Gonna Give You Up" became integral to the meme known as "rickrolling". Astley was voted "Best Act Ever" by Internet users at the',