From 538030c5519ded0340786e04e637f817901524b4 Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Sun, 29 Oct 2017 12:01:30 -0700 Subject: [PATCH] got edit-form-directive tests to pass --- .../admin-form.client.controller.test.js | 44 ++++++++--------- .../edit-form.client.directive.test.js | 48 ++++++++++++------- 2 files changed, 53 insertions(+), 39 deletions(-) diff --git a/public/modules/forms/tests/unit/controllers/admin-form.client.controller.test.js b/public/modules/forms/tests/unit/controllers/admin-form.client.controller.test.js index b94d75b7..d49d8914 100644 --- a/public/modules/forms/tests/unit/controllers/admin-form.client.controller.test.js +++ b/public/modules/forms/tests/unit/controllers/admin-form.client.controller.test.js @@ -57,28 +57,6 @@ _id: '525a8422f6d0f87f0e407a33' }; - var newFakeModal = function(){ - var modal = { - opened: true, - close: function( item ) { - //The user clicked OK on the modal dialog, call the stored confirm callback with the selected item - this.opened = false; - }, - dismiss: function( type ) { - //The user clicked cancel on the modal dialog, call the stored cancel callback - this.opened = false; - }, - result: { - then: function (cb) { - if(cb && typeof cb === 'function'){ - cb(); - } - } - } - }; - return modal; - }; - //Mock myForm Service beforeEach(module(function($provide) { $provide.service('myForm', function($q) { @@ -166,6 +144,28 @@ }); })); + var newFakeModal = function(){ + var modal = { + opened: true, + close: function( item ) { + //The user clicked OK on the modal dialog, call the stored confirm callback with the selected item + this.opened = false; + }, + dismiss: function( type ) { + //The user clicked cancel on the modal dialog, call the stored cancel callback + this.opened = false; + }, + result: { + then: function (cb) { + if(cb && typeof cb === 'function'){ + cb(); + } + } + } + }; + return modal; + }; + //Mock $uibModal beforeEach(inject(function($uibModal) { var modal = newFakeModal(); diff --git a/public/modules/forms/tests/unit/directives/edit-form.client.directive.test.js b/public/modules/forms/tests/unit/directives/edit-form.client.directive.test.js index aa1710ca..5ad0047b 100644 --- a/public/modules/forms/tests/unit/directives/edit-form.client.directive.test.js +++ b/public/modules/forms/tests/unit/directives/edit-form.client.directive.test.js @@ -80,6 +80,34 @@ }); })); + var newFakeModal = function(){ + var modal = { + opened: true, + close: function( item ) { + //The user clicked OK on the modal dialog, call the stored confirm callback with the selected item + this.opened = false; + }, + dismiss: function( type ) { + //The user clicked cancel on the modal dialog, call the stored cancel callback + this.opened = false; + }, + result: { + then: function (cb) { + if(cb && typeof cb === 'function'){ + cb(); + } + } + } + }; + return modal; + }; + + //Mock $uibModal + beforeEach(inject(function($uibModal) { + var modal = newFakeModal(); + spyOn($uibModal, 'open').and.returnValue(modal); + })); + beforeEach(inject(function($compile, $controller, $rootScope, _$httpBackend_) { //Instantiate directive. var tmp_scope = $rootScope.$new(); @@ -115,26 +143,12 @@ scope.myform = _.cloneDeep(sampleForm); }); - it('$scope.addNewField() should ADD a new field to $scope.myform.form_fields', function() { + it('$scope.addNewField() should open the new field modal', function() { //Run controller methods - scope.addNewField(true, 'textfield'); + scope.addNewField('textfield'); - var expectedFormField = { - title: 'Short Text2', - fieldType: 'textfield', - fieldValue: '', - required: true, - disabled: false, - deletePreserved: false, - logicJump: Object({ }) - }; - - 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); + expect(scope.editFieldModal.opened).toBeTruthy(); }); it('$scope.deleteField() should DELETE a field to $scope.myform.form_fields', function() {