File tree Expand file tree Collapse file tree
test/javascripts/controllers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- var server ;
2-
31module ( "Discourse.HeaderController" , {
42 setup : function ( ) {
5- server = sinon . fakeServer . create ( ) ;
3+ sinon . stub ( Discourse , "ajax" ) ;
64 } ,
75
86 teardown : function ( ) {
9- server . restore ( ) ;
7+ Discourse . ajax . restore ( ) ;
108 }
119} ) ;
1210
1311test ( "showNotifications action" , function ( ) {
12+ var resolveRequestWith ;
13+ var request = new Ember . RSVP . Promise ( function ( resolve ) {
14+ resolveRequestWith = resolve ;
15+ } ) ;
16+
17+
1418 var controller = Discourse . HeaderController . create ( ) ;
1519 var viewSpy = {
1620 showDropdownBySelector : sinon . spy ( )
1721 } ;
1822 Discourse . User . current ( ) . set ( "unread_notifications" , 1 ) ;
19- server . respondWith ( "/notifications" , [ 200 , { "Content-Type" : "application/json" } , '["notification"]' ] ) ;
23+ Ember . run ( function ( ) {
24+ Discourse . ajax . withArgs ( "/notifications" ) . returns ( request ) ;
25+ } ) ;
2026
2127
2228 Ember . run ( function ( ) {
@@ -28,7 +34,9 @@ test("showNotifications action", function() {
2834 ok ( viewSpy . showDropdownBySelector . notCalled , "dropdown with notifications is not shown before data has finished loading" ) ;
2935
3036
31- server . respond ( ) ;
37+ Ember . run ( function ( ) {
38+ resolveRequestWith ( [ "notification" ] ) ;
39+ } ) ;
3240
3341 deepEqual ( controller . get ( "notifications" ) , [ "notification" ] , "notifications are set correctly after data has finished loading" ) ;
3442 equal ( Discourse . User . current ( ) . get ( "unread_notifications" ) , 0 , "current user's unread notifications count is zeroed after data has finished loading" ) ;
You can’t perform that action at this time.
0 commit comments