Skip to content

Commit

Permalink
Adapted new wallet tests to the new spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sem committed May 1, 2014
1 parent 9508fc9 commit 65b3db8
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions test/unit/frontend/controllers/newWalletSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define(['angular-mocks', 'testUtils'],
function (mocks, testUtils) {
describe('New wallet controller', function() {

var newWalletCtrl, scope, $window, DarkWallet, pars = {};
var newWalletCtrl, scope, $location, _location, DarkWallet, pars = {};

beforeEach(function (done) {
testUtils.stub('darkwallet', {
Expand All @@ -29,8 +29,10 @@ function (mocks, testUtils) {
mocks.module("DarkWallet.controllers");
mocks.inject(["$rootScope", "$controller", function ($rootScope, $controller) {
scope = $rootScope.$new();
$window = {};
newWalletCtrl = $controller('NewWalletCtrl', {$scope: scope, $window: $window});
$location = {path: function(location){
_location = location;
}};
newWalletCtrl = $controller('NewWalletCtrl', {$scope: scope, $location: $location});
done();
}]);
});
Expand All @@ -41,64 +43,67 @@ function (mocks, testUtils) {
});

it('is initialized properly', function() {
expect(scope.activeForm).toBe('password');
expect(scope.create_or_restore).toBe('create');
expect(scope.network).toBe('bitcoin');
expect(scope.step).toBe(1);
expect(scope.form.create_or_restore).toBe('create');
expect(scope.form.network).toBe('bitcoin');
});

it('goes to the next step of the form', function() {
scope.nextStep();
expect(scope.step).toBe(2);
});

it('shows mnemonic form on password one is submitted', function() {
scope.passwd = 'p4ssw0rd';
scope.passwd2 = 'p4ssw0rd';
scope.form.passwd = 'p4ssw0rd';
scope.form.passwd2 = 'p4ssw0rd';
scope.step = 3;
scope.passwordSubmit();
expect(scope.activeForm).toBe('mnemonic');
expect(scope.mnemonicWords.split(' ').length).toBe(12);
expect(scope.step).toBe(4);
expect(scope.form.mnemonic.split(' ').length).toBe(12);
expect(scope.message).toBeUndefined();
});

it('do not show next form if passwords doesn\'t match', function() {
scope.passwd = 'p4ssw0rd';
scope.passwd2 = 'doesntmatch';
scope.form.passwd = 'p4ssw0rd';
scope.form.passwd2 = 'doesntmatch';
scope.passwordSubmit();
scope.create_or_restore = 'restore';
scope.form.create_or_restore = 'restore';
scope.step = 2;
scope.passwordSubmit();
expect(scope.activeForm).toBe('password');
expect(scope.step).toBe(2);
expect(scope.message).toBeDefined();
});

it('directly shows confirm mnemonic form if restore is marked in password form', function() {
scope.passwd = 'p4ssw0rd';
scope.passwd2 = 'p4ssw0rd';
scope.create_or_restore = 'restore';
scope.form.passwd = 'p4ssw0rd';
scope.form.passwd2 = 'p4ssw0rd';
scope.form.create_or_restore = 'restore';
scope.step = 3;
scope.passwordSubmit();
expect(scope.activeForm).toBe('mnemonic2');
expect(scope.mnemonicWords).toBeUndefined();
});

it('makes mnemonic form go to the confirm mnemonic form', function() {
scope.mnemonicSubmit();
expect(scope.activeForm).toBe('mnemonic2');
expect(scope.step).toBe(5);
expect(scope.form.mnemonic).toBeUndefined();
});

it('displays an error if mnemonics does not match on confirm mnemonic', function() {
scope.mnemonicWords = "foo bar baz qux";
scope.mnemonic2Submit();
scope.form.mnemonic = "foo bar baz qux";
scope.mnemonicSubmit();
expect(scope.message2).toBeDefined();
});

it('generates a new identity when a mnemonic is provided', function() {
scope.name = 'Satoshi';
scope.passwd = 'p4ssw0rd';
scope.mnemonic2Words = "king government grown apologize bowl precious eternal ceiling satisfy just silently control";
scope.mnemonic2Submit();
scope.form.name = 'Satoshi';
scope.form.passwd = 'p4ssw0rd';
scope.form.mnemonic2 = "king government grown apologize bowl precious eternal ceiling satisfy just silently control";
scope.mnemonicSubmit();

expect($window.location).toBe('#dashboard');
expect(_location).toBe('#dashboard');

expect(scope.message2).toBeUndefined();

expect(pars.name).toBe(scope.name);
expect(pars.network).toBe(scope.network);
expect(pars.name).toBe(scope.form.name);
expect(pars.network).toBe(scope.form.network);
expect(pars.secret).toBe('be21b135c24c58c0fd72182db940af8d');
expect(pars.password).toBe(scope.passwd);
expect(pars.password).toBe(scope.form.passwd);
});
});
});

0 comments on commit 65b3db8

Please sign in to comment.