got subdomains to work in production

This commit is contained in:
David Baldwynn 2016-06-20 15:35:41 -07:00
parent f00edf73dd
commit ebec20c1de
18 changed files with 1232 additions and 1864 deletions

View file

@ -24,7 +24,8 @@ module.exports = {
},
assets: {
css: 'public/dist/application.min.css',
js: 'public/dist/application.min.js'
js: 'public/dist/application.min.js',
form_js: 'public/dist/form-application.min.js'
},
facebook: {
clientID: process.env.FACEBOOK_ID || 'APP_ID',

View file

@ -12,8 +12,8 @@ module.exports = function(grunt) {
serverJS: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js', '!app/tests/'],
clientViews: ['public/modules/**/views/**/*.html', '!public/modules/**/demo/**/*.html', '!public/modules/**/dist/**/*.html', '!public/modules/**/node_modules/**/*.html'],
clientJS: ['public/js/*.js', 'public/modules/**/*.js', '!public/modules/**/gruntfile.js', '!public/modules/**/demo/**/*.js', '!public/modules/**/dist/**/*.js', '!public/modules/**/node_modules/**/*.js'],
clientCSS: ['public/modules/**/*.css', '!public/modules/**/demo/**/*.css', '!public/modules/**/dist/**/*.css', '!public/modules/**/node_modules/**/*.css'],
clientJS: ['public/js/*.js', 'public/form_modules/**/*.js', 'public/modules/**/*.js', '!public/modules/**/gruntfile.js', '!public/modules/**/demo/**/*.js', '!public/modules/**/dist/**/*.js', '!public/modules/**/node_modules/**/*.js'],
clientCSS: ['public/modules/**/*.css', 'public/form_modules/**/*.css', '!public/modules/**/demo/**/*.css', '!public/modules/**/dist/**/*.css', '!public/modules/**/node_modules/**/*.css'],
serverTests: ['app/tests/**/*.js'],
clientTests: ['public/modules/**/tests/*.js', '!public/modules/**/demo/**/*.js', '!public/modules/**/dist/**/*.js', '!public/modules/**/node_modules/**/*.js']
@ -97,7 +97,8 @@ module.exports = function(grunt) {
mangle: false
},
files: {
'public/dist/application.min.js': 'public/dist/application.js'
'public/dist/application.min.js': 'public/dist/application.js',
'public/dist/form-application.min.js': 'public/dist/form-application.js'
}
}
},
@ -134,7 +135,8 @@ module.exports = function(grunt) {
ngAnnotate: {
production: {
files: {
'public/dist/application.js': '<%= applicationJavaScriptFiles %>'
'public/dist/application.js': '<%= applicationJavaScriptFiles %>',
'public/dist/form-application.js': '<%= formApplicationJavaScriptFiles %>'
}
}
},
@ -177,7 +179,7 @@ module.exports = function(grunt) {
unit: {
configFile: 'karma.conf.js',
singleRun: true
}
}
},
protractor: {
options: {
@ -286,6 +288,7 @@ module.exports = function(grunt) {
var config = require('./config/config');
grunt.config.set('applicationJavaScriptFiles', config.assets.js);
grunt.config.set('formApplicationJavaScriptFiles', config.assets.form_js);
grunt.config.set('applicationCSSFiles', config.assets.css);
});

1219
public/dist/form-application.js vendored Normal file

File diff suppressed because one or more lines are too long

3
public/dist/form-application.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,256 +0,0 @@
'use strict';
(function() {
// Forms Controller Spec
describe('AdminForm Controller Tests', function() {
// Initialize global variables
var AdminFormController,
createAdminFormController,
scope,
$httpBackend,
$stateParams,
$location,
$state;
var sampleUser = {
firstName: 'Full',
lastName: 'Name',
email: 'test@test.com',
username: 'test@test.com',
password: 'password',
provider: 'local',
roles: ['user'],
_id: 'ed873933b1f1dea0ce12fab9'
};
var sampleForm = {
title: 'Form Title',
admin: 'ed873933b1f1dea0ce12fab9',
language: 'english',
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: '', deletePreserved: false, _id:'56340745f59a6fc9e22028e9'},
{fieldType:'checkbox', title:'nascar', fieldValue: '', deletePreserved: false, _id:'5c9e22028e907634f45f59a6'},
{fieldType:'checkbox', title:'hockey', fieldValue: '', deletePreserved: false, _id:'56e90745f5934fc9e22028a6'}
],
_id: '525a8422f6d0f87f0e407a33'
};
var expectedForm = {
title: 'Form Title',
admin: 'ed873933b1f1dea0ce12fab9',
language: 'english',
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: '', deletePreserved: false, _id:'56340745f59a6fc9e22028e9'},
{fieldType:'checkbox', title:'nascar', fieldValue: '', deletePreserved: false, _id:'5c9e22028e907634f45f59a6'},
{fieldType:'checkbox', title:'hockey', fieldValue: '', deletePreserved: false, _id:'56e90745f5934fc9e22028a6'}
],
visible_form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: '', deletePreserved: false, _id:'56340745f59a6fc9e22028e9'},
{fieldType:'checkbox', title:'nascar', fieldValue: '', deletePreserved: false, _id:'5c9e22028e907634f45f59a6'},
{fieldType:'checkbox', title:'hockey', fieldValue: '', deletePreserved: false, _id:'56e90745f5934fc9e22028a6'}
],
_id: '525a8422f6d0f87f0e407a33'
};
var newFakeModal = function(){
var result = {
opened: true,
result: {
then: function(confirmCallback, cancelCallback) {
//Store the callbacks for later when the user clicks on the OK or Cancel button of the dialog
this.confirmCallBack = confirmCallback;
this.cancelCallback = cancelCallback;
}
},
close: function( item ) {
//The user clicked OK on the modal dialog, call the stored confirm callback with the selected item
this.opened = false;
this.result.confirmCallBack( item );
},
dismiss: function( type ) {
//The user clicked cancel on the modal dialog, call the stored cancel callback
this.opened = false;
this.result.cancelCallback( type );
}
};
return result;
};
//Mock Users Service
beforeEach(module(function($provide) {
$provide.service('myForm', function($q) {
return sampleForm;
});
}));
// The $resource service augments the response object with methods for updating and deleting the resource.
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
// the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
// When the toEqualData matcher compares two objects, it takes only object properties into
// account and ignores methods.
beforeEach(function() {
jasmine.addMatchers({
toEqualData: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
return {
pass: angular.equals(actual, expected)
};
}
};
}
});
});
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
beforeEach(module('stateMock'));
//Mock Users Service
beforeEach(module(function($provide) {
$provide.service('User', function($q) {
return {
getCurrent: function() {
var deferred = $q.defer();
deferred.resolve( JSON.stringify(sampleUser) );
return deferred.promise;
},
login: function(credentials) {
var deferred = $q.defer();
if( credentials.password === sampleUser.password && credentials.username === sampleUser.username){
deferred.resolve( JSON.stringify(sampleUser) );
}else {
deferred.resolve('Error: User could not be loggedin');
}
return deferred.promise;
},
logout: function() {
var deferred = $q.defer();
deferred.resolve(null);
return deferred.promise;
},
signup: function(credentials) {
var deferred = $q.defer();
if( credentials.password === sampleUser.password && credentials.username === sampleUser.username){
deferred.resolve( JSON.stringify(sampleUser) );
}else {
deferred.resolve('Error: User could not be signed up');
}
return deferred.promise;
}
};
});
}));
//Mock Authentication Service
beforeEach(module(function($provide) {
$provide.service('Auth', function() {
return {
ensureHasCurrentUser: function() {
return sampleUser;
},
isAuthenticated: function() {
return true;
},
getUserState: function() {
return true;
}
};
});
}));
//Mock $uibModal
beforeEach(inject(function($uibModal) {
var modal = newFakeModal();
spyOn($uibModal, 'open').and.returnValue(modal);
//spyOn($uibModal, 'close').and.callFake(modal.close());
}));
// The injector ignores leading and trailing underscores here (i.e. _$httpBackend_).
// This allows us to inject a service but then attach it to a variable
// with the same name as the service.
beforeEach(inject(function($controller, $rootScope, _$state_, _$location_, _$stateParams_, _$httpBackend_, CurrentForm, Forms) {
// Set a new global scope
scope = $rootScope.$new();
//Set CurrentForm
CurrentForm.setForm(sampleForm);
// Point global variables to injected services
$stateParams = _$stateParams_;
$httpBackend = _$httpBackend_;
$location = _$location_;
$state = _$state_;
$httpBackend.whenGET(/\.html$/).respond('');
$httpBackend.whenGET('/users/me/').respond('');
// Initialize the Forms controller.
createAdminFormController = function(){
return $controller('AdminFormController', { $scope: scope });
};
}));
it('AdminFormController should fetch current Form when instantiated', function() {
// Run controller functionality
var controller = createAdminFormController();
// Test scope value
expect(scope.myform).toEqualData(sampleForm);
});
it('$scope.removeCurrentForm() with valid form data should send a DELETE request with the id of form', function() {
var controller = createAdminFormController();
//Set $state transition
$state.expectTransitionTo('listForms');
// Set DELETE response
$httpBackend.expect('DELETE', /^(\/forms\/)([0-9a-fA-F]{24})$/).respond(200, sampleForm);
//Run controller functionality
scope.openDeleteModal();
scope.removeCurrentForm();
$httpBackend.flush();
$state.ensureAllTransitionsHappened();
});
it('$scope.update() should send a PUT request with the id of form', function() {
var controller = createAdminFormController();
//Set PUT response
$httpBackend.expect('PUT', /^(\/forms\/)([0-9a-fA-F]{24})$/).respond(200, sampleForm);
//Run controller functionality
scope.update(false, null);
$httpBackend.flush();
});
it('$scope.openDeleteModal() should open scope.deleteModal', function() {
var controller = createAdminFormController();
//Run controller functionality
scope.openDeleteModal();
console.log(scope.deleteModal);
expect(scope.deleteModal.opened).toEqual(true);
});
it('$scope.cancelDeleteModal() should close $scope.deleteModal', inject(function($uibModal) {
var controller = createAdminFormController();
//Run controller functionality
scope.openDeleteModal();
//Run controller functionality
scope.cancelDeleteModal();
expect( scope.deleteModal.opened ).toEqual(false);
}));
});
}());

View file

@ -1,224 +0,0 @@
'use strict';
(function() {
// Forms Controller Spec
describe('ListForms Controller Tests', function() {
// Initialize global variables
var ListFormsController,
createListFormsController,
scope,
$httpBackend,
$stateParams,
$location,
$state;
var sampleForm = {
title: 'Form Title',
admin: 'ed873933b1f1dea0ce12fab9',
language: 'english',
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: '', deletePreserved: false},
{fieldType:'checkbox', title:'nascar', fieldValue: '', deletePreserved: false},
{fieldType:'checkbox', title:'hockey', fieldValue: '', deletePreserved: false}
],
_id: '525a8422f6d0f87f0e407a33'
};
var sampleFormList = [{
title: 'Form Title1',
admin: 'ed873933b1f1dea0ce12fab9',
language: 'english',
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: '', deletePreserved: false},
{fieldType:'checkbox', title:'nascar', fieldValue: '', deletePreserved: false},
{fieldType:'checkbox', title:'hockey', fieldValue: '', deletePreserved: false}
],
_id: '525a8422f6d0f87f0e407a33'
},{
title: 'Form Title2',
admin: '39223933b1f1dea0ce12fab9',
language: 'english',
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: '', deletePreserved: false},
{fieldType:'checkbox', title:'nascar', fieldValue: '', deletePreserved: false},
{fieldType:'checkbox', title:'hockey', fieldValue: '', deletePreserved: false}
],
_id: '52f6d0f87f5a407a384220e3'
},{
title: 'Form Title3',
admin: '2fab9ed873937f0e1dea0ce1',
language: 'english',
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: '', deletePreserved: false},
{fieldType:'checkbox', title:'nascar', fieldValue: '', deletePreserved: false},
{fieldType:'checkbox', title:'hockey', fieldValue: '', deletePreserved: false}
],
_id: '922f6d0f87fed8730e4e1233'
}
];
// The $resource service augments the response object with methods for updating and deleting the resource.
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
// the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
// When the toEqualData matcher compares two objects, it takes only object properties into
// account and ignores methods.
beforeEach(function() {
jasmine.addMatchers({
toEqualData: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
return {
pass: angular.equals(actual, expected)
};
}
};
}
});
});
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
beforeEach(module('stateMock'));
//Mock Users Service
beforeEach(module(function($provide) {
$provide.service('myForm', function($q) {
return sampleForm;
});
}));
// The injector ignores leading and trailing underscores here (i.e. _$httpBackend_).
// This allows us to inject a service but then attach it to a variable
// with the same name as the service.
beforeEach(inject(function($controller, $rootScope, _$state_, _$location_, _$stateParams_, _$httpBackend_, CurrentForm, Forms) {
// Set a new global scope
scope = $rootScope.$new();
//Set CurrentForm
CurrentForm.setForm(sampleForm);
// Point global variables to injected services
$stateParams = _$stateParams_;
$httpBackend = _$httpBackend_;
$location = _$location_;
$state = _$state_;
$httpBackend.whenGET(/\.html$/).respond('');
$httpBackend.whenGET('/users/me/').respond('');
// Initialize the Forms controller.
createListFormsController = function(){
return $controller('ListFormsController', { $scope: scope });
};
}));
it('$scope.findAll() should query all User\'s Forms', inject(function(Forms) {
var controller = createListFormsController();
// Set GET response
$httpBackend.expectGET(/^(\/forms)$/).respond(200, sampleFormList);
// Run controller functionality
scope.findAll();
$httpBackend.flush();
// Test scope value
expect( scope.myforms ).toEqualData(sampleFormList);
}));
it('$scope.duplicateForm() should duplicate a Form', inject(function(Forms) {
var dupSampleForm = sampleFormList[2],
dupSampleForm_index = 3,
newSampleFormList = _.clone(sampleFormList);
dupSampleForm._id = 'a02df75b44c1d26b6a5e05b8';
newSampleFormList.splice(3, 0, dupSampleForm);
var controller = createListFormsController();
// Set GET response
$httpBackend.expectGET(/^(\/forms)$/).respond(200, sampleFormList);
// Run controller functionality
scope.findAll();
$httpBackend.flush();
// Set GET response
$httpBackend.expect('POST', '/forms').respond(200, dupSampleForm);
// Run controller functionality
scope.duplicateForm(2);
$httpBackend.flush();
// Test scope value
expect( scope.myforms.length ).toEqual(newSampleFormList.length);
for(var i=0; i<scope.myforms.length; i++){
expect( scope.myforms[i] ).toEqualData(newSampleFormList[i]);
}
expect( scope.myforms[dupSampleForm_index] ).toEqualData(dupSampleForm);
}));
it('$scope.removeForm() should remove a Form', inject(function(Forms) {
var delIndex = 0,
delSampleForm = sampleFormList[delIndex],
delSampleFormList = _.clone(sampleFormList);
delSampleFormList.splice(delIndex, 1);
var controller = createListFormsController();
// Set GET response
$httpBackend.expectGET(/^(\/forms)$/).respond(200, sampleFormList);
// Run controller functionality
scope.findAll();
$httpBackend.flush();
// Set GET response
$httpBackend.expect('DELETE', /^(\/forms\/)([0-9a-fA-F]{24})$/).respond(200, delSampleForm);
// Run controller functionality
scope.removeForm(delIndex);
$httpBackend.flush();
// Test scope value
expect( scope.myforms.length ).toEqual(delSampleFormList.length);
for(var i=0; i<scope.myforms.length; i++){
expect( scope.myforms[i] ).toEqualData(delSampleFormList[i]);
}
expect( scope.myforms[0] ).not.toEqualData(delSampleForm);
}));
it('$scope.createNewForm() should create a new Form', inject(function(Forms) {
var newForm = _.clone(sampleForm);
newForm.name = 'Test Form5';
var controller = createListFormsController();
scope.forms.createForm = {
language: {
$modelValue: 'english'
},
title: {
$modelValue: 'Test Form5'
},
$dirty: true,
$valid: true
};
//Set $state transition
$state.expectTransitionTo('viewForm.create');
// Set GET response
$httpBackend.expect('POST', '/forms').respond(200, newForm);
scope.createNewForm();
$httpBackend.flush();
$state.ensureAllTransitionsHappened();
}));
});
}());

