This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from LiskHQ/unit-tests
Adding unit tests for login and timestamp components.
- Loading branch information
Showing
9 changed files
with
165 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,118 @@ | ||
var sinon = require('sinon'); | ||
var sinonChai = require('sinon-chai'); | ||
var expect = chai.expect; | ||
chai.use(sinonChai); | ||
|
||
describe('Login component', function() { | ||
var $compile, | ||
$rootScope; | ||
$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_){ | ||
beforeEach(inject(function(_$compile_, _$rootScope_) { | ||
// The injector unwraps the underscores (_) from around the parameter names when matching | ||
$compile = _$compile_; | ||
$rootScope = _$rootScope_; | ||
})); | ||
|
||
it('should contain header', function() { | ||
beforeEach(function() { | ||
// Compile a piece of HTML containing the directive | ||
var element = $compile("<login></login>")($rootScope); | ||
element = $compile('<login></login>')($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); | ||
}); | ||
}); | ||
|
||
describe('Login controller', function() { | ||
beforeEach(angular.mock.module('app')); | ||
|
||
var $controller, | ||
$rootScope; | ||
|
||
beforeEach(inject(function(_$componentController_, _$rootScope_) { | ||
$componentController = _$componentController_; | ||
$rootScope = _$rootScope_; | ||
})); | ||
|
||
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(''); | ||
}); | ||
}); | ||
|
||
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; | ||
|
||
beforeEach(function() { | ||
$scope = $rootScope.$new(); | ||
controller = $componentController('login', $scope, {}); | ||
}); | ||
|
||
it('sets $scope.valid = 2 if value is empty', function() { | ||
controller.isValidPassphrase(''); | ||
expect(controller.valid).to.equal(2); | ||
}); | ||
|
||
it('sets $scope.valid = 1 if value is valid', function() { | ||
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.isValidPassphrase('INVALID VALUE'); | ||
expect(controller.valid).to.equal(0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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('<timestamp data="currentTimestamp"></timestamp>')($rootScope); | ||
$rootScope.$digest(); | ||
}); | ||
|
||
it('should contain a timeago of the date', function() { | ||
expect(element.text()).to.equal('a few seconds'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
|
||
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_; | ||
})); | ||
|
||
it('should contain address', function() { | ||
// Compile a piece of HTML containing the directive | ||
var element = $compile("<top></top>")($rootScope); | ||
var element = $compile('<top></top>')($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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters