tellform/public/modules/forms/tests/unit/directives/configure-form.client.directive.test.js

92 lines
3.6 KiB
JavaScript
Raw Normal View History

2015-11-23 21:06:02 +00:00
'use strict';
2015-08-21 00:17:14 +00:00
(function() {
// Forms Controller Spec
describe('ConfigureForm Directive-Controller Tests', function() {
2015-08-21 00:17:14 +00:00
// Initialize global variables
var el, scope, controller, $httpBackend;
2015-08-21 00:17:14 +00:00
var sampleUser = {
firstName: 'Full',
lastName: 'Name',
email: 'test@test.com',
username: 'test@test.com',
password: 'password',
provider: 'local',
roles: ['user'],
2016-04-29 06:00:41 +00:00
_id: 'ed873933b1f1dea0ce12fab9'
2015-08-21 00:17:14 +00:00
};
var sampleForm = {
title: 'Form Title',
admin: 'ed873933b1f1dea0ce12fab9',
language: 'english',
form_fields: [
2015-11-23 19:19:02 +00:00
{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'}
],
2015-08-21 00:17:14 +00:00
pdf: {},
pdfFieldMap: {},
startPage: {
showStart: false
},
hideFooter: false,
isGenerated: false,
isLive: false,
autofillPDFs: false,
2016-04-29 06:00:41 +00:00
_id: '525a8422f6d0f87f0e407a33'
2015-08-21 00:17:14 +00:00
};
// 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'));
2015-11-23 19:19:02 +00:00
beforeEach(module('stateMock'));
2016-04-29 06:00:41 +00:00
2015-08-21 00:17:14 +00:00
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>');
2015-08-21 00:17:14 +00:00
$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();
}));
});
2016-04-29 06:00:41 +00:00
}());