Skip to content
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: node_js
node_js:
- "4.2"
branches:
only:
- test/signupFunctionalTest
env:
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
package:
- g++-4.8
cache:
directories:
- node_modules
139 changes: 139 additions & 0 deletions src/components/auth/registerUser.functional.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import signUpModule from './signup/signup';
import signUpCtrl from './signup/signup.controller';
import signUpTemplate from './signup/signup.html';
import directives from '../../directives/email';
import app from './../../index.js';

describe('register user functional test', function() {
let $rootScope;
let makeController;
let makeDirective;
let makeTemplate
let $toast;
let $state;
let $auth;
let $compile;
let form;
let AuthService;
let $httpBackend;

beforeEach(angular.mock.module('app'));

beforeEach(inject((_$rootScope_, _$toast_, _$state_, _$auth_, _$compile_, _AuthService_, _$httpBackend_) => {
$rootScope = _$rootScope_;

$httpBackend = _$httpBackend_;

$toast = _$toast_;

$state = _$state_;

$auth = _$auth_;

$compile = _$compile_;

AuthService = _AuthService_;

makeTemplate = angular.element(signUpTemplate);

$compile(makeTemplate)($rootScope);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should compile the sign-up template into sign-up controller instead of $rootScope.


form = $rootScope.signup.form;

makeController = () => {
return new signUpCtrl($auth, $state, $toast, AuthService);
};
}));
it('signup form test', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first argument of it() should be revised with a meaningful sentence.

const controller = makeController();

form.email.$setViewValue('eeeiii');
$rootScope.$digest();
expect(form.email.$valid).to.eq(false);
expect(form.email.$viewValue).to.eq('eeeiii');
expect(form.$invalid).to.eq(true);

form.email.$setViewValue('');
$rootScope.$digest();
expect(form.email.$valid).to.eq(false);
expect(form.email.$viewValue).to.eq('');
expect(form.$invalid).to.eq(true);

form.email.$setViewValue('chaoeninwinstack.com');
$rootScope.$digest();
expect(form.email.$valid).to.eq(false);
expect(form.email.$viewValue).to.eq('chaoeninwinstack.com');
expect(form.$invalid).to.eq(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 50 to 66 are already in Unit Tests.


form.email.$setViewValue('chaoen@inwinstack.com');
$rootScope.$digest();
expect(form.email.$valid).to.eq(true);
expect(form.email.$viewValue).to.eq('chaoen@inwinstack.com');
expect(form.$invalid).to.eq(true);

const data = { email : form.email.$setViewValue };
controller.form = { email: { '$valid': form.email.$valid }};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you compile the sign-up template into sign-up controller instead of $rootScope, you won't have to assign the controller.form.email.$valid manually.

controller.credentials = data;
$httpBackend.expectPOST('http://163.17.136.83:8080/api/v1/auth/checkEmail', data).respond(403);
controller.checkEmail();
$httpBackend.flush();
$rootScope.$digest();
expect(controller.emailIsValid).to.eq(false);

form.email.$setViewValue('chaoen.l@inwinstack.com');
$rootScope.$digest();
expect(form.email.$valid).to.eq(true);
expect(form.email.$viewValue).to.eq('chaoen.l@inwinstack.com');
expect(form.$invalid).to.eq(true);

data.email = form.email.$setViewValue;
controller.credentials = data;
$httpBackend.expectPOST('http://163.17.136.83:8080/api/v1/auth/checkEmail', data).respond(200);
controller.checkEmail();
$httpBackend.flush();
$rootScope.$digest();
expect(controller.emailIsValid).to.eq(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 68 to 81 and line 83 to 95 should be separated to different it() sections.


form.password.$setViewValue('abc1234');
form.password_confirmation.$setViewValue('1234567');
$rootScope.$digest();
expect(form.password_confirmation.$valid).to.eq(false);
expect(form.password_confirmation.$viewValue).to.eq('1234567');
expect(form.password.$viewValue).to.eq('abc1234');
expect(form.$invalid).to.eq(true);

form.password_confirmation.$setViewValue('abc1234');
$rootScope.$digest();
expect(form.password_confirmation.$valid).to.eq(true);
expect(form.password_confirmation.$viewValue).to.eq('abc1234');
expect(form.password.$viewValue).to.eq('abc1234');
expect(form.password.$valid).to.eq(true);
expect(form.email.$valid).to.eq(true);
expect(form.$invalid).to.eq(false);
expect(controller.emailIsInvalid).to.eq(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 97 to 103 and line 105 to 113 should be separated to different it() sections.

})
it('controller submit test', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first argument of it() should be revised with a meaningful sentence.

const controller = makeController();
const state = sinon.spy($state, 'go');
const toast = sinon.spy($toast, 'show');
const data = { email: 'chaoen@inwinstack.com', password: 'abc1234' };
controller.credentials = data;
controller.form = { '$submitted': true };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should compile the sign-up template into sign-up controller instead of $rootScope, so you assign the controller.form.$submitted by controller.form.$submitted = true; instead of controller.form = { '$submitted': true };.

$httpBackend.expectPOST('http://163.17.136.83:8080/api/v1/auth/register', data).respond(422);
controller.submit();
$httpBackend.flush();
$rootScope.$digest();
expect(state.called).to.eq(false);
expect(toast.called).to.eq(false);
expect(controller.form.$submitted).to.eq(false);

data.email ='chaoen.l@inwinstack.com';
controller.credentials = data;
$httpBackend.expectPOST('http://163.17.136.83:8080/api/v1/auth/register', data).respond(200);
controller.submit();
$httpBackend.flush();
$rootScope.$digest();
expect(state).to.have.been.calledWith('auth.signin');
expect(toast).to.have.been.calledWith('Sign Up Success!');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 119 to 128 and line 130 to 137 should be separated to different it() sections.

})
})
10 changes: 4 additions & 6 deletions src/components/auth/signin/signin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ describe('SignIn', function() {
let $state;
let $auth;

const form = {};

beforeEach(window.module('app'));

beforeEach(inject(($q, _$rootScope_, _$toast_, _$state_, _$auth_) => {
Expand Down Expand Up @@ -39,14 +37,14 @@ describe('SignIn', function() {

const controller = makeController();

$state.go = sinon.spy();
$toast.show = sinon.spy();
const state = sinon.spy($state, 'go');
const toast = sinon.spy($toast, 'show');

controller.submit();
$rootScope.$digest();

chai.expect($state.go).to.have.been.calledWith('dashboard');
chai.expect($toast.show).to.have.been.calledWith('Sign In Success!');
chai.expect(state).to.have.been.calledWith('dashboard');
chai.expect(toast).to.have.been.calledWith('Sign In Success!');
})
it('signin fail unit test', function() {
const AuthMock = sinon.mock($auth);
Expand Down
10 changes: 4 additions & 6 deletions src/components/auth/signup/signup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ describe('SignUp', function() {
let $auth;
let AuthService;

const form = {};

beforeEach(window.module('app'));

beforeEach(inject(($q, _$rootScope_, _$toast_, _$state_, _$auth_, _AuthService_) => {
Expand Down Expand Up @@ -75,14 +73,14 @@ describe('SignUp', function() {

const controller = makeController();

$state.go = sinon.spy();
$toast.show = sinon.spy();
const state = sinon.spy($state, 'go');
const toast = sinon.spy($toast, 'show');

controller.submit();
$rootScope.$digest();

chai.expect($state.go).to.have.been.calledWith('auth.signin');
chai.expect($toast.show).to.have.been.calledWith('Sign Up Success!');
chai.expect(state).to.have.been.calledWith('auth.signin');
chai.expect(toast).to.have.been.calledWith('Sign Up Success!');
})
it('signup fail unit test', function() {
const AuthMock = sinon.mock($auth);
Expand Down