View file

@ -1,230 +0,0 @@
'use strict';
(function() {
// Forms Controller Spec
describe('SubmitForm Controller Tests', function() {
// Initialize global variables
var SubmitFormController,
createSubmitFormController,
scope,
$httpBackend,
$stateParams,
$location,
$state;
var sampleUser = {
firstName: 'Full',
lastName: 'Name',
email: 'test@test.com',
username: 'test@test.com',
password: 'password',
provider: 'local',
roles: ['user'],
_id: 'ed873933b1f1dea0ce12fab9'
};
var sampleForm = {
title: 'Form Title',
admin: 'ed873933b1f1dea0ce12fab9',
language: 'english',
form_fields: [
{'fieldType':'textfield', 'title':'First Name', 'fieldValue': '', 'deletePreserved': false},
{'fieldType':'checkbox', 'title':'nascar', 'fieldValue': '', 'deletePreserved': false},
{'fieldType':'checkbox', 'title':'hockey', 'fieldValue': '', 'deletePreserved': false}
],
isLive: false,
_id: '525a8422f6d0f87f0e407a33',
visible_form_fields: [
{'fieldType':'textfield', 'title':'First Name', 'fieldValue': '', 'deletePreserved': false},
{'fieldType':'checkbox', 'title':'nascar', 'fieldValue': '', 'deletePreserved': false},
{'fieldType':'checkbox', 'title':'hockey', 'fieldValue': '', 'deletePreserved': false}
]
};
//Mock Users Service
beforeEach(module(function($provide) {
$provide.service('myForm', function($q) {
return sampleForm;
});
}));
//Mock Users Service
beforeEach(module(function($provide) {
$provide.service('User', function($q) {
return {
getCurrent: function() {
var deferred = $q.defer();
deferred.resolve( JSON.stringify(sampleUser) );
return deferred.promise;
},
login: function(credentials) {
var deferred = $q.defer();
if( credentials.password === sampleUser.password && credentials.username === sampleUser.username){
deferred.resolve( JSON.stringify(sampleUser) );
}else {
deferred.resolve('Error: User could not be loggedin');
}
return deferred.promise;
},
logout: function() {
var deferred = $q.defer();
deferred.resolve(null);
return deferred.promise;
},
signup: function(credentials) {
var deferred = $q.defer();
if( credentials.password === sampleUser.password && credentials.username === sampleUser.username){
deferred.resolve( JSON.stringify(sampleUser) );
}else {
deferred.resolve('Error: User could not be signed up');
}
return deferred.promise;
}
};
});
}));
//Mock Authentication Service
beforeEach(module(function($provide) {
$provide.service('Auth', function() {
return {
ensureHasCurrentUser: function() {
return sampleUser;
},
isAuthenticated: function() {
return true;
},
getUserState: function() {
return true;
}
};
});
}));
// The $resource service augments the response object with methods for updating and deleting the resource.
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
// the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
// When the toEqualData matcher compares two objects, it takes only object properties into
// account and ignores methods.
beforeEach(function() {
jasmine.addMatchers({
toEqualData: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
return {
pass: angular.equals(actual, expected)
};
}
};
}
});
});
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
beforeEach(module('stateMock'));
//Mock Authentication Service
beforeEach(module(function($provide) {
$provide.service('Auth', function() {
return {
ensureHasCurrentUser: function() {
return sampleUser;
},
isAuthenticated: function() {
return true;
},
getUserState: function() {
return true;
}
};
});
}));
//Mock Users Service
beforeEach(module(function($provide) {
$provide.service('User', function($q) {
return {
getCurrent: function() {
var deferred = $q.defer();
deferred.resolve( JSON.stringify(sampleUser) );
return deferred.promise;
},
login: function(credentials) {
var deferred = $q.defer();
if( credentials.password === sampleUser.password && credentials.username === sampleUser.username){
deferred.resolve( JSON.stringify(sampleUser) );
}else {
deferred.resolve('Error: User could not be loggedin');
}
return deferred.promise;
},
logout: function() {
var deferred = $q.defer();
deferred.resolve(null);
return deferred.promise;
},
signup: function(credentials) {
var deferred = $q.defer();
if( credentials.password === sampleUser.password && credentials.username === sampleUser.username){
deferred.resolve( JSON.stringify(sampleUser) );
}else {
deferred.resolve('Error: User could not be signed up');
}
return deferred.promise;
}
};
});
}));
// The injector ignores leading and trailing underscores here (i.e. _$httpBackend_).
// This allows us to inject a service but then attach it to a variable
// with the same name as the service.
beforeEach(inject(function($controller, $rootScope, _$state_, _$location_, _$stateParams_, _$httpBackend_, CurrentForm, Forms) {
// Set a new global scope
scope = $rootScope.$new();
//Set CurrentForm
CurrentForm.setForm(sampleForm);
// Point global variables to injected services
$stateParams = _$stateParams_;
$httpBackend = _$httpBackend_;
$location = _$location_;
$state = _$state_;
$httpBackend.whenGET(/\.html$/).respond('');
$httpBackend.whenGET('/users/me/').respond('');
// Initialize the Forms controller.
createSubmitFormController = function(){
return $controller('SubmitFormController', { $scope: scope });
};
}));
it('on controller instantiation it should populate $scope.myform with current Form', inject(function(Forms) {
var controller = createSubmitFormController();
$stateParams.formId = '525a8422f6d0f87f0e407a33';
// Set GET response
$httpBackend.expectGET(/^(\/forms\/)([0-9a-fA-F]{24})$/).respond(200, sampleForm);
// Test scope value
expect( scope.myform ).toEqualData(sampleForm);
expect( scope.hideNav ).toEqual(false);
}));
});
}());

