Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Merge branch '112_prevent-invalid-enter-login' into 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
karmacoma committed Apr 18, 2017
2 parents 7aadb04 + f54538b commit 352e282
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/app/components/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ app.component('login', {
}

doTheLogin() {
this.passphrase = login.fixCaseAndWhitespace(this.input_passphrase);
if (this.isValidPassphrase(this.input_passphrase) === 1) {
this.passphrase = login.fixCaseAndWhitespace(this.input_passphrase);

this.reset();
this.$timeout(this.onLogin);
this.reset();
this.$timeout(this.onLogin);
}
}

isValidPassphrase(value) {
Expand All @@ -56,6 +58,7 @@ app.component('login', {
} else {
this.valid = 1;
}
return this.valid;
}

startGenratingNewPassphrase() {
Expand Down
10 changes: 6 additions & 4 deletions src/test/components/login/login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ describe('Login controller', () => {
let $scope;
let controller;
let $componentController;
let testPassphrase;

beforeEach(inject((_$componentController_, _$rootScope_) => {
$componentController = _$componentController_;
$rootScope = _$rootScope_;
}));

beforeEach(() => {
testPassphrase = 'glow two glimpse camp aware tip brief confirm similar code float defense';
$scope = $rootScope.$new();
controller = $componentController('login', $scope, { });
controller.onLogin = function () {};
Expand Down Expand Up @@ -123,18 +125,20 @@ describe('Login controller', () => {

describe('$scope.doTheLogin()', () => {
it('sets this.phassphrase as this.input_passphrase processed by fixCaseAndWhitespace', () => {
controller.input_passphrase = '\tTEST PassPHrASe ';
controller.input_passphrase = '\tGLOW two GliMpse camp aware tip brief confirm similar code float defense ';
controller.doTheLogin();
expect(controller.passphrase).to.equal('test passphrase');
expect(controller.passphrase).to.equal('glow two glimpse camp aware tip brief confirm similar code float defense');
});

it('calls this.reset()', () => {
controller.input_passphrase = testPassphrase;
const spy = sinon.spy(controller, 'reset');
controller.doTheLogin();
expect(spy).to.have.been.calledWith();
});

it('sets timeout with this.onLogin', () => {
controller.input_passphrase = testPassphrase;
const spy = sinon.spy(controller, '$timeout');
controller.doTheLogin();
expect(spy).to.have.been.calledWith(controller.onLogin);
Expand Down Expand Up @@ -172,15 +176,13 @@ describe('Login controller', () => {

describe('$scope.devTestAccount()', () => {
it('sets input_passphrase from cookie called passphrase if present', () => {
const testPassphrase = 'test passphrase';
const mock = sinon.mock(controller.$cookies);
mock.expects('get').returns(testPassphrase);
controller.devTestAccount();
expect(controller.input_passphrase).to.equal(testPassphrase);
});

it('does nothing if cooke called passphrase not present', () => {
const testPassphrase = 'test passphrase';
controller.input_passphrase = testPassphrase;
const mock = sinon.mock(controller.$cookies);

Expand Down

0 comments on commit 352e282

Please sign in to comment.