ember.js - Ember auth transition.retry() after login doesn't transit while testing -
i having issues testing login , related features of app. app works perfectly, test fails. testing, use qunit
karma
i have created few authenticated routes(say accounts) 1 can visit after logging in. if user goes accounts route without logging, redirected login page , after successful login, redirected accounts page.
app.authenticatedroute = ember.route.extend({ beforemodel: function(transition) { if (!app.authmanager.isauthenticated()) { this.redirecttologin(transition); } }, redirecttologin: function(transition) { var logincontroller; logincontroller = this.controllerfor('login'); logincontroller.set("attemptedtransition", transition); this.transitionto("login"); }, events: { error: function(reason, transition) { this.redirecttologin(transition); } } }); app.logincontroller = ember.objectcontroller.extend({ attemptedtransition: null, loginuser: function() { var attemptedtran, form_data, router, that; router = this.get("target"); form_data = this.getproperties("email", "password"); attemptedtran = this.get('attemptedtransition'); = this; return $.post("/sessions", { 'session': form_data }, (function(results) { return ember.run(function() { app.authmanager.authenticate(results.api_key.access_token, results.api_key.user_id); if (attemptedtran) { attemptedtran.retry(); return that.set('attemptedtransition', null); } else { return router.transitionto("index"); } }); }), "json"); } }); app.accountsroute = app.authenticatedroute.extend({ model: function() { return this.store.find('account'); } });
i trying test using
test("account index", function() { expect(3); // ensure perform 1 assertion visit("/accounts").andthen(function() { equal(currentroutename(),"login",'accounts authenticated route. redirected login page'); fillin('input[type=text]', "j@j.com"); fillin('input[type=password]', "jjjjjj"); click("button:submit").andthen(function(){ equal(currentroutename(),"accounts",'after login redirected account page.'); }) });
but test fails after logging in , doesn't redirect accounts page. help??
it looks you're setting previoustransition
getting attemptedtransition
. attemptedtransition
should null according logic above.
Comments
Post a Comment