View file

@ -1,135 +0,0 @@
'use strict';
(function() {
// Forms Controller Spec
describe('ConfigureForm Directive-Controller Tests', function() {
// Initialize global variables
var el, scope, controller, $httpBackend;
var sampleUser = {
firstName: 'Full',
lastName: 'Name',
email: 'test@test.com',
username: 'test@test.com',
password: 'password',
provider: 'local',
roles: ['user'],
_id: 'ed873933b1f1dea0ce12fab9'
};
var pdfObj = {
fieldname:'file',
originalname:'test.pdf',
name:'1440112660375.pdf',
encoding:'7bit',
mimetype:'application/pdf',
path:'uploads/tmp/test@test.com/1440112660375.pdf',
extension:'pdf',
size:56223,
truncated:false,
buffer:null
};
var sampleForm = {
title: 'Form Title',
admin: 'ed873933b1f1dea0ce12fab9',
language: 'english',
form_fields: [
{fieldType:'textfield', title:'First Name', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed873933b0ce121f1deafab9'},
{fieldType:'checkbox', title:'nascar', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed83b0ce121f17393deafab9'},
{fieldType:'checkbox', title:'hockey', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed8317393deab0ce121ffab9'}
],
pdf: {},
pdfFieldMap: {},
startPage: {
showStart: false
},
hideFooter: false,
isGenerated: false,
isLive: false,
autofillPDFs: false,
_id: '525a8422f6d0f87f0e407a33'
};
// The $resource service augments the response object with methods for updating and deleting the resource.
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
// the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
// When the toEqualData matcher compares two objects, it takes only object properties into
// account and ignores methods.
beforeEach(function() {
jasmine.addMatchers({
toEqualData: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
return {
pass: angular.equals(actual, expected)
};
}
};
}
});
});
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
beforeEach(module('module-templates'));
beforeEach(module('stateMock'));
beforeEach(inject(function($compile, $controller, $rootScope, _$httpBackend_) {
//Instantiate directive.
var tmp_scope = $rootScope.$new();
tmp_scope.myform = sampleForm;
tmp_scope.user = sampleUser;
//gotacha: Controller and link functions will execute.
el = angular.element('<configure-form-directive myform=\'myform\' user=\'user\'></configure-form-directive>');
$compile(el)(tmp_scope);
$rootScope.$digest();
// Point global variables to injected services
$httpBackend = _$httpBackend_;
// $httpBackend.whenGET(/.+\.html$/).respond('');
$httpBackend.whenGET('/users/me/').respond('');
//Grab controller instance
controller = el.controller();
//Grab scope. Depends on type of scope.
//See angular.element documentation.
scope = el.isolateScope() || el.scope();
}));
it('$scope.uploadPDF() should upload a pdf file', function() {
// expect(scope.isInitialized).toBeDefined()
// expect(scope.log).toEqual('');
expect(scope.pdfLoading).toBe(false);
//Set POST response
$httpBackend.when('POST', '/upload/pdf').respond(pdfObj);
var files = [{}];
scope.uploadPDF(files);
$httpBackend.flush();
expect(scope.myform.pdf).toEqualData(pdfObj);
});
it('$scope.removePDF() should removed uploaded pdf file', function() {
// expect(scope.isInitialized).toBeDefined()
// expect(scope.log).toEqual('');
scope.myform.pdf = pdfObj;
scope.myform.isGenerated = true;
scope.myform.autofillPDFs = true;
scope.removePDF();
expect(scope.myform.pdf).toEqual(null);
expect(scope.myform.isGenerated).toBe(false);
expect(scope.myform.autofillPDFs).toBe(false);
});
});
}());

View file

