Commits

Dan Dirks committed f5e1ba2

Adds tests around the remainder of zombie-world.

Comments (0)

Files changed (1)

test/zombie-world.test.coffee

       World.call(@World, ->)
       @browserMock = sinon.mock(@World.browser)
 
+    teardown ->
+      @browserMock.verify()
+
     suite 'visit', ->
       test 'should visit the correct page', ->
         url = 'http://test.url'
-        callback = {}
+        callback = ->
 
         @browserMock.expects('visit').once().withExactArgs(url, callback)
 
         @World.visit(url, callback)
 
+
     suite 'path', ->
       test 'should return the current path', ->
         path = '/my/awesome/path'
         assert.throws (=>
           @World.findElement(selector, findBy, findAll)),
         /Element '.my-element' not found using search method xpath/
+
+
+    suite 'type', ->
+      test 'should type in the correct input box and fire events', ->
+        field = '.my-input'
+        value = 'some awesome text!'
+        thenStub = sinon.stub()
+        thenReturn = { then: thenStub }
+        callback = sinon.spy()
+
+        @browserMock.expects('fill').once().withArgs(field, value).yields()
+        @browserMock.expects('fire').once().withExactArgs('keydown', field).returns(thenReturn)
+        @browserMock.expects('fire').once().withExactArgs('keyup', field).returns(thenReturn)
+        @browserMock.expects('fire').once().withExactArgs('keypress', field).returns(thenReturn)
+        thenStub.returns(thenReturn).yields()
+
+        @World.type(field, value, callback)
+
+        assert(callback.calledOnce, 'callback not called')
+
+
+    suite 'click', ->
+      test 'should fire a click event for the element', ->
+        element = Object.create(null)
+        callback = ->
+
+        @browserMock.expects('fire').once().withExactArgs('click', element, callback)
+
+        @World.click(element, callback)
+
+
+    suite 'check', ->
+      test 'should check an element', ->
+        element = Object.create(null)
+        callback = ->
+
+        @browserMock.expects('check').once().withExactArgs(element, callback)
+
+        @World.check(element, callback)
+
+
+    suite 'uncheck', ->
+      test 'should uncheck an element', ->
+        element = Object.create(null)
+        callback = ->
+
+        @browserMock.expects('uncheck').once().withExactArgs(element, callback)
+
+        @World.uncheck(element, callback)
+
+
+    suite 'alertedWithMessage', ->
+      test 'should return true if browser received an alert with message', ->
+        message = 'UHOH!'
+
+        @browserMock.expects('prompted').once().withExactArgs(message).returns(true)
+
+        actual = @World.alertedWithMessage(message)
+
+        assert.equal(actual, true, 'alertedWithMessage should have returned true')
+
+      test 'should return false if browser did not receive an alert with message', ->
+        message = 'UHOH!'
+
+        @browserMock.expects('prompted').once().withExactArgs(message).returns(false)
+
+        actual = @World.alertedWithMessage(message)
+
+        assert.equal(actual, false, 'alertedWithMessage should have returned false')