pavlov.specify.globalApi = true;
pavlov.specify( "News Aggregator", function() {
describe( "User Interactions", function() {
var button = $( "#btnRefresh" ),
isUpdated = false, news,
newsUpdatedCallback = function( data ) {
isUpdated = true;
news = data;
};
before( function() {
isUpdated = false;
hackerNews.init();
amplify.request.define( "getNews", function( settings ) {
settings.success({
status: "success",
items: [
{ commentCount: 5, id: 1, points: 50, postedAgo: "1 hour ago", postedBy: "davidedicillo", title: "Five four three...", url: "http://techcrunch.com/5" },
{ commentCount: 4, id: 2, points: 40, postedAgo: "2 hour ago", postedBy: "davidedicillo", title: "Four three two...", url: "http://techcrunch.com/4" },
{ commentCount: 3, id: 3, points: 30, postedAgo: "3 hour ago", postedBy: "davidedicillo", title: "Three two one...", url: "http://techcrunch.com/3" },
{ commentCount: 2, id: 4, points: 20, postedAgo: "4 hour ago", postedBy: "davidedicillo", title: "Two, one, zero...", url: "http://techcrunch.com/2" },
{ commentCount: 1, id: 5, points: 10, postedAgo: "5 hour ago", postedBy: "davidedicillo", title: "One, zero, negative one...", url: "http://techcrunch.com/1" }
]
});
});
amplify.subscribe( "news.updated", newsUpdatedCallback );
});
after( function() {
amplify.unsubscribe( newsUpdatedCallback );
});
it( "should publish a news updated message", function() {
button.trigger( "click" );
stop();
setTimeout( function() {
start();
assert( isUpdated ).isTrue();
}, 2000 );
});
it( "should return 5 news items", function() {
button.trigger( "click" );
stop();
setTimeout( function() {
start();
assert( news ).isDefined();
assert( news.items.length ).isEqualTo(5);
}, 2000 );
});
});
});