@ -1,200 +0,0 @@
'use strict';
(function() {
// Forms Controller Spec
describe('EditSubmissions Directive-Controller Tests', function() {
// Initialize global variables
var el, scope, controller, $httpBackend;
var sampleUser = {
firstName: 'Full',
lastName: 'Name',
email: 'test@test.com',
username: 'test@test.com',
password: 'password',
provider: 'local',
roles: ['user'],
_id: 'ed873933b1f1dea0ce12fab9'
};
var pdfObj = {
fieldname:'file',
originalname:'test.pdf',
name:'1440112660375.pdf',
encoding:'7bit',
mimetype:'application/pdf',
path:'uploads/tmp/test@test.com/1440112660375.pdf',
extension:'pdf',
size:56223,
truncated:false,
buffer:null
};
var sampleForm = {
title: 'Form Title',
admin: 'ed873933b1f1dea0ce12fab9',
language: 'english',
form_fields: [
{fieldType:'textfield', title:'First Name', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed873933b0ce121f1deafab9'},
{fieldType:'checkbox', title:'nascar', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed83b0ce121f17393deafab9'},
{fieldType:'checkbox', title:'hockey', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed8317393deab0ce121ffab9'}
],
pdf: {},
pdfFieldMap: {},
startPage: {
showStart: false
},
hideFooter: false,
isGenerated: false,
isLive: false,
autofillPDFs: false,
_id: '525a8422f6d0f87f0e407a33'
};
var sampleSubmission = {
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: 'John Smith', deletePreserved: false},
{fieldType:'checkbox', title:'nascar', fieldValue: 1, deletePreserved: false},
{fieldType:'checkbox', title:'hockey', fieldValue: 0, deletePreserved: false}
],
admin: sampleUser,
form: sampleForm,
timeElapsed: 17.55
};
var sampleSubmissions = [{
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: 'The Terminator', deletePreserved: false},
{fieldType:'checkbox', title:'nascar', fieldValue: 0, deletePreserved: false},
{fieldType:'checkbox', title:'hockey', fieldValue: 1, deletePreserved: false}
],
admin: sampleUser,
form: sampleForm,
timeElapsed: 10.33
},
{
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: 'John Smith', deletePreserved: false},
{fieldType:'checkbox', title:'nascar', fieldValue: 1, deletePreserved: false},
{fieldType:'checkbox', title:'hockey', fieldValue: 0, deletePreserved: false}
],
admin: sampleUser,
form: sampleForm,
timeElapsed: 2.33
},
{
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: 'Jane Doe', deletePreserved: false},
{fieldType:'checkbox', title:'nascar', fieldValue: 1, deletePreserved: false},
{fieldType:'checkbox', title:'hockey', fieldValue: 1, deletePreserved: false}
],
admin: sampleUser,
form: sampleForm,
timeElapsed: 11.11
}];
// The $resource service augments the response object with methods for updating and deleting the resource.
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
// the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
// When the toEqualData matcher compares two objects, it takes only object properties into
// account and ignores methods.
beforeEach(function() {
jasmine.addMatchers({
toEqualData: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
return {
pass: angular.equals(actual, expected)
};
}
};
}
});
});
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
beforeEach(module('module-templates'));
beforeEach(module('stateMock'));
beforeEach(inject(function($compile, $controller, $rootScope, _$httpBackend_) {
// Point global variables to injected services
$httpBackend = _$httpBackend_;
$httpBackend.whenGET('/users/me/').respond('');
$httpBackend.whenGET(/^(\/forms\/)([0-9a-fA-F]{24})(\/submissions)$/).respond(200, sampleSubmissions);
//Instantiate directive.
var tmp_scope = $rootScope.$new();
tmp_scope.myform = sampleForm;
tmp_scope.user = sampleUser;
//gotacha: Controller and link functions will execute.
el = angular.element('<edit-submissions-form-directive myform=\'myform\' user=\'user\'></edit-submissions-form-directive>');
$compile(el)(tmp_scope);
$rootScope.$digest();
//Grab controller instance
controller = el.controller();
//Grab scope. Depends on type of scope.
//See angular.element documentation.
scope = el.isolateScope() || el.scope();
}));
it('$scope.initFormSubmissions() should fetch all relevant form submissions', function() {
$httpBackend.expectGET(/^(\/forms\/)([0-9a-fA-F]{24})(\/submissions)$/).respond(200, sampleSubmissions);
scope.initFormSubmissions();
$httpBackend.flush();
scope.$digest();
});
describe('Form Table Methods', function(){
it('$scope.toggleAllCheckers should toggle all checkboxes in table', function(){
scope.initFormSubmissions();
$httpBackend.flush();
//Run Controller Logic to Test
scope.table.masterChecker = true;
scope.toggleAllCheckers();
for(var i=0; i<scope.table.rows.length; i++){
expect(scope.table.rows[i].selected).toBe(true);
}
expect(scope.table.rows.length).not.toEqual(0);
});
it('$scope.isAtLeastOneChecked should return true when at least one checkbox is selected', function(){
scope.initFormSubmissions();
$httpBackend.flush();
scope.table.masterChecker = true;
scope.toggleAllCheckers();
//Run Controller Logic to Test
var atLeastOne = scope.isAtLeastOneChecked();
expect(atLeastOne).toBe(true);
});
it('$scope.deleteSelectedSubmissions should delete all submissions that are selected', function(){
scope.initFormSubmissions();
$httpBackend.flush();
scope.table.masterChecker = true;
scope.toggleAllCheckers();
$httpBackend.expect('DELETE', /^(\/forms\/)([0-9a-fA-F]{24})(\/submissions)$/).respond(200);
//Run Controller Logic to Test
scope.deleteSelectedSubmissions();
$httpBackend.flush();
expect(scope.table.rows.length).toEqual(0);
});
});
});
}());

View file

@ -1,206 +0,0 @@
'use strict';
(function() {
// Forms Controller Spec
describe('EditForm Directive-Controller Tests', function() {
// Initialize global variables
var el, scope, controller, $httpBackend;
var sampleUser = {
firstName: 'Full',
lastName: 'Name',
email: 'test@test.com',
username: 'test@test.com',
password: 'password',
provider: 'local',
roles: ['user'],
_id: 'ed873933b1f1dea0ce12fab9',
};
var pdfObj = {
fieldname:'file',
originalname:'test.pdf',
name:'1440112660375.pdf',
encoding:'7bit',
mimetype:'application/pdf',
path:'uploads/tmp/test@test.com/1440112660375.pdf',
extension:'pdf',
size:56223,
truncated:false,
buffer:null
};
var sampleForm = {
title: 'Form Title',
admin: 'ed873933b1f1dea0ce12fab9',
language: 'english',
form_fields: [
{fieldType:'textfield', title:'First Name', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed873933b0ce121f1deafab9'},
{fieldType:'checkbox', title:'nascar', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed83b0ce121f17393deafab9'},
{fieldType:'checkbox', title:'hockey', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed8317393deab0ce121ffab9'}
],
pdf: {},
pdfFieldMap: {},
startPage: {
showStart: false,
buttons: [],
},
hideFooter: false,
isGenerated: false,
isLive: false,
autofillPDFs: false,
_id: '525a8422f6d0f87f0e407a33',
};
// The $resource service augments the response object with methods for updating and deleting the resource.
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
// the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
// When the toEqualData matcher compares two objects, it takes only object properties into
// account and ignores methods.
beforeEach(function() {
jasmine.addMatchers({
toEqualData: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
return {
pass: angular.equals(actual, expected)
};
}
};
}
});
});
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
beforeEach(module('module-templates'));
beforeEach(module('stateMock'));
beforeEach(inject(function($compile, $controller, $rootScope, _$httpBackend_) {
//Instantiate directive.
var tmp_scope = $rootScope.$new();
tmp_scope.myform = _.cloneDeep(sampleForm);
//gotacha: Controller and link functions will execute.
el = angular.element('<edit-form-directive myform=\'myform\'></edit-form-directive>');
$compile(el)(tmp_scope);
$rootScope.$digest();
// Point global variables to injected services
$httpBackend = _$httpBackend_;
//$httpBackend.whenGET(/.+\.html$/).respond('');
$httpBackend.whenGET('/users/me/').respond('');
//Grab controller instance
controller = el.controller();
//Grab scope. Depends on type of scope.
//See angular.element documentation.
scope = el.isolateScope() || el.scope();
}));
describe('> Form Field >',function(){
beforeEach(function(){
scope.myform = _.cloneDeep(sampleForm);
});
it('$scope.addNewField() should ADD a new field to $scope.myform.form_fields', function() {
//Run controller methods
scope.addNewField(true, 'textfield');
var expectedFormField = {
title:'Short Text2',
fieldType:'textfield',
fieldValue: '',
required: true,
disabled: false,
deletePreserved: false
};
var actualFormField = _.cloneDeep(_.last(scope.myform.form_fields));
delete actualFormField._id;
expect(scope.myform.form_fields.length).toEqual(sampleForm.form_fields.length+1);
expect(actualFormField).toEqualData(expectedFormField);
});
it('$scope.deleteField() should DELETE a field to $scope.myform.form_fields', function() {
//Run controller methods
scope.deleteField(0);
expect(scope.myform.form_fields.length).toEqual(sampleForm.form_fields.length-1);
expect(_.first(scope.myform.form_fields)).toEqualData(sampleForm.form_fields[1]);
});
it('$scope.duplicateField() should DUPLICATE a field and update $scope.myform.form_fields', function() {
//Run controller methods
scope.duplicateField(0);
var originalField = _.cloneDeep(scope.myform.form_fields[0]);
originalField.title += ' copy';
delete originalField._id;
var copyField = _.cloneDeep(scope.myform.form_fields[1]);
delete copyField._id;
expect(scope.myform.form_fields.length).toEqual(sampleForm.form_fields.length+1);
expect(originalField).toEqualData(copyField);
});
});
describe('> Form Field Button >',function(){
it('$scope.addButton() should ADD a button to $scope.myform.startPage.buttons', function() {
var expectedStartPageBtn = {
bgColor:'#ddd',
color:'#ffffff',
text: 'Button'
};
//Run controller methods
scope.addButton();
var actualStartPageBtn = _.cloneDeep(_.last(scope.myform.startPage.buttons));
delete actualStartPageBtn._id;
expect(scope.myform.startPage.buttons.length).toEqual(sampleForm.startPage.buttons.length+1);
expect(actualStartPageBtn).toEqualData(expectedStartPageBtn);
});
it('$scope.deleteButton() should DELETE a button from $scope.myform.startPage.buttons', function() {
//Run controller methods
scope.deleteButton(scope.myform.startPage.buttons[0]);
expect(scope.myform.startPage.buttons.length).toEqual(0);
});
});
describe('> Form Field Option >',function(){
it('$scope.addOption() should ADD a new option to a field.fieldOptions', function() {
var originalOptionLen = scope.myform.form_fields[1].fieldOptions.length;
//Run controller methods
scope.addOption(1);
expect(originalOptionLen+1).toEqual(scope.myform.form_fields[1].fieldOptions.length);
expect(scope.myform.form_fields[1].fieldOptions[0].option_title).toEqualData('Option 0');
expect(scope.myform.form_fields[1].fieldOptions[0].option_value).toEqualData('Option 0');
});
it('$scope.deleteOption() should DELETE remove option from field.fieldOptions', function() {
//Run controller methods
scope.deleteOption(1, scope.myform.form_fields[1].fieldOptions[0]);
expect(scope.myform.form_fields[0].fieldOptions.length).toEqual(0);
expect(scope.myform.form_fields[0].fieldOptions[0]).not.toBeDefined();
});
});
});
}());

View file

@ -1,93 +0,0 @@
// 'use strict';
// (function() {
// // Forms Controller Spec
// describe('entryPage Directive Tests', function() {
// // Initialize global variables
// var scope,
// $templateCache,
// $httpBackend,
// $compile;
// var sampleStartPage = {
// showStart: true,
// introTitle: 'Welcome to Form',
// introParagraph: 'Sample intro paragraph',
// buttons:[
// {
// url: 'http://google.com',
// action: '',
// text: 'Google',
// bgColor: '#ffffff',
// color: '#000000',
// },
// {
// url: 'http://facebook.com',
// action: '',
// text: 'Facebook',
// bgColor: '#0000ff',
// color: '#000000',
// }
// ]
// };
// // The $resource service augments the response object with methods for updating and deleting the resource.
// // If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
// // the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
// // When the toEqualData matcher compares two objects, it takes only object properties into
// // account and ignores methods.
// beforeEach(function() {
// jasmine.addMatchers({
// toEqualData: function(util, customEqualityTesters) {
// return {
// compare: function(actual, expected) {
// return {
// pass: angular.equals(actual, expected)
// };
// }
// };
// }
// });
// });
// // Load the main application module
// beforeEach(module(ApplicationConfiguration.applicationModuleName));
// beforeEach(inject(function($rootScope, _$compile_, _$httpBackend_) {
// scope = $rootScope.$new();
// $compile = _$compile_;
// // Point global variables to injected services
// $httpBackend = _$httpBackend_;
// }));
// it('should be able to render entryPage in html', function() {
// scope.myStartPage = _.cloneDeep(sampleStartPage);
// console.log(scope.myStartPage);
// var element = angular.element('<entry-page pageData="myStartPage" pageType="startPage"></entry-page>');
// $compile(element)(scope);
// scope.$digest();
// // console.log(element.html());
// expect(element.html()).not.toEqual('<div class="ng-scope">Start Page</div>');
// });
// // it('exitStartPage should work for "startPage" type of entryPage', inject(function($rootScope) {
// // scope.myPage = _.cloneDeep(sampleStartPage);
// // var el = angular.element('<entry-page pageData="myPage" pageType="startPage"></entry-page>');
// // $compile(el)(scope);
// // scope.$digest();
// // $httpBackend.whenGET(/.+\.html$/).respond('');
// // $httpBackend.whenGET('/users/me/').respond('');
// // scope = el.isolateScope() || el.scope();
// // scope.exitStartPage();
// // // expect(scope.myStartPage.showStart).toBe(false);
// // expect(el.html()).not.toEqual('<div>Start Page</div>');
// // }));
// });
// }());

View file

@ -1,54 +0,0 @@
'use strict';
(function() {
// Forms Controller Spec
describe('FieldIcon Directive Tests', function() {
// Initialize global variables
var scope,
FormFields,
faClasses = {
'textfield': 'fa fa-pencil-square-o',
'dropdown': 'fa fa-th-list',
'date': 'fa fa-calendar',
'checkbox': 'fa fa-check-square-o',
'radio': 'fa fa-dot-circle-o',
'email': 'fa fa-envelope-o',
'textarea': 'fa fa-pencil-square',
'legal': 'fa fa-legal',
'file': 'fa fa-cloud-upload',
'rating': 'fa fa-star-half-o',
'link': 'fa fa-link',
'scale': 'fa fa-sliders',
'stripe': 'fa fa-credit-card',
'statement': 'fa fa-quote-left',
'yes_no': 'fa fa-toggle-on',
'number': 'fa fa-slack'
};
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
beforeEach(inject(function ($rootScope, _FormFields_) {
scope = $rootScope.$new();
FormFields = _FormFields_;
}));
it('should be able render all field-icon types', inject(function($compile) {
var currType, currClass;
for(var i=0; i<FormFields.types.length; i++){
currType = FormFields.types[i];
currClass = faClasses[currType.name];
var element = $compile('<field-icon-directive type-name="'+currType.name+'"></field-icon-directive>')(scope);
scope.$digest();
expect(currClass).toBeDefined();
expect(element.find('i')).not.toBe(null);
expect(element.find('i').hasClass(currClass)).toBe(true);
}
}));
});
}());

View file

