From c655ee5c6b747e0bf35f59073c52ffff75c48f5e Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 17 Mar 2017 13:53:30 +0100 Subject: [PATCH 01/13] Add login component controller tests --- src/test/components/login/login.spec.js | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/test/components/login/login.spec.js b/src/test/components/login/login.spec.js index ae31f9289..583bd1568 100644 --- a/src/test/components/login/login.spec.js +++ b/src/test/components/login/login.spec.js @@ -21,3 +21,47 @@ describe('Login component', function() { }); }); +describe('Login controller', function() { + beforeEach(angular.mock.module("app")); + + var $controller, + $rootScope; + + beforeEach(inject(function(_$componentController_, _$rootScope_){ + $componentController = _$componentController_; + $rootScope = _$rootScope_; + })); + + describe('$scope.emptyBytes', function() { + it('it returns array of 12 zeros', function() { + var $scope = $rootScope.$new(); + var controller = $componentController('login', $scope, { }); + expect(controller.emptyBytes()).to.equal([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + }); + }); + + describe('$scope.isValid(value)', function() { + var $scope, + controller; + + beforeEach(function() { + $scope = $rootScope.$new(); + controller = $componentController('login', $scope, { }); + }); + + it('sets $scope.valid = 2 if value is empty', function() { + controller.isValid(''); + expect(controller.valid).to.equal(2); + }); + + it('sets $scope.valid = 1 if value is valid', function() { + controller.isValid('ability theme abandon abandon abandon abandon abandon abandon abandon abandon abandon absorb'); + expect(controller.valid).to.equal(1); + }); + + it('sets $scope.valid = 0 if value is invalid', function() { + controller.isValid('INVALID VALUE'); + expect(controller.valid).to.equal(0); + }); + }); +}); From d974b4a4ec0d645269f99204851af73744e582f0 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 17 Mar 2017 14:25:33 +0100 Subject: [PATCH 02/13] Add more tests of login component --- src/test/components/login/login.spec.js | 27 +++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/test/components/login/login.spec.js b/src/test/components/login/login.spec.js index 583bd1568..4d4d5c3ff 100644 --- a/src/test/components/login/login.spec.js +++ b/src/test/components/login/login.spec.js @@ -1,6 +1,7 @@ describe('Login component', function() { var $compile, - $rootScope; + $rootScope, + element; // Load the myApp module, which contains the directive beforeEach(angular.mock.module("app")); @@ -13,11 +14,29 @@ describe('Login component', function() { $rootScope = _$rootScope_; })); - it('should contain header', function() { + beforeEach(function() { // Compile a piece of HTML containing the directive - var element = $compile("")($rootScope); + element = $compile("")($rootScope); $rootScope.$digest(); - expect(element.html()).to.contain("Sign In"); + }); + + var HEADER_TEXT = 'Sign In'; + it('should contain header saying "' + HEADER_TEXT + '"', function() { + expect(element.find('.md-title').text()).to.equal(HEADER_TEXT); + }); + + var LABEL_TEXT = 'Enter your passphrase'; + it('should contain a form with label saying "' + LABEL_TEXT + '"', function() { + expect(element.find('form label').text()).to.equal(LABEL_TEXT); + }); + + it('should contain an input field', function() { + expect(element.find('form input').html()).to.equal(''); + }); + + var LOGIN_BUTTON_TEXT = 'Login'; + it('should contain a button saying "' + LOGIN_BUTTON_TEXT + '"', function() { + expect(element.find('.md-raised').text()).to.equal(LOGIN_BUTTON_TEXT); }); }); From 602c1e36fc157a78c898a8a47c5f3865df7cc04f Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 17 Mar 2017 16:08:51 +0100 Subject: [PATCH 03/13] Add timestamp component test --- .../components/timestamp/timestamp.spec.js | 30 +++++++++++++++++++ src/test/test.js | 1 + 2 files changed, 31 insertions(+) create mode 100644 src/test/components/timestamp/timestamp.spec.js diff --git a/src/test/components/timestamp/timestamp.spec.js b/src/test/components/timestamp/timestamp.spec.js new file mode 100644 index 000000000..fd44d1ce8 --- /dev/null +++ b/src/test/components/timestamp/timestamp.spec.js @@ -0,0 +1,30 @@ +describe('timestamp component', function() { + var $compile, + $rootScope, + element; + + // Load the myApp module, which contains the directive + beforeEach(angular.mock.module("app")); + + // Store references to $rootScope and $compile + // so they are available to all tests in this describe block + beforeEach(inject(function(_$compile_, _$rootScope_){ + // The injector unwraps the underscores (_) from around the parameter names when matching + $compile = _$compile_; + $rootScope = _$rootScope_; + })); + + beforeEach(function() { + var liskEpoch = Date.UTC(2016, 4, 24, 17, 0, 0, 0); + $rootScope.currentTimestamp = Math.floor((new Date().valueOf() - liskEpoch) / 1000); + + element = $compile("")($rootScope); + $rootScope.$digest(); + }); + + it('should contain a timeago of the date', function() { + expect(element.text()).to.equal('a few seconds'); + }); + +}); + diff --git a/src/test/test.js b/src/test/test.js index 39d45b3f6..8e9a4d053 100644 --- a/src/test/test.js +++ b/src/test/test.js @@ -4,4 +4,5 @@ require('chai'); require('./components/login/login.spec'); require('./components/top/top.spec'); +require('./components/timestamp/timestamp.spec'); From 1cb2b82e08c7569f0b1dce28e0183a4d6e5cf8eb Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 17 Mar 2017 17:11:40 +0100 Subject: [PATCH 04/13] Unit test login component reset() method --- src/test/components/login/login.spec.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/test/components/login/login.spec.js b/src/test/components/login/login.spec.js index 4d4d5c3ff..e863cbb3e 100644 --- a/src/test/components/login/login.spec.js +++ b/src/test/components/login/login.spec.js @@ -51,11 +51,21 @@ describe('Login controller', function() { $rootScope = _$rootScope_; })); - describe('$scope.emptyBytes', function() { - it('it returns array of 12 zeros', function() { - var $scope = $rootScope.$new(); - var controller = $componentController('login', $scope, { }); - expect(controller.emptyBytes()).to.equal([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + describe('$scope.reset()', function() { + var $scope, + controller; + + beforeEach(function() { + $scope = $rootScope.$new(); + controller = $componentController('login', $scope, { }); + }); + + it('makes input_passphrase empty', function() { + passphrase = 'TEST'; + controller.input_passphrase = passphrase; + expect(controller.input_passphrase).to.equal(passphrase); + controller.reset(); + expect(controller.input_passphrase).to.equal(''); }); }); From b6880f6d21d1a94fe365d701746f633b6ace465a Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 17 Mar 2017 17:26:06 +0100 Subject: [PATCH 05/13] Refacotring: make login method names more verbose --- src/app/components/login/login.js | 36 ++++++++++++------------- src/app/components/login/login.pug | 10 +++---- src/test/components/login/login.spec.js | 8 +++--- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/app/components/login/login.js b/src/app/components/login/login.js index 980bc0037..4cca4f0a5 100644 --- a/src/app/components/login/login.js +++ b/src/app/components/login/login.js @@ -21,7 +21,7 @@ app.component('login', { this.$mdMedia = $mdMedia; this.$cookies = $cookies; - this.$scope.$watch('$ctrl.input_passphrase', this.isValid.bind(this)); + this.$scope.$watch('$ctrl.input_passphrase', this.isValidPassphrase.bind(this)); this.$timeout(this.devTestAccount.bind(this), 200); this.$scope.$watch(() => this.$mdMedia('xs') || this.$mdMedia('sm'), (wantsFullScreen) => { @@ -35,34 +35,34 @@ app.component('login', { this.seed = login.emptyBytes().map(() => '00'); } - stop() { - this.random = false; + stopNewPassphraseGeneration() { + this.generatingNewPassphrase = false; this.$document.unbind('mousemove', this.listener); } - go() { - this.passphrase = login.fix(this.input_passphrase); + doTheLogin () { + this.passphrase = login.fixCaseAndWhitespace(this.input_passphrase); this.reset(); this.$timeout(this.onLogin); } - isValid(value) { - const fixedValue = login.fix(value); + isValidPassphrase(value) { + const fixedValue = login.fixCaseAndWhitespace(value); if (fixedValue === '') { this.valid = 2; - } else if (fixedValue.split(' ').length < 12 || !mnemonic.isValid(fixedValue)) { + } else if (fixedValue.split(' ').length < 12 || !mnemonic.isValidPassphrase(fixedValue)) { this.valid = 0; } else { this.valid = 1; } } - start() { + startGenratingNewPassphrase() { this.reset(); - this.random = true; + this.generatingNewPassphrase = true; let last = [0, 0]; let used = login.emptyBytes(); @@ -108,8 +108,8 @@ app.component('login', { } if (count >= total) { - this.stop(); - this.setNew(); + this.stopNewPassphraseGeneration(); + this.setNewPassphrase(this.seed); return; } } @@ -119,15 +119,15 @@ app.component('login', { this.$timeout(() => this.$document.mousemove(this.listener), 300); } - asd() { + simulateMousemove() { this.$document.mousemove(); } - setNew() { - const passphrase = (new mnemonic(new Buffer(this.seed.join(''), 'hex'))).toString(); + setNewPassphrase(seed) { + const passphrase = (new mnemonic(new Buffer(seed.join(''), 'hex'))).toString(); const ok = () => { this.input_passphrase = passphrase; - this.$timeout(this.go.bind(this), 100); + this.$timeout(this.doTheLogin.bind(this), 100); }; this.$mdDialog.show({ @@ -172,11 +172,11 @@ app.component('login', { const passphrase = this.$cookies.get('passphrase'); if (passphrase) { this.input_passphrase = passphrase; - this.$timeout(this.go.bind(this), 10); + this.$timeout(this.doTheLogin.bind(this), 10); } } - static fix(v) { + static fixCaseAndWhitespace(v) { return (v || '').replace(/ +/g, ' ').trim().toLowerCase(); } diff --git a/src/app/components/login/login.pug b/src/app/components/login/login.pug index d23faae4c..a630457db 100644 --- a/src/app/components/login/login.pug +++ b/src/app/components/login/login.pug @@ -6,17 +6,17 @@ md-card form(ng-submit='$ctrl.go()') md-input-container.md-block(md-is-error='$ctrl.valid === 0') label Enter your passphrase - input(type="{{ $ctrl.show_passphrase ? 'text' : 'password' }}", ng-model='$ctrl.input_passphrase', ng-disabled='$ctrl.random', autofocus) + input(type="{{ $ctrl.show_passphrase ? 'text' : 'password' }}", ng-model='$ctrl.input_passphrase', ng-disabled='$ctrl.generatingNewPassphrase', autofocus) md-input-container.md-block md-checkbox.md-primary(ng-model="$ctrl.show_passphrase", aria-label="Show passphrase") Show passphrase md-content(layout='row', layout-align='center center') - // md-button(ng-disabled='$ctrl.random', ng-click='$ctrl.devTestAccount()') Dev Test Account - md-button.md-primary(ng-disabled='$ctrl.random', ng-click='$ctrl.start()') NEW ACCOUNT + // md-button(ng-disabled='$ctrl.generatingNewPassphrase', ng-click='$ctrl.devTestAccount()') Dev Test Account + md-button.md-primary(ng-disabled='$ctrl.random', ng-click='$ctrl.startGenratingNewPassphrase()') NEW ACCOUNT md-button.md-raised.md-primary(md-autofocus, ng-disabled='$ctrl.valid !== 1', ng-click='$ctrl.go()') Login - md-content(layout-padding, layout='column', layout-align='center center', ng-show='$ctrl.random') + md-content(layout-padding, layout='column', layout-align='center center', ng-show='$ctrl.generatingNewPassphrase') h4.move(ng-show='$ctrl.mobileAndTabletcheck()') Enter text below to generate random bytes h4.move(ng-hide='$ctrl.mobileAndTabletcheck()') Move your mouse to generate random bytes - input.random-input(type="text", ng-keydown='$ctrl.asd()', ng-show='$ctrl.mobileAndTabletcheck()') + input.random-input(type="text", ng-keydown='$ctrl.simulateMousemove()', ng-show='$ctrl.mobileAndTabletcheck()') md-progress-linear(md-mode='determinate', value='{{ $ctrl.progress }}') md-content.bytes span.byte(ng-repeat='byte in $ctrl.seed track by $index', ng-bind='byte', animate-on-change='byte') diff --git a/src/test/components/login/login.spec.js b/src/test/components/login/login.spec.js index e863cbb3e..131d7d5a2 100644 --- a/src/test/components/login/login.spec.js +++ b/src/test/components/login/login.spec.js @@ -69,7 +69,7 @@ describe('Login controller', function() { }); }); - describe('$scope.isValid(value)', function() { + describe('$scope.isValidPassphrase(value)', function() { var $scope, controller; @@ -79,17 +79,17 @@ describe('Login controller', function() { }); it('sets $scope.valid = 2 if value is empty', function() { - controller.isValid(''); + controller.isValidPassphrase(''); expect(controller.valid).to.equal(2); }); it('sets $scope.valid = 1 if value is valid', function() { - controller.isValid('ability theme abandon abandon abandon abandon abandon abandon abandon abandon abandon absorb'); + controller.isValidPassphrase('ability theme abandon abandon abandon abandon abandon abandon abandon abandon abandon absorb'); expect(controller.valid).to.equal(1); }); it('sets $scope.valid = 0 if value is invalid', function() { - controller.isValid('INVALID VALUE'); + controller.isValidPassphrase('INVALID VALUE'); expect(controller.valid).to.equal(0); }); }); From 0ba1a44c5b692ce467ae45673a4907749606e333 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 17 Mar 2017 17:31:58 +0100 Subject: [PATCH 06/13] Create a command to run tests on file change: npm run test-live --- src/karma.conf.js | 5 +++-- src/package.json | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/karma.conf.js b/src/karma.conf.js index 66a1f776c..c5ab74762 100644 --- a/src/karma.conf.js +++ b/src/karma.conf.js @@ -13,6 +13,7 @@ preprocessors[test] = ['webpack']; var opts = { onTravis: process.env.ON_TRAVIS, + live: process.env.LIVE, }; module.exports = function(config) { @@ -57,7 +58,7 @@ module.exports = function(config) { // enable / disable watching file and executing tests whenever any file changes - autoWatch: false, + autoWatch: opts.live, ngHtml2JsPreprocessor: { stripPrefix: 'app/components/', @@ -77,7 +78,7 @@ module.exports = function(config) { // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits - singleRun: true, + singleRun: !opts.live, client: { mocha: { opts: 'test/mocha.opts' // You can set opts to equal true then plugin will load opts from default location 'test/mocha.opts' diff --git a/src/package.json b/src/package.json index 619804cac..7847c80ed 100644 --- a/src/package.json +++ b/src/package.json @@ -5,7 +5,8 @@ "scripts": { "build": "webpack --profile --progress --display-modules --display-exclude --display-chunks --display-cached --display-cached-assets", "dev": "webpack-dev-server --host 0.0.0.0 --profile --progress", - "test": "export NODE_ENV=test && karma start" + "test": "export NODE_ENV=test && karma start", + "test-live": "export NODE_ENV=test && export LIVE=true && karma start" }, "dependencies": { "angular": "=1.5.8", From f3c0f854f0085e53cd6d715f4f2710680c388644 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Fri, 17 Mar 2017 18:03:25 +0100 Subject: [PATCH 07/13] Revert incorrectly renamed isValid call --- src/app/components/login/login.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/login/login.js b/src/app/components/login/login.js index 4cca4f0a5..9117f7be0 100644 --- a/src/app/components/login/login.js +++ b/src/app/components/login/login.js @@ -52,7 +52,7 @@ app.component('login', { if (fixedValue === '') { this.valid = 2; - } else if (fixedValue.split(' ').length < 12 || !mnemonic.isValidPassphrase(fixedValue)) { + } else if (fixedValue.split(' ').length < 12 || !mnemonic.isValid(fixedValue)) { this.valid = 0; } else { this.valid = 1; From 224c10b6ffa70e3862c92e52a5114bc4898f9178 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Tue, 21 Mar 2017 11:45:26 +0100 Subject: [PATCH 08/13] Create the first test with sinon-chai --- src/package.json | 2 ++ src/test/components/login/login.spec.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/package.json b/src/package.json index 7847c80ed..2563f40fd 100644 --- a/src/package.json +++ b/src/package.json @@ -71,6 +71,8 @@ "pug-loader": "=2.3.0", "raw-loader": "=0.5.1", "should": "=11.2.0", + "sinon": "^2.0.0", + "sinon-chai": "^2.8.0", "style-loader": "=0.13.1", "url-loader": "=0.5.7", "webpack": "=1.13.1", diff --git a/src/test/components/login/login.spec.js b/src/test/components/login/login.spec.js index 131d7d5a2..0a2ce1681 100644 --- a/src/test/components/login/login.spec.js +++ b/src/test/components/login/login.spec.js @@ -1,3 +1,8 @@ +var sinon = require('sinon'); +var sinonChai = require("sinon-chai"); +var expect = chai.expect; +chai.use(sinonChai); + describe('Login component', function() { var $compile, $rootScope, @@ -69,6 +74,23 @@ describe('Login controller', function() { }); }); + describe('$scope.setNewPassphrase()', function() { + var $scope, + controller; + + beforeEach(function() { + $scope = $rootScope.$new(); + controller = $componentController('login', $scope, { }); + }); + + it('opens a material design dialog', function() { + var seed = ['23', '34', '34', '34', '34', '34', '34', '34']; + var dialogSpy = sinon.spy(controller.$mdDialog, 'show'); + controller.setNewPassphrase(seed); + expect(dialogSpy).to.have.been.calledWith(); + }); + }); + describe('$scope.isValidPassphrase(value)', function() { var $scope, controller; From cdc1d61721ec3b49c43c2020c175a22fe335b902 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Tue, 21 Mar 2017 11:48:58 +0100 Subject: [PATCH 09/13] Cache node_modules in travis --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4ddb3a185..77aa5a805 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: node_js node_js: - 'node' # Latest stable Node.js release +cache: + directories: + - src/node_modules/ env: - ON_TRAVIS=true before_install: cd src From 294e1de1cdb7be6820adac90dc4b0f8511a52e39 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Tue, 21 Mar 2017 11:49:45 +0100 Subject: [PATCH 10/13] Don't install global grunt commands as they are not necessary --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 77aa5a805..5c858b87f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,6 @@ env: - ON_TRAVIS=true before_install: cd src before_script: - - npm install -g grunt - - npm install -g grunt-cli - npm install script: - npm run test From 9729b3617184ed28c841557d90e92f0a1b184ed9 Mon Sep 17 00:00:00 2001 From: Oliver Beddows Date: Tue, 21 Mar 2017 14:30:55 +0100 Subject: [PATCH 11/13] Standardising code --- src/app/components/login/login.js | 2 +- src/test/components/login/login.spec.js | 14 +++++++------- src/test/components/timestamp/timestamp.spec.js | 4 +--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/app/components/login/login.js b/src/app/components/login/login.js index 9117f7be0..7504e9205 100644 --- a/src/app/components/login/login.js +++ b/src/app/components/login/login.js @@ -40,7 +40,7 @@ app.component('login', { this.$document.unbind('mousemove', this.listener); } - doTheLogin () { + doTheLogin() { this.passphrase = login.fixCaseAndWhitespace(this.input_passphrase); this.reset(); diff --git a/src/test/components/login/login.spec.js b/src/test/components/login/login.spec.js index 0a2ce1681..855617801 100644 --- a/src/test/components/login/login.spec.js +++ b/src/test/components/login/login.spec.js @@ -1,5 +1,5 @@ var sinon = require('sinon'); -var sinonChai = require("sinon-chai"); +var sinonChai = require('sinon-chai'); var expect = chai.expect; chai.use(sinonChai); @@ -13,7 +13,7 @@ describe('Login component', function() { // Store references to $rootScope and $compile // so they are available to all tests in this describe block - beforeEach(inject(function(_$compile_, _$rootScope_){ + beforeEach(inject(function(_$compile_, _$rootScope_) { // The injector unwraps the underscores (_) from around the parameter names when matching $compile = _$compile_; $rootScope = _$rootScope_; @@ -51,7 +51,7 @@ describe('Login controller', function() { var $controller, $rootScope; - beforeEach(inject(function(_$componentController_, _$rootScope_){ + beforeEach(inject(function(_$componentController_, _$rootScope_) { $componentController = _$componentController_; $rootScope = _$rootScope_; })); @@ -62,7 +62,7 @@ describe('Login controller', function() { beforeEach(function() { $scope = $rootScope.$new(); - controller = $componentController('login', $scope, { }); + controller = $componentController('login', $scope, {}); }); it('makes input_passphrase empty', function() { @@ -80,7 +80,7 @@ describe('Login controller', function() { beforeEach(function() { $scope = $rootScope.$new(); - controller = $componentController('login', $scope, { }); + controller = $componentController('login', $scope, {}); }); it('opens a material design dialog', function() { @@ -97,10 +97,10 @@ describe('Login controller', function() { beforeEach(function() { $scope = $rootScope.$new(); - controller = $componentController('login', $scope, { }); + controller = $componentController('login', $scope, {}); }); - it('sets $scope.valid = 2 if value is empty', function() { + it('sets $scope.valid = 2 if value is empty', function() { controller.isValidPassphrase(''); expect(controller.valid).to.equal(2); }); diff --git a/src/test/components/timestamp/timestamp.spec.js b/src/test/components/timestamp/timestamp.spec.js index fd44d1ce8..8a7425028 100644 --- a/src/test/components/timestamp/timestamp.spec.js +++ b/src/test/components/timestamp/timestamp.spec.js @@ -8,7 +8,7 @@ describe('timestamp component', function() { // Store references to $rootScope and $compile // so they are available to all tests in this describe block - beforeEach(inject(function(_$compile_, _$rootScope_){ + beforeEach(inject(function(_$compile_, _$rootScope_) { // The injector unwraps the underscores (_) from around the parameter names when matching $compile = _$compile_; $rootScope = _$rootScope_; @@ -25,6 +25,4 @@ describe('timestamp component', function() { it('should contain a timeago of the date', function() { expect(element.text()).to.equal('a few seconds'); }); - }); - From c85587819d9a783210c717a136a146bc1c1e7cbf Mon Sep 17 00:00:00 2001 From: Oliver Beddows Date: Tue, 21 Mar 2017 14:36:10 +0100 Subject: [PATCH 12/13] Fixating dependency versions --- src/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/package.json b/src/package.json index 2563f40fd..ea3f67858 100644 --- a/src/package.json +++ b/src/package.json @@ -71,8 +71,8 @@ "pug-loader": "=2.3.0", "raw-loader": "=0.5.1", "should": "=11.2.0", - "sinon": "^2.0.0", - "sinon-chai": "^2.8.0", + "sinon": "=2.0.0", + "sinon-chai": "=2.8.0", "style-loader": "=0.13.1", "url-loader": "=0.5.7", "webpack": "=1.13.1", From f632ec7e33b686f7697c02f31ed74039bd634557 Mon Sep 17 00:00:00 2001 From: Oliver Beddows Date: Tue, 21 Mar 2017 14:42:18 +0100 Subject: [PATCH 13/13] Standardising code --- src/test/components/login/login.spec.js | 4 ++-- src/test/components/timestamp/timestamp.spec.js | 4 ++-- src/test/components/top/top.spec.js | 9 ++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/test/components/login/login.spec.js b/src/test/components/login/login.spec.js index 855617801..bc3068dcd 100644 --- a/src/test/components/login/login.spec.js +++ b/src/test/components/login/login.spec.js @@ -21,7 +21,7 @@ describe('Login component', function() { beforeEach(function() { // Compile a piece of HTML containing the directive - element = $compile("")($rootScope); + element = $compile('')($rootScope); $rootScope.$digest(); }); @@ -46,7 +46,7 @@ describe('Login component', function() { }); describe('Login controller', function() { - beforeEach(angular.mock.module("app")); + beforeEach(angular.mock.module('app')); var $controller, $rootScope; diff --git a/src/test/components/timestamp/timestamp.spec.js b/src/test/components/timestamp/timestamp.spec.js index 8a7425028..cee468f8c 100644 --- a/src/test/components/timestamp/timestamp.spec.js +++ b/src/test/components/timestamp/timestamp.spec.js @@ -4,7 +4,7 @@ describe('timestamp component', function() { element; // Load the myApp module, which contains the directive - beforeEach(angular.mock.module("app")); + beforeEach(angular.mock.module('app')); // Store references to $rootScope and $compile // so they are available to all tests in this describe block @@ -18,7 +18,7 @@ describe('timestamp component', function() { var liskEpoch = Date.UTC(2016, 4, 24, 17, 0, 0, 0); $rootScope.currentTimestamp = Math.floor((new Date().valueOf() - liskEpoch) / 1000); - element = $compile("")($rootScope); + element = $compile('')($rootScope); $rootScope.$digest(); }); diff --git a/src/test/components/top/top.spec.js b/src/test/components/top/top.spec.js index 6a0cebd6f..e41995d32 100644 --- a/src/test/components/top/top.spec.js +++ b/src/test/components/top/top.spec.js @@ -1,14 +1,13 @@ - describe('Top component', function() { var $compile, $rootScope; // Load the myApp module, which contains the directive - beforeEach(angular.mock.module("app")); + beforeEach(angular.mock.module('app')); // Store references to $rootScope and $compile // so they are available to all tests in this describe block - beforeEach(inject(function(_$compile_, _$rootScope_){ + beforeEach(inject(function(_$compile_, _$rootScope_) { // The injector unwraps the underscores (_) from around the parameter names when matching $compile = _$compile_; $rootScope = _$rootScope_; @@ -16,10 +15,10 @@ describe('Top component', function() { it('should contain address', function() { // Compile a piece of HTML containing the directive - var element = $compile("")($rootScope); + var element = $compile('')($rootScope); // fire all the watches, so the scope expression {{1 + 1}} will be evaluated $rootScope.$digest(); // Check that the compiled element contains the templated content - expect(element.html()).to.contain("address"); + expect(element.html()).to.contain('address'); }); });