Commit 340c9f0

mo khan <mo@mokhan.ca>
2015-06-23 01:26:21
add specs for the google button view.
1 parent 9f64608
Changed files (3)
app/assets/javascripts/views/google_sync_button.js.coffee
@@ -1,13 +1,16 @@
 Stronglifters.GoogleSyncButton = Ractive.extend
   template: "<button on-click='synchronize'><i class='fa {{icon}}'></i> {{text}}</button>",
   oninit: ->
-    @set(text: 'Sync With Google', icon: 'fa-camera-retro')
-    @drive = new Stronglifters.GoogleDrive
-      client_id: @get('client_id')
-      drive_upload_path: @get('drive_upload_path')
+    @set(text: 'Sync with Google', icon: 'fa-camera-retro')
     @on 'synchronize', (event) ->
-      @synchronize(@drive)
+      @synchronize()
 
-  synchronize: (drive) ->
+  synchronize: ->
     @set(text: 'Syncing...', icon: 'fa-spin fa-spinner')
-    drive.syncFile()
+    @drive().syncFile()
+
+  drive: ->
+    @drive ||= new Stronglifters.GoogleDrive
+      client_id: @get('client_id')
+      drive_upload_path: @get('drive_upload_path')
+
spec/javascripts/views/google_sync_button_spec.js.coffee
@@ -3,10 +3,25 @@ describe "GoogleSyncButton", ->
   beforeEach ->
     @subject = new Stronglifters.GoogleSyncButton()
 
+  it 'displays the correct button text', ->
+    expect(@subject.get('text')).toEqual("Sync with Google")
+
   describe "synchronize", ->
+    beforeEach ->
+      @drive = { syncFile: null }
+      spyOn(@drive, 'syncFile')
+      spyOn(@subject, 'drive').and.returnValue(@drive)
+
     it 'synchronizes the drive', ->
-      drive = { syncFile: null }
-      spyOn(drive, 'syncFile')
-      @subject.synchronize(drive)
-      expect(drive).to haveCalled('syncFile')
+      @subject.synchronize(@drive)
+      expect(@drive.syncFile).toHaveBeenCalled()
+
+    it 'changes the text on the button', ->
+      @subject.synchronize(@drive)
+      expect(@subject.get('text')).toEqual('Syncing...')
+
+    it 'changes the button icon', ->
+      @subject.synchronize(@drive)
+      expect(@subject.get('icon')).toContain('fa-spin')
+      expect(@subject.get('icon')).toContain('fa-spinner')
 
spec/teaspoon_env.rb
@@ -42,7 +42,7 @@ Teaspoon.configure do |config|
     # Note: If no version is specified, the latest is assumed.
     #
     # Available: jasmine[1.3.1, 2.0.0], mocha[1.10.0, 1.17.1] qunit[1.12.0, 1.14.0]
-    suite.use_framework :jasmine, "1.3.1"
+    suite.use_framework :jasmine, "2.2.0"
 
     # Specify a file matcher as a regular expression and all matching files will be loaded when the suite is run. These
     # files need to be within an asset path. You can add asset paths using the `config.asset_paths`.