Skip to content

Instantly share code, notes, and snippets.

@zedd45
Last active August 29, 2015 14:09
Show Gist options
  • Save zedd45/5d74308c4496de5f1678 to your computer and use it in GitHub Desktop.
Save zedd45/5d74308c4496de5f1678 to your computer and use it in GitHub Desktop.
registration / login tests
describe "User Registration", ->
describe "Login", ->
beforeEach ->
# Mock the Facebook login (try not to hurt it's feelings; FB is nice)
window.FB = jasmine.createSpyObj "FB", ["login"]
jasmine.Ajax.install()
this.registrationDialog = Vu.Registration.logIn()
afterEach ->
jasmine.Ajax.uninstall()
it "should render the login dialog", ->
expect( this.registrationDialog.$el ).toBeVisible()
expect( this.registrationDialog.$("form") ).toHaveAttr("action", "/login")
it "should be able to login!", ->
# trigger authenticateWithEmail method
this.registrationDialog.$("form").submit()
expect( jasmine.Ajax.requests.mostRecent().url ).toBe("/login")
it "should be able to login with Facebook!", ->
this.registrationDialog.$(".btn-facebook").click()
expect( window.FB.login ).toHaveBeenCalled()
# nested here to take advantage of the beforeEach above
describe "switching views", ->
it "should switch to the login view when the 'switch' button is pressed", ->
this.registrationDialog.$("[rel~=switch]").click()
expect( this.registrationDialog.$el ).toContainElement(".modal-title")
expect( this.registrationDialog.$(".modal-title") ).toContainText("Sign Up")
expect( this.registrationDialog.$("form") ).toHaveAttr("action", "/register")
it "should switch back to the login view when the login button is pressed", ->
this.registrationDialog.$("[rel~=switch]").click()
expect( this.registrationDialog.$el ).toContainElement(".modal-title")
expect( this.registrationDialog.$(".modal-title") ).toContainText("Sign Up")
expect( this.registrationDialog.$("form") ).toHaveAttr("action", "/register")
# now back
this.registrationDialog.$("[rel~=switch]").click()
expect( this.registrationDialog.$el ).toContainElement(".modal-title")
expect( this.registrationDialog.$(".modal-title") ).toContainText("Log In")
expect( this.registrationDialog.$("form") ).toHaveAttr("action", "/login")
describe "Registration", ->
beforeEach ->
window.FB = jasmine.createSpyObj "FB", ["login"]
this.registrationDialog = Vu.Registration.signUp()
it "should render the registration dialog", ->
expect( this.registrationDialog.$el ).toBeVisible()
expect( this.registrationDialog.$("form") ).toHaveAttr("action", "/register")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment