2013-11-08 15:06:27 -05:00
module ( "Discourse.HeaderController" , {
setup : function ( ) {
2013-11-12 14:40:46 -05:00
sinon . stub ( Discourse , "ajax" ) ;
2013-11-08 15:06:27 -05:00
} ,
teardown : function ( ) {
2013-11-12 14:40:46 -05:00
Discourse . ajax . restore ( ) ;
2013-11-08 15:06:27 -05:00
}
} ) ;
test ( "showNotifications action" , function ( ) {
2013-11-12 14:40:46 -05:00
var resolveRequestWith ;
var request = new Ember . RSVP . Promise ( function ( resolve ) {
resolveRequestWith = resolve ;
} ) ;
2013-11-08 15:06:27 -05:00
var controller = Discourse . HeaderController . create ( ) ;
var viewSpy = {
showDropdownBySelector : sinon . spy ( )
} ;
Discourse . User . current ( ) . set ( "unread_notifications" , 1 ) ;
2013-11-12 14:40:46 -05:00
Ember . run ( function ( ) {
Discourse . ajax . withArgs ( "/notifications" ) . returns ( request ) ;
} ) ;
2013-11-08 15:06:27 -05:00
Ember . run ( function ( ) {
controller . send ( "showNotifications" , viewSpy ) ;
} ) ;
equal ( controller . get ( "notifications" ) , null , "notifications are null before data has finished loading" ) ;
equal ( Discourse . User . current ( ) . get ( "unread_notifications" ) , 1 , "current user's unread notifications count is not zeroed before data has finished loading" ) ;
ok ( viewSpy . showDropdownBySelector . notCalled , "dropdown with notifications is not shown before data has finished loading" ) ;
2013-11-12 14:40:46 -05:00
Ember . run ( function ( ) {
resolveRequestWith ( [ "notification" ] ) ;
} ) ;
2013-11-08 15:06:27 -05:00
deepEqual ( controller . get ( "notifications" ) , [ "notification" ] , "notifications are set correctly after data has finished loading" ) ;
equal ( Discourse . User . current ( ) . get ( "unread_notifications" ) , 0 , "current user's unread notifications count is zeroed after data has finished loading" ) ;
ok ( viewSpy . showDropdownBySelector . calledWith ( "#user-notifications" ) , "dropdown with notifications is shown after data has finished loading" ) ;
} ) ;