Permalink
Browse files

Jasmine spec is polished and running

  • Loading branch information...
1 parent e9d5c0c commit 607d5e2f5e01093dbf0e5632fd2a4d035c41aac7 @tindandelion committed May 8, 2012
@@ -22,4 +22,6 @@ Ext.define 'Portal.ui.LoginScreen',
initialize: ->
@callParent(arguments)
- @child('#action').setHandler => @fireEvent('login')
+ @child('#action').setHandler =>
+ credentials = @getValues()
+ @fireEvent('loginRequest', credentials.username, credentials.password)
View
@@ -8,9 +8,8 @@ Ext.application
login_screen = Ext.create 'Portal.ui.LoginScreen',
id: 'login-screen'
listeners:
- login: ->
- credentials = login_screen.getValues()
- home_screen.setUserName(credentials.username)
+ loginRequest: (username, password) ->
+ home_screen.setUserName(username)
Ext.Viewport.setActiveItem(home_screen)
Ext.Viewport.setActiveItem(login_screen)
@@ -0,0 +1,6 @@
+window.EventMatchers =
+ toBeFiredWith: (expectedArgs...) ->
+ return false unless @actual.wasCalled
+ eventArgs = @actual.mostRecentCall.args[0...-2]
+ expect(expectedArgs).toEqual(eventArgs)
+ return true
@@ -0,0 +1,13 @@
+class LoginScreenDriver
+ constructor: (screen) ->
+ @screen = screen
+
+ clickLogin: ->
+ button = @screen.child('#action')
+ handler = button.getHandler()
+ handler(button)
+
+ setCredentials: (username, password) ->
+ @screen.setValues({username, password})
+
+window.LoginScreenDriver = LoginScreenDriver
@@ -1,21 +1,22 @@
Ext.Loader.setPath('Portal', 'public/Portal')
Ext.require ['Portal.ui.LoginScreen']
-
+
describe 'LoginScreen', ->
-
beforeEach ->
+ @addMatchers(EventMatchers)
+
@loginScreen = Ext.create('Portal.ui.LoginScreen')
+ @driver = new LoginScreenDriver(@loginScreen)
afterEach ->
@loginScreen.destroy()
- it 'initializes', ->
- expect(@loginScreen).toBeDefined()
+ it 'fires the login request event when clicking on login button', ->
+ loginHandler = jasmine.createSpy('login-handler')
+ @loginScreen.on 'loginRequest', loginHandler
+
+ @driver.setCredentials('user-login', 'user-password')
+ @driver.clickLogin()
+
+ expect(loginHandler).toBeFiredWith('user-login', 'user-password')
- it 'fires the login event when clicking on login button', ->
- eventFired = false
- @loginScreen.on 'login', ->
- eventFired = true
-
- @loginScreen.fireEvent('login')
- expect(eventFired).toBeTruthy()
@@ -37,6 +37,7 @@ stylesheets:
# - helpers/**/*.js
#
helpers:
+ - helpers/**/*.js
# spec_files
#

0 comments on commit 607d5e2

Please sign in to comment.