Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
More tests using promises.
Browse files Browse the repository at this point in the history
  • Loading branch information
assaf committed May 25, 2012
1 parent 41d3c0a commit e6d5bc1
Show file tree
Hide file tree
Showing 7 changed files with 601 additions and 603 deletions.
19 changes: 10 additions & 9 deletions test/event_source_test.coffee
Expand Up @@ -3,8 +3,6 @@

describe "EventSource", ->

events = null

before (done)->
brains.get "/streaming", (req, res)->
res.send """
Expand Down Expand Up @@ -36,13 +34,16 @@ describe "EventSource", ->

before (done)->
browser = new Browser()
browser.visit "http://localhost:3003/streaming"
completed = (window)->
return window.events && window.events.length == 2
browser.wait completed, =>
events = browser.evaluate("window.events")
done()
browser.visit("http://localhost:3003/streaming")
.then =>
browser.wait (window)->
return window.events && window.events.length == 2
, null
.then =>
@events = browser.evaluate("window.events")
return
.then(done, done)

it "should stream to browser", ->
assert.deepEqual events, ["first", "second"]
assert.deepEqual @events, ["first", "second"]

60 changes: 31 additions & 29 deletions test/facebook_connect_test.coffee
Expand Up @@ -45,42 +45,44 @@ describe "Facebook Connect", ->
brains.ready done

describe "initial", ->
browser = new Browser()

before (done)->
browser.visit("http://localhost:3003/facebook")
.then ->
browser.clickLink "Connect"
.then done
@browser = new Browser()
@browser.visit("http://localhost:3003/facebook")
.then =>
@browser.clickLink "Connect"
.then(done, done)

it "should show FB Connect login form", ->
assert browser.query(".login_form_container #loginform")
assert @browser.query(".login_form_container #loginform")

describe "login", ->
before (done)->
@browser.fill("email", "---").fill("pass", "---")
@browser.pressButton("login")
.then(done, done)

describe "login", ->
before (done)->
browser.fill("email", "---").fill("pass", "---")
browser.pressButton "login", done

it "should show permission dialog", ->
assert button = browser.query("#platform_dialog_content #grant_clicked input")
assert.equal button.value, "Log In with Facebook"
it "should show permission dialog", ->
assert button = @browser.query("#platform_dialog_content #grant_clicked input")
assert.equal button.value, "Log In with Facebook"

describe "authorize", ->
before (done)->
# all.js sets a callback with a different ID on each run. Our
# HTTP/S responses were captured with the callback ID f42febd2c.
# So we cheat by using this ID and linking it to whatver callback
# was registered last.
FB = browser.windows.get(0).FB
for id, fn of FB.XD._callbacks
FB.XD._callbacks["f42febd2c"] = fn
browser.pressButton "Log In with Facebook", ->
describe "authorize", ->
before (done)->
# all.js sets a callback with a different ID on each run. Our
# HTTP/S responses were captured with the callback ID f42febd2c.
# So we cheat by using this ID and linking it to whatver callback
# was registered last.
FB = @browser.windows.get(0).FB
for id, fn of FB.XD._callbacks
FB.XD._callbacks["f42febd2c"] = fn
@browser.pressButton("Log In with Facebook")
.then =>
# Go back to the first window
browser.windows.close()
done()
@browser.windows.close()
return
.then(done, done)

it "should log user in", ->
assert.equal browser.window.connected.userID, "100001620738919"
assert browser.window.connected.accessToken
it "should log user in", ->
assert.equal @browser.window.connected.userID, "100001620738919"
assert @browser.window.connected.accessToken

0 comments on commit e6d5bc1

Please sign in to comment.