@ -1,97 +0,0 @@
'use strict';
(function() {
// Forms Controller Spec
describe('Field Directive Tests', function() {
// Initialize global variables
var scope,
FormFields,
$templateCache,
$httpBackend,
$compile;
var sampleUser = {
firstName: 'Full',
lastName: 'Name',
email: 'test@test.com',
username: 'test@test.com',
password: 'password',
provider: 'local',
roles: ['user'],
_id: 'ed873933b1f1dea0ce12fab9',
};
var sampleFields = [
{fieldType:'textfield', title:'First Name', fieldValue: 'AoeuName', deletePreserved: false, required: true, disabled: false},
{fieldType:'email', title:'Email', fieldValue: 'aoeu@aoeu.com', deletePreserved: false, required: true, disabled: false},
{fieldType:'yes_no', title:'Do you Play Hockey?', fieldValue: 'true', deletePreserved: false, required: true, disabled: false},
{fieldType:'url', title:'Github Account', fieldValue: 'http://github.com/aoeu', deletePreserved: false, required: true, disabled: false},
{fieldType:'textarea', title:'Bio', fieldValue: 'This is my bio.', deletePreserved: false, required: true, disabled: false},
{fieldType:'number', title:'Phone #', fieldValue: 5325325325, deletePreserved: false, required: true, disabled: false},
{fieldType:'legal', title:'You agree to terms and conditions', description:'By selecting \'I agree\' you are agreeing under Canadian law that you have read and accept terms and conditions outlayed below', fieldValue: '', deletePreserved: false, required: true, disabled: false},
{fieldType:'dropdown', title:'Your Sex', fieldValue: '', fieldOptions:[ { 'option_id': 0, 'option_title': 'M', 'option_value': 'male' }, { 'option_id': 1, 'option_title': 'F', 'option_value': 'female' }], deletePreserved: false, required: true, disabled: false},
{fieldType:'radio', title:'Your Sexual Orientation', fieldValue: '', fieldOptions:[ { 'option_id': 0, 'option_title': 'Heterosexual', 'option_value': 'hetero' }, { 'option_id': 1, 'option_title': 'Homosexual', 'option_value': 'homo' }, { 'option_id': 2, 'option_title': 'Bisexual', 'option_value': 'bi' }, { 'option_id': 3, 'option_title': 'Asexual', 'option_value': 'asex' }], deletePreserved: false, required: true, disabled: false},
{fieldType:'rating', title:'Your Current Happiness', fieldValue: '0', deletePreserved: false, required: true, disabled: false},
];
// The $resource service augments the response object with methods for updating and deleting the resource.
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
// the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
// When the toEqualData matcher compares two objects, it takes only object properties into
// account and ignores methods.
beforeEach(function() {
jasmine.addMatchers({
toEqualData: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
return {
pass: angular.equals(actual, expected)
};
}
};
}
});
});
beforeEach(module(function ($sceProvider) {
$sceProvider.enabled(false);
}));
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
beforeEach(module('stateMock'));
beforeEach(module('module-templates'));
beforeEach(module('ngSanitize', 'ui.select'));
beforeEach(inject(function($rootScope, _FormFields_, _$compile_) {
scope = $rootScope.$new();
FormFields = _FormFields_;
$compile = _$compile_;
}));
it('should be able to render all field types in html', inject(function($rootScope) {
scope.fields = sampleFields;
for(var i=0; i<sampleFields.length; i++){
var field = sampleFields[i];
if(!field.title) field.title = '';
scope.myfield = field;
var element = angular.element('<field-directive field="myfield"></field-directive>');
$compile(element)(scope);
scope.$digest();
console.log('Actual: ');
console.log(element.html());
console.log('\nExpected: ');
console.log('<div class="ng-binding ng-scope>'+field.title+'</div>');
expect(element.html()).not.toEqual('<div class="ng-binding ng-scope>'+field.title+'</div>');
}
}));
});
}());

View file

@ -1,46 +0,0 @@
'use strict';
(function() {
// Forms Controller Spec
describe('onFinishRender Directive Tests', function() {
// Initialize global variables
var scope,
FormFields;
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
beforeEach(inject(function ($rootScope, _FormFields_) {
scope = $rootScope.$new();
FormFields = _FormFields_;
spyOn($rootScope, '$broadcast');
}));
it('should emit Custom "Finished" and "Started" events on ng-repeat', inject(function($compile, $rootScope) {
scope.myfields = FormFields.types;
var e = $compile('<div><div ng-repeat="item in myfields" on-finish-render="editFormFields">{{item.name}}</div></div>')(scope);
scope.$digest();
//run code to test
expect($rootScope.$broadcast).toHaveBeenCalledWith('editFormFields Started');
expect(scope.$broadcast).toHaveBeenCalledWith('editFormFields Finished');
}));
it('should emit "ngRepeat Finished" and "ngRepeat Started" events on ng-repeat when attr is not set to string', inject(function($compile, $rootScope) {
// console.log(FormFields.types);
scope.myfields = FormFields.types;
var e = $compile('<div><div ng-repeat="item in myfields" on-finish-render>{{item.name}}</div></div>')(scope);
scope.$digest();
//run code to test
expect($rootScope.$broadcast).toHaveBeenCalledWith('ngRepeat Started');
expect(scope.$broadcast).toHaveBeenCalledWith('ngRepeat Finished');
}));
});
}());

View file

@ -1,203 +0,0 @@
'use strict';
(function() {
// Forms Controller Spec
describe('SubmitForm Directive-Controller Tests', function() {
// Initialize global variables
var scope, controller, $httpBackend;
var sampleUser = {
firstName: 'Full',
lastName: 'Name',
email: 'test@test.com',
username: 'test@test.com',
password: 'password',
provider: 'local',
roles: ['user'],
_id: 'ed873933b1f1dea0ce12fab9'
};
var pdfObj = {
fieldname:'file',
originalname:'test.pdf',
name:'1440112660375.pdf',
encoding:'7bit',
mimetype:'application/pdf',
path:'uploads/tmp/test@test.com/1440112660375.pdf',
extension:'pdf',
size:56223,
truncated:false,
buffer:null
};
var sampleForm = {
title: 'Form Title',
admin: 'ed873933b1f1dea0ce12fab9',
language: 'english',
form_fields: [
{fieldType:'textfield', title:'First Name', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed873933b0ce121f1deafab9'},
{fieldType:'checkbox', title:'nascar', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed83b0ce121f17393deafab9'},
{fieldType:'checkbox', title:'hockey', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed8317393deab0ce121ffab9'} ],
visible_form_fields: [
{fieldType:'textfield', title:'First Name', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed873933b0ce121f1deafab9'},
{fieldType:'checkbox', title:'nascar', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed83b0ce121f17393deafab9'},
{fieldType:'checkbox', title:'hockey', fieldOptions: [], fieldValue: '', required: true, disabled: false, deletePreserved: false, _id: 'ed8317393deab0ce121ffab9'} ],
pdf: {},
pdfFieldMap: {},
startPage: {
showStart: false
},
hideFooter: false,
isGenerated: false,
isLive: false,
autofillPDFs: false,
_id: '525a8422f6d0f87f0e407a33'
};
var sampleSubmission = {
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: 'John Smith', deletePreserved: false, _id: 'ed873933b0ce121f1deafab9'},
{fieldType:'yes_no', title:'Do you like nascar', fieldValue: true, deletePreserved: false, _id: 'ed83b0ce121f17393deafab9'},
{fieldType:'yes_no', title:'Do you like hockey', fieldValue: false, deletePreserved: false, _id: 'ed8317393deab0ce121ffab9'}
],
admin: sampleUser,
form: sampleForm,
timeElapsed: 17.55
};
var sampleSubmissions = [{
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: 'The Terminator', deletePreserved: false},
{fieldType:'yes_no', title:'Do you like nascar', fieldValue: 'true', deletePreserved: false},
{fieldType:'yes_no', title:'Do you like hockey', fieldValue: 'false', deletePreserved: false}
],
admin: sampleUser,
form: sampleForm,
timeElapsed: 10.33
},
{
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: 'John Smith', deletePreserved: false},
{fieldType:'yes_no', title:'Do you like nascar', fieldValue: 'true', deletePreserved: false},
{fieldType:'yes_no', title:'Do you like hockey', fieldValue: 'true', deletePreserved: false}
],
admin: sampleUser,
form: sampleForm,
timeElapsed: 2.33
},
{
form_fields: [
{fieldType:'textfield', title:'First Name', fieldValue: 'Jane Doe', deletePreserved: false},
{fieldType:'yes_no', title:'Do you like nascar', fieldValue: 'false', deletePreserved: false},
{fieldType:'yes_no', title:'Do you like hockey', fieldValue: 'false', deletePreserved: false}
],
admin: sampleUser,
form: sampleForm,
timeElapsed: 11.11
}];
// The $resource service augments the response object with methods for updating and deleting the resource.
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
// the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
// When the toEqualData matcher compares two objects, it takes only object properties into
// account and ignores methods.
beforeEach(function() {
jasmine.addMatchers({
toEqualData: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
return {
pass: angular.equals(actual, expected)
};
}
};
}
});
});
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
beforeEach(module('module-templates'));
beforeEach(module('stateMock'));
beforeEach(inject(function($compile, $controller, $rootScope, _$httpBackend_) {
// Point global variables to injected services
$httpBackend = _$httpBackend_;
$httpBackend.whenGET('/users/me/').respond('');
//Instantiate directive.
var tmp_scope = $rootScope.$new();
tmp_scope.myform = sampleForm;
//gotacha: Controller and link functions will execute.
var el = angular.element('<submit-form-directive myform=\'myform\'></submit-form-directive>');
$compile(el)(tmp_scope);
tmp_scope.$digest();
$rootScope.$digest();
//Grab controller instance
controller = el.controller();
//Grab scope. Depends on type of scope.
//See angular.element documentation.
scope = el.isolateScope() || el.scope();
console.log(scope);
}));
var Validator = (function() {
return {
hasMinimumFields: function(entry) {
return !_.isEmpty(entry._id) && !_.isEmpty(entry.title);
},
isNewForm: function(entry) {
return this.hasMinimumFields(entry);
}
};
})();
it('$scope.submitForm() should submit valid form', function(){
//Initialize variables
scope.myform.form_fields = sampleSubmissions[0].form_fields;
var expectedForm = _.cloneDeep(sampleForm);
expectedForm.form_fields = sampleSubmissions[0].form_fields;
delete expectedForm.visible_form_fields;
var data = function(data) {
var form = angular.fromJson(data);
var compareForm = _.cloneDeep(form);
delete compareForm.timeElapsed;
delete compareForm.percentageComplete;
return Validator.isNewForm(form) && _.isEqual(compareForm, expectedForm);
};
//Set expected HTTP requests
$httpBackend.expect('POST',/^(\/forms\/)([0-9a-fA-F]{24})$/, data).respond(200);
//Run Controller Logic to Test
scope.submitForm();
$httpBackend.flush();
setTimeout(function(){
expect(scope.myform.submitted).toBe(true);
expect(scope.error).toEqual('');
}, 25);
});
it('$scope.reloadForm() should reset and reload form', function(){
scope.submitForm();
scope.reloadForm();
expect(scope.myform.submitted).toBe(false);
for(var i=0; i<scope.myform.form_fields.length; i++){
expect(scope.myform.form_fields[i].fieldValue).toEqual('');
}
});
});
}());

View file

@ -1,54 +0,0 @@
'use strict';
(function() {
// Forms Controller Spec
describe('CurrentForm Service Tests', function() {
// Initialize global variables
var CurrentForm,
sampleForm = {
title: 'Form Title',
admin: 'ed873933b1f1dea0ce12fab9',
language: 'english',
form_fields: [
{'fieldType':'textfield', 'title':'First Name', 'fieldValue': '', 'deletePreserved': false},
{'fieldType':'checkbox', 'title':'nascar', 'fieldValue': '', 'deletePreserved': false},
{'fieldType':'checkbox', 'title':'hockey', 'fieldValue': '', 'deletePreserved': false}
],
_id: '525a8422f6d0f87f0e407a33'
};
// The $resource service augments the response object with methods for updating and deleting the resource.
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
// the responses exactly. To solve the problem, we define a new toEqualData Jasmine matcher.
// When the toEqualData matcher compares two objects, it takes only object properties into
// account and ignores methods.
beforeEach(function() {
jasmine.addMatchers({
toEqualData: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
return {
pass: angular.equals(actual, expected)
};
}
};
}
});
});
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
beforeEach(inject(function (_CurrentForm_) {
CurrentForm = _CurrentForm_;
}));
it('CurrentForm be able to get() and set() a Form', function() {
CurrentForm.setForm(sampleForm);
var newForm = CurrentForm.getForm();
expect(sampleForm).toEqualData(newForm);
});
});
}());

View file

@ -1,28 +0,0 @@
'use strict';
(function() {
// Forms Controller Spec
describe('TimeCounter Service Tests', function() {
// Initialize global variables
var TimeCounter;
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
beforeEach(inject(function (_TimeCounter_) {
TimeCounter = _TimeCounter_;
}));
it('should be able to time 1 second interval as 1 second', function() {
var timeSpent = 0;
TimeCounter.restartClock();
setTimeout(function(){
timeSpent = TimeCounter.stopClock();
expect(timeSpent).toEqual(1);
},1000);
});
});
}());

View file

@ -1,32 +0,0 @@
'use strict';
angular.module('stateMock',[]);
angular.module('stateMock').service('$state', function($q){
this.expectedTransitions = [];
this.transitionTo = function(stateName){
if(this.expectedTransitions.length > 0){
var expectedState = this.expectedTransitions.shift();
if(expectedState !== stateName){
throw Error('Expected transition to state: ' + expectedState + ' but transitioned to ' + stateName );
}
}else{
throw Error('No more transitions were expected! Tried to transition to '+ stateName );
}
console.log('Mock transition to: ' + stateName);
var deferred = $q.defer();
var promise = deferred.promise;
deferred.resolve();
return promise;
};
this.go = this.transitionTo;
this.expectTransitionTo = function(stateName){
this.expectedTransitions.push(stateName);
};
this.ensureAllTransitionsHappened = function(){
if(this.expectedTransitions.length > 0){
throw Error('Not all transitions happened!');
}
};
});