refactor to load controller on the beforeEach in all spec files for client side unit tests

This commit is contained in:
Carlos 2017-10-17 14:24:40 +02:00
parent 4cfc6f23d9
commit 85ec628ae6
23 changed files with 102 additions and 184 deletions

View File

@ -2,6 +2,7 @@ import './address-create.js';
describe('Client', () => {
describe('Component vnAddressCreate', () => {
let controller;
let $componentController;
let $state;
@ -13,11 +14,10 @@ describe('Client', () => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.id = '1234';
controller = $componentController('vnAddressCreate', {$state});
}));
it('should define and set address property', () => {
let controller = $componentController('vnAddressCreate', {$state});
expect(controller.address.clientFk).toBe(1234);
expect(controller.address.isEnabled).toBe(true);
});

View File

@ -4,6 +4,7 @@ describe('Client', () => {
describe('Component vnAddressEdit', () => {
let $componentController;
let $state;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -13,11 +14,10 @@ describe('Client', () => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.addressId = '1234';
controller = $componentController('vnAddressEdit', {$state: $state});
}));
it('should define and set address property', () => {
let controller = $componentController('vnAddressEdit', {$state: $state});
expect(controller.address.id).toBe(1234);
});
});

View File

@ -5,6 +5,7 @@ describe('Client', () => {
let $componentController;
let $httpBackend;
let $scope;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -18,11 +19,11 @@ describe('Client', () => {
$scope.watcher = {submit};
let show = jasmine.createSpy('show');
$scope.sendMail = {show};
controller = $componentController('vnClientBillingData', {$scope: $scope});
}));
describe('copyData()', () => {
it(`should define billData using client's data`, () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.client = {
credit: 1000000000000,
creditInsurance: null,
@ -40,7 +41,6 @@ describe('Client', () => {
describe('submit()', () => {
it(`should call submit() on the watcher then receive a callback`, done => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
spyOn(controller, 'checkPaymentChanges');
controller.submit()
.then(() => {
@ -53,7 +53,6 @@ describe('Client', () => {
describe('checkPaymentChanges()', () => {
it(`should not call sendMail.show() if there are no changes on billing data`, () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.billData = {marvelHero: 'Silver Surfer'};
controller.client = {marvelHero: 'Silver Surfer'};
controller.checkPaymentChanges();
@ -62,7 +61,6 @@ describe('Client', () => {
});
it(`should call sendMail.show() if there are changes on billing data object`, () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.billData = {marvelHero: 'Silver Surfer'};
controller.client = {marvelHero: 'Spider-Man'};
controller.checkPaymentChanges();
@ -73,7 +71,6 @@ describe('Client', () => {
describe('returnDialog()', () => {
it('should request to send notification email', () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.client = {id: '123'};
$httpBackend.when('POST', `/mailer/manuscript/payment-update/${controller.client.id}`).respond('done');
$httpBackend.expectPOST(`/mailer/manuscript/payment-update/${controller.client.id}`);

View File

@ -4,6 +4,7 @@ describe('Client', () => {
describe('Component vnClientCard', () => {
let $componentController;
let $scope;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -12,11 +13,10 @@ describe('Client', () => {
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
$componentController = _$componentController_;
$scope = $rootScope;
controller = $componentController('vnClientCard', {$scope: $scope});
}));
it('should define and set client property to null in the module instance', () => {
let controller = $componentController('vnClientCard', {$scope: $scope});
expect(controller.client).toBeDefined();
expect(controller.client).toBe(null);
});

View File

@ -5,6 +5,7 @@ describe('Client', () => {
let $componentController;
let $scope;
let $state;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -23,11 +24,10 @@ describe('Client', () => {
};
}
};
controller = $componentController('vnClientCreate', {$scope: $scope});
}));
it('should define and set scope, state and client properties', () => {
let controller = $componentController('vnClientCreate', {$scope: $scope});
expect(controller.$).toBe($scope);
expect(controller.$state).toBe($state);
expect(controller.client.active).toBe(true);
@ -35,7 +35,6 @@ describe('Client', () => {
describe('onSubmit()', () => {
it(`should call submit() on the watcher then expect a callback`, () => {
let controller = $componentController('vnClientCreate', {$scope: $scope});
spyOn($state, 'go');
controller.onSubmit();

View File

@ -4,6 +4,7 @@ describe('Client', () => {
describe('Component vnDescriptor', () => {
let $componentController;
let $scope;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -12,11 +13,11 @@ describe('Client', () => {
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
controller = $componentController('vnDescriptor', {$scope: $scope});
}));
describe('set active', () => {
it('should check if active is defined and diferent from the new value', () => {
let controller = $componentController('vnDescriptor', {$scope: $scope});
controller.client = {id: 1};
expect(controller._active).toBe(undefined);

View File

@ -3,6 +3,7 @@ import './index.js';
describe('Client', () => {
describe('Component vnClientIndex', () => {
let $componentController;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -10,17 +11,15 @@ describe('Client', () => {
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
controller = $componentController('vnClientIndex');
}));
it('should define and set model property as an empty object', () => {
let controller = $componentController('vnClientIndex');
expect(controller.model).toEqual({});
});
describe('search()', () => {
it(`should set model's search to the search input`, () => {
let controller = $componentController('vnClientIndex');
controller.model.search = 'batman';
let index = {
filter: {},

View File

@ -4,6 +4,7 @@ describe('Client', () => {
describe('Component vnNoteCreate', () => {
let $componentController;
let $state;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -13,11 +14,10 @@ describe('Client', () => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.id = '1234';
controller = $componentController('vnNoteCreate', {$state: $state});
}));
it('should define clientFk using $state.params.id', () => {
let controller = $componentController('vnNoteCreate', {$state: $state});
expect(controller.note.clientFk).toBe(1234);
expect(controller.note.client).toBe(undefined);
});

View File

@ -5,6 +5,7 @@ describe('Client', () => {
let $componentController;
let $state;
let $httpBackend;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -14,11 +15,11 @@ describe('Client', () => {
$componentController = _$componentController_;
$state = _$state_;
$httpBackend = _$httpBackend_;
controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
}));
describe('$onChanges()', () => {
it(`should call getObservation() with the client id`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {
id: 1234
};
@ -31,7 +32,6 @@ describe('Client', () => {
describe('$getObservation()', () => {
it(`should request to GET the client notes`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {id: '1234'};
let jsonString = JSON.stringify({where: {clientFk: '1234'}, order: 'created DESC'});
let json = {data: 'some data'};
@ -46,7 +46,6 @@ describe('Client', () => {
describe('$newObservation()', () => {
it(`should redirect the user to the newObservation view`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {id: '1234'};
spyOn(controller.$state, 'go');
controller.newObservation();

View File

@ -4,6 +4,7 @@ describe('Client', () => {
describe('Component vnClientSearchPanel', () => {
let $componentController;
let $window;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -12,11 +13,11 @@ describe('Client', () => {
beforeEach(angular.mock.inject((_$componentController_, _$window_) => {
$componentController = _$componentController_;
$window = _$window_;
controller = $componentController('vnClientSearchPanel', {$window: $window});
}));
describe('onSearch()', () => {
it(`should call setStorageValue() and onSubmit()`, () => {
let controller = $componentController('vnClientSearchPanel', {$window: $window});
spyOn(controller, 'setStorageValue');
spyOn(controller, 'onSubmit');
controller.setStorageValue();
@ -29,8 +30,6 @@ describe('Client', () => {
describe('$onChanges()', () => {
it(`should set filter properties using the search values`, () => {
let controller = $componentController('vnClientSearchPanel', {$window: $window});
expect(controller.filter).not.toBeDefined();
spyOn(JSON, 'parse').and.returnValue({data: 'data'});
controller.$onChanges();

View File

@ -5,6 +5,7 @@ describe('Component VnClientWebAccess', () => {
let $httpBackend;
let $scope;
let vnApp;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -16,11 +17,11 @@ describe('Component VnClientWebAccess', () => {
$httpBackend = _$httpBackend_;
vnApp = _vnApp_;
spyOn(vnApp, 'showError');
controller = $componentController('vnClientWebAccess', {$scope: $scope});
}));
describe('$onChanges()', () => {
it(`should pass client's account data to account then call isCustomer function`, () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope});
spyOn(controller, 'isCustomer');
controller.client = {client: 'Bruce Wayne', account: 'Wayne Industries'};
controller.account = {};
@ -33,7 +34,6 @@ describe('Component VnClientWebAccess', () => {
describe('isCustomer()', () => {
it(`should perform a query if client is defined with an ID`, () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope});
controller.client = {id: '1234'};
controller.isCustomer();
@ -45,7 +45,6 @@ describe('Component VnClientWebAccess', () => {
describe('onPassOpen()', () => {
it('should set passwords to empty values', () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope});
controller.newPassword = 'm24x8';
controller.repeatPassword = 'm24x8';
controller.onPassOpen();
@ -57,7 +56,6 @@ describe('Component VnClientWebAccess', () => {
describe('onPassChange()', () => {
it('should request to update the password', () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope});
controller.client = {id: '1234'};
controller.newPassword = 'm24x8';
controller.repeatPassword = 'm24x8';
@ -70,7 +68,6 @@ describe('Component VnClientWebAccess', () => {
describe(`when password is empty`, () => {
it(`should throw Passwords can't be empty error`, () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope});
controller.client = {id: '1234'};
controller.newPassword = '';
controller.canChangePassword = true;
@ -82,7 +79,6 @@ describe('Component VnClientWebAccess', () => {
describe(`when passwords don't match`, () => {
it(`should throw Passwords don't match error`, () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope});
controller.client = {id: '1234'};
controller.newPassword = 'm24x8';
controller.canChangePassword = true;

View File

@ -6,6 +6,7 @@ describe('Component vnAutocomplete', () => {
let $httpBackend;
let $timeout;
let $element;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -17,11 +18,11 @@ describe('Component vnAutocomplete', () => {
$httpBackend = _$httpBackend_;
$timeout = _$timeout_;
$element = angular.element('<div></div>');
controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
}));
describe('showDropDown() setter', () => {
it(`should set _showDropDown value`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller._showDropDown = '';
controller.showDropDown = 'some value';
@ -29,7 +30,6 @@ describe('Component vnAutocomplete', () => {
});
it(`should set _showDropDown value`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller._showDropDown = '';
controller.showDropDown = 'some value';
@ -39,7 +39,6 @@ describe('Component vnAutocomplete', () => {
describe('displayValue() setter', () => {
it(`should display value in a formated way`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
let value = 'some value';
controller.displayValue = value;
@ -48,7 +47,6 @@ describe('Component vnAutocomplete', () => {
describe('when the autocomeplete is multiple', () => {
it(`should display values separated with commas`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.multiple = true;
controller.displayValue = 'some value';
controller.displayValue = 'another value';
@ -61,14 +59,12 @@ describe('Component vnAutocomplete', () => {
describe('field() setter', () => {
describe('when value is an object', () => {
it(`should set _field controllers property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.field = {id: 1, name: 'Bruce Wayne'};
expect(controller._field).toEqual(1);
});
it(`should set _multifield controllers property `, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.multiple = true;
controller.field = {id: 1, name: 'Bruce Wayne'};
@ -82,7 +78,6 @@ describe('Component vnAutocomplete', () => {
});
it(`should set _multifield value and remove it if called a second type with same value`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.multiple = true;
controller.field = {id: 1, name: 'Bruce Wayne'};
@ -96,7 +91,6 @@ describe('Component vnAutocomplete', () => {
});
it(`should set displayValue finding an existing item in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
controller.field = {id: 2, name: 'Bruce Wayne'};
@ -106,7 +100,6 @@ describe('Component vnAutocomplete', () => {
describe('when value is a number', () => {
it(`should set _field controller property finding an existing item in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}];
controller.field = 2;
@ -114,7 +107,6 @@ describe('Component vnAutocomplete', () => {
});
it(`should set _multifield value and remove it if called a second type with same value finding an existing item in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}];
controller.multiple = true;
controller.field = 2;
@ -127,7 +119,7 @@ describe('Component vnAutocomplete', () => {
});
it(`should perform a query if the item id isn't present in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
controller.url = 'test.com';
$httpBackend.whenGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}').respond();
$httpBackend.expectGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}');
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
@ -136,7 +128,6 @@ describe('Component vnAutocomplete', () => {
});
it(`should set displayValue finding an existing item in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
controller.field = 2;
@ -144,7 +135,7 @@ describe('Component vnAutocomplete', () => {
});
it(`should set field performing a query as the item id isn't present in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
controller.url = 'test.com';
$httpBackend.whenGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}').respond();
$httpBackend.expectGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}');
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
@ -155,23 +146,9 @@ describe('Component vnAutocomplete', () => {
});
describe('findItems()', () => {
it(`should return items empty array if the controller does not provide a url and have no items defined`, () => {
let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout});
controller.findItems('some search value');
expect(controller.items).not.toBeDefined();
});
it(`should return items array if the controller does not provide a url`, () => {
let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout});
controller.items = ['Batman', 'Bruce Wayne'];
controller.findItems('some search value');
expect(controller.items.length).toEqual(2);
});
it(`should perform a search and store the result in controller items`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.url = 'test.com';
let search = 'The Joker';
let json = JSON.stringify({where: {name: {regexp: search}}});
$httpBackend.whenGET(`test.com?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
@ -183,7 +160,7 @@ describe('Component vnAutocomplete', () => {
});
it(`should perform a search with multiple true and store the result in controller items with the checked property defined`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
controller.url = 'test.com';
let search = 'Joker';
controller.multiple = true;
let json = JSON.stringify({where: {name: {regexp: search}}});
@ -196,7 +173,7 @@ describe('Component vnAutocomplete', () => {
});
it(`should call getItems function if there's no search value`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
controller.url = 'test.com';
spyOn(controller, 'getItems');
controller.findItems();
@ -206,7 +183,7 @@ describe('Component vnAutocomplete', () => {
describe('getItems()', () => {
it(`should perfom a query to fill the items without filter`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
controller.url = 'test.com';
$httpBackend.whenGET(`test.com?filter={"skip":0,"limit":10,"order":"name ASC"}`).respond([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
$httpBackend.expectGET(`test.com?filter={"skip":0,"limit":10,"order":"name ASC"}`);
controller.getItems();

View File

@ -2,6 +2,7 @@ import './column-header.js';
describe('Component vnColumnHeader', () => {
let $componentController;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -9,11 +10,12 @@ describe('Component vnColumnHeader', () => {
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
controller = $componentController('vnColumnHeader', {});
}));
describe('onClick()', () => {
it(`should change the ordenation to DESC (descendant) if it was ASC (ascendant)`, () => {
let controller = $componentController('vnColumnHeader', {}, {gridHeader: {selectColum: () => {}}});
controller.gridHeader = {selectColum: () => {}};
controller.order = 'ASC';
controller.onClick();
@ -21,7 +23,7 @@ describe('Component vnColumnHeader', () => {
});
it(`should change the ordenation to ASC (ascendant) if it wasnt ASC`, () => {
let controller = $componentController('vnColumnHeader', {}, {gridHeader: {selectColum: () => {}}});
controller.gridHeader = {selectColum: () => {}};
controller.order = 'DESC or any other value that might occur';
controller.onClick();
@ -29,7 +31,7 @@ describe('Component vnColumnHeader', () => {
});
it(`should call the selectColum() function after changing a value`, () => {
let controller = $componentController('vnColumnHeader', {}, {gridHeader: {selectColum: () => {}}});
controller.gridHeader = {selectColum: () => {}};
controller.order = 'Change me!';
spyOn(controller.gridHeader, 'selectColum');
controller.onClick();
@ -40,7 +42,7 @@ describe('Component vnColumnHeader', () => {
describe('showArrow()', () => {
it(`should return true when the type is DESC and MouseIsOver`, () => {
let controller = $componentController('vnColumnHeader', {}, {gridHeader: {selectColum: () => {}}});
controller.gridHeader = {selectColum: () => {}};
controller.mouseIsOver = true;
let result = controller.showArrow('DESC');
@ -48,7 +50,7 @@ describe('Component vnColumnHeader', () => {
});
it(`should return true if many conditions are true`, () => {
let controller = $componentController('vnColumnHeader', {}, {gridHeader: {currentColumn: {field: 'fields should be identical'}}});
controller.gridHeader = {currentColumn: {field: 'fields should be identical'}};
controller.field = 'fields should be identical';
controller.order = 'ASC';
let result = controller.showArrow('ASC');
@ -57,7 +59,7 @@ describe('Component vnColumnHeader', () => {
});
it(`should return false without type being DESC or any other values being true`, () => {
let controller = $componentController('vnColumnHeader', {}, {gridHeader: {currentColumn: {field: 'this field isnt the same as controllers field'}}});
controller.gridHeader = {currentColumn: {field: 'fields should be identical'}};
controller.field = 'I am the controllers field';
controller.order = 'ASC';
let result = controller.showArrow('ASC');

View File

@ -6,6 +6,7 @@ describe('Component vnDatePicker', () => {
let $timeout;
let $element;
let $translate;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -17,25 +18,23 @@ describe('Component vnDatePicker', () => {
$timeout = _$timeout_;
$element = angular.element(`<div><input></div>`);
$translate = {};
controller = $componentController('vnDatePicker', {$scope, $element, $translate, $timeout});
}));
describe('_formatFlat2Angular()', () => {
it(`should format date from Y-m-d to yyyy-MM-dd`, () => {
let controller = $componentController('vnDatePicker', {$scope, $element, $translate, $timeout});
let formatedDate = controller._formatFlat2Angular(`Y-m-d`);
expect(formatedDate).toBe('yyyy-MM-dd');
});
it(`should format date from d-m-Y to dd-MM-yyyy`, () => {
let controller = $componentController('vnDatePicker', {$scope, $element, $translate, $timeout});
let formatedDate = controller._formatFlat2Angular(`d-m-Y`);
expect(formatedDate).toBe('dd-MM-yyyy');
});
it(`should split the given string into parts`, () => {
let controller = $componentController('vnDatePicker', {$scope, $element, $translate, $timeout});
controller.iniOptions = {dateFormat: 'd/m/Y'};
controller.model = '2017-12-23';

View File

@ -3,6 +3,7 @@ import './dialog.js';
describe('Component vnDialog', () => {
let $componentController;
let $element;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -11,13 +12,15 @@ describe('Component vnDialog', () => {
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
$element = angular.element('<div></div>');
controller = $componentController('vnDialog', {$element});
}));
describe('show()', () => {
it(`should define keypressHandler function, call addEventListener function and define element.style.display to block then call onOpen function`, () => {
window.innerHeight = 600;
window.innerWidth = 800;
let controller = $componentController('vnDialog', {$element}, {onOpen: () => {}, dialog: {style: {}, offsetWidth: 780, offsetHeight: 581}});
controller.onOpen = () => {};
controller.dialog = {style: {}, offsetWidth: 780, offsetHeight: 581};
spyOn(controller.document, 'addEventListener');
spyOn(controller, 'onOpen');
controller.show();
@ -31,7 +34,7 @@ describe('Component vnDialog', () => {
it(`should define keypressHandler function, call addEventListener function and define element.style.display to block and never call onOpen function`, () => {
window.innerHeight = 600;
window.innerWidth = 800;
let controller = $componentController('vnDialog', {$element}, {dialog: {style: {}, offsetWidth: 781, offsetHeight: 581}});
controller.dialog = {style: {}, offsetWidth: 781, offsetHeight: 581};
spyOn(controller.document, 'addEventListener');
controller.show();
@ -44,7 +47,6 @@ describe('Component vnDialog', () => {
describe('hide()', () => {
it(`should call fireResponse() and realHide()`, () => {
let controller = $componentController('vnDialog', {$element});
spyOn(controller, 'fireResponse');
spyOn(controller, 'realHide');
controller.hide();
@ -56,7 +58,6 @@ describe('Component vnDialog', () => {
describe('fireResponse()', () => {
it(`should return cancel as false`, () => {
let controller = $componentController('vnDialog', {$element});
let result = controller.fireResponse('I am the answer!');
expect(controller.onResponse).not.toBeDefined();
@ -65,9 +66,9 @@ describe('Component vnDialog', () => {
it(`should return onResponse()`, () => {
let text = 'I am the answer!';
let controller = $componentController('vnDialog', {$element}, {onResponse: () => {
controller.onResponse = () => {
return {response: text};
}});
};
let result = controller.fireResponse(text);
expect(result.response).toEqual(text);
@ -76,7 +77,6 @@ describe('Component vnDialog', () => {
describe('realHide()', () => {
it(`should set element.style.display and lastEvent properties and call removeEvenListener()`, () => {
let controller = $componentController('vnDialog', {$element});
spyOn(controller.document, 'removeEventListener');
expect(controller.element.style.display).not.toEqual('none');
@ -91,7 +91,6 @@ describe('Component vnDialog', () => {
describe('onButtonClick()', () => {
it(`should call realHide if cancel isn't false`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
controller.element.className = 'tpl-buttons';
let childElement = document.createElement('div');
@ -106,7 +105,6 @@ describe('Component vnDialog', () => {
});
it(`should call fireResponse with the value of response`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
controller.element.className = 'tpl-buttons';
let childElement = document.createElement('div');
@ -125,7 +123,6 @@ describe('Component vnDialog', () => {
describe('onDialogMouseDown()', () => {
it(`should set controller's lastEvent property`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
let event = {target: controller.element};
controller.onDialogMouseDown(event);
@ -136,7 +133,6 @@ describe('Component vnDialog', () => {
describe('onBackgroundMouseDown()', () => {
it(`shouldn't call hide() function as event equals lastEvent`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
let event = {target: controller.element};
controller.lastEvent = event;
@ -147,7 +143,6 @@ describe('Component vnDialog', () => {
});
it(`should call hide() function as event doesn't equal lastEvent`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
let event = {target: controller.element};
controller.lastEvent = event;
@ -161,7 +156,6 @@ describe('Component vnDialog', () => {
describe('onKeypress()', () => {
it(`should call hide() if the key pressed equal the code 27`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
let event = {target: controller.element};
event.keyCode = 27;
@ -172,7 +166,6 @@ describe('Component vnDialog', () => {
});
it(`should't call hide() as the key pressed equal the code 999`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
let event = {target: controller.element};
event.keyCode = 999;

View File

@ -5,6 +5,7 @@ describe('Component vnDropDown', () => {
let $timeout;
let $element;
let $filter;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -15,11 +16,11 @@ describe('Component vnDropDown', () => {
$element = angular.element('<div><ul><li></li></ul></div>');
$timeout = _$timeout_;
$filter = _$filter_;
controller = $componentController('vnDropDown', {$element, $timeout, $filter});
}));
describe('show() setter', () => {
it(`should define controllers _show using the value received as argument`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller._show = 'old value';
controller.show = 'new value';
@ -29,21 +30,18 @@ describe('Component vnDropDown', () => {
describe('search()', () => {
it(`should set controllers _search property with the value received`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.search = 'some filter valiue';
expect(controller._search).toEqual('some filter valiue');
});
it(`should set controllers _search property to null as the value received is an empty string`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.search = '';
expect(controller._search).toEqual(null);
});
it(`should call onFilterRest() if controllers filterAction is defined`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.filterAction = true;
spyOn(controller, 'onFilterRest');
controller.search = 'some filter valiue';
@ -52,7 +50,6 @@ describe('Component vnDropDown', () => {
});
it(`should call filterItems() if controllers filterAction is undefined`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.filterAction = undefined;
spyOn(controller, 'filterItems');
controller.search = 'some filter valiue';
@ -63,7 +60,6 @@ describe('Component vnDropDown', () => {
describe('activeOption() setter', () => {
it(`should set _activeOption as items.length if showLoadMore is defined if activeOption is bigger than items.length then call loadItems()`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'loadItems');
controller.showLoadMore = true;
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
@ -75,7 +71,6 @@ describe('Component vnDropDown', () => {
});
it(`should set _activeOption as activeOption if showLoadMore is defined if activeOption is smaller than items.length then call loadItems()`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'loadItems');
controller.showLoadMore = true;
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
@ -87,7 +82,6 @@ describe('Component vnDropDown', () => {
});
it(`should set _activeOption as items.length -1 if showLoadMore is not defined then call loadItems()`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'loadItems');
controller.showLoadMore = undefined;
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
@ -99,7 +93,6 @@ describe('Component vnDropDown', () => {
});
it(`should define _activeOption as activeOption and never call loadItems()`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'loadItems');
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}, {id: 5, name: 'Doctor X'}];
controller.activeOption = 1;
@ -112,7 +105,6 @@ describe('Component vnDropDown', () => {
describe('filterItems() setter', () => {
it(`should set _itemsFiltered using the value of items`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.items = [{id: 1, name: 'Batman'}];
controller.filterItems();
@ -120,7 +112,6 @@ describe('Component vnDropDown', () => {
});
it(`should set _itemsFiltered with the filtered value of items`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
controller.search = 'Batman';
controller.filterItems();
@ -129,7 +120,6 @@ describe('Component vnDropDown', () => {
});
it(`should set _itemsFiltered an empty array`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
controller.search = 'the Joker';
@ -139,7 +129,7 @@ describe('Component vnDropDown', () => {
describe('onFilterRest()', () => {
it(`should call the filterAction() with a constructed object as argument`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter}, {filterAction: () => {}});
controller.filterAction = () => {};
controller.search = 'Batman';
spyOn(controller, 'filterAction');
controller.onFilterRest();
@ -150,7 +140,6 @@ describe('Component vnDropDown', () => {
describe('$onChanges()', () => {
it(`should set the top css of the $element`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
let argumentObject = {show: true, top: {currentValue: 100}};
spyOn(controller.$element, 'css');
controller.$onChanges(argumentObject);
@ -159,7 +148,6 @@ describe('Component vnDropDown', () => {
});
it(`should set the width css of the $element`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
let argumentObject = {show: true, itemWidth: {currentValue: 100}};
spyOn(controller.$element, 'css');
controller.$onChanges(argumentObject);
@ -168,7 +156,6 @@ describe('Component vnDropDown', () => {
});
it(`should set the width css of the $element`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
let argumentObject = {items: {id: 1, name: 'Batman'}};
spyOn(controller, 'filterItems');
controller.$onChanges(argumentObject);
@ -179,7 +166,6 @@ describe('Component vnDropDown', () => {
describe('clearSearch()', () => {
it(`should set the controllers search property to null`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.search = true;
controller.clearSearch();
@ -189,7 +175,6 @@ describe('Component vnDropDown', () => {
describe('selectOption()', () => {
it(`should set controllers selected and show properties then call clearSearch() as _activeOption is smaller than items.length`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'clearSearch');
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
controller._activeOption = 0;
@ -201,7 +186,6 @@ describe('Component vnDropDown', () => {
});
it(`should not set controllers selected, show and never call clearSearch() as _activeOption is bigger than items.length`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'clearSearch');
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
controller._activeOption = 100;
@ -213,7 +197,7 @@ describe('Component vnDropDown', () => {
});
it(`should call loadMore() if the activeValue equals items.length`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter}, {loadMore: () => {}});
controller.loadMore = () => {};
spyOn(controller, 'loadMore');
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
controller._activeOption = 4;
@ -226,7 +210,6 @@ describe('Component vnDropDown', () => {
describe('onKeydown()', () => {
it(`should call selectOption() and preventDefault() if Enter key is pressed`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'selectOption');
controller._show = true;
controller.element = document.createElement('div');
@ -241,7 +224,6 @@ describe('Component vnDropDown', () => {
});
it(`should call clearSearch() Esc key is pressed`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'clearSearch');
controller._show = true;
controller.element = document.createElement('div');
@ -253,7 +235,6 @@ describe('Component vnDropDown', () => {
});
it(`should call clearSearch() Esc key is pressed and take off 1 from _activeOption`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
spyOn(controller, 'setScrollPosition');
controller._show = true;
@ -269,7 +250,6 @@ describe('Component vnDropDown', () => {
});
it(`should call clearSearch() Esc key is pressed and add up 1 to _activeOption`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
spyOn(controller, 'setScrollPosition');
controller._show = true;
@ -291,7 +271,6 @@ describe('Component vnDropDown', () => {
let child = $element[0].firstChild.firstChild;
child.scrollIntoView = () => {};
spyOn(child, 'scrollIntoView');
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller._activeOption = 0;
controller.setScrollPosition();
@ -301,7 +280,6 @@ describe('Component vnDropDown', () => {
describe('selectItem()', () => {
it(`should pass item to selected and set controller._show to false`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
let item = {id: 1, name: 'Batman'};
controller.selectItem(item);
@ -310,7 +288,6 @@ describe('Component vnDropDown', () => {
});
it(`should pass item to selected and set controller._show to true if the controller.multiple is defined`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
let item = {id: 1, name: 'Batman'};
controller.multiple = true;
controller.selectItem(item);
@ -322,14 +299,14 @@ describe('Component vnDropDown', () => {
describe('loadItems()', () => {
it(`should set controller._show to true`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.loadItems();
expect(controller._show).toEqual(true);
});
it(`should call loadMore() and then set controller._show to true`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter}, {showLoadMore: () => {}, loadMore: () => {}});
controller.showLoadMore = () => {};
controller.loadMore = () => {};
spyOn(controller, 'loadMore');
controller.loadItems();
@ -340,7 +317,6 @@ describe('Component vnDropDown', () => {
describe('$onInit()', () => {
it(`should add an event listener to the parent element`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller.parent, 'addEventListener');
controller.$onInit();
@ -350,7 +326,6 @@ describe('Component vnDropDown', () => {
describe('$onDestroy()', () => {
it(`should remove an event listener from the parent element`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller.parent, 'removeEventListener');
controller.$onDestroy();

View File

@ -2,6 +2,7 @@ import './grid-header.js';
describe('Component vnGridHeader', () => {
let $componentController;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -9,11 +10,11 @@ describe('Component vnGridHeader', () => {
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
controller = $componentController('vnGridHeader', {});
}));
describe('selectColum()', () => {
it(`should set controller currentColumn to equal the argument received`, () => {
let controller = $componentController('vnGridHeader', {});
let col = {columnStuff: 'some stuff'};
controller.selectColum(col);
@ -21,7 +22,6 @@ describe('Component vnGridHeader', () => {
});
it(`should set controller currentColumn.order to undefined then set currentColumn to equal the argument received`, () => {
let controller = $componentController('vnGridHeader', {});
controller.currentColumn = {field: 'some field', order: 'ordered'};
let col = {columnStuff: 'some stuff'};
controller.selectColum(col);
@ -31,7 +31,6 @@ describe('Component vnGridHeader', () => {
});
it(`should set controller currentColumn.order to undefined then call onOrder passing currentColumn as argument`, () => {
let controller = $componentController('vnGridHeader', {});
controller.onOrder = () => {};
spyOn(controller, 'onOrder');
let col = {columnStuff: 'some stuff'};

View File

@ -6,6 +6,7 @@ describe('Component vnIconMenu', () => {
let $httpBackend;
let $timeout;
let $scope;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -17,19 +18,21 @@ describe('Component vnIconMenu', () => {
$timeout = _$timeout_;
$scope = $rootScope.$new();
$element = angular.element('<div></div>');
controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
}));
describe('component vnIconMenu', () => {
describe('findItem()', () => {
it(`should return items empty array if the controller does not provide a url and have no items defined`, () => {
let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout});
controller.findItems('some search value');
controller.url = undefined;
controller.items = undefined;
let result = controller.findItems('some search value');
expect(controller.items).not.toBeDefined();
expect(result).toEqual([]);
});
it(`should return items array if the controller does not provide a url`, () => {
let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout});
controller.url = undefined;
controller.items = ['Batman', 'Bruce Wayne'];
controller.findItems('some search value');
@ -37,11 +40,10 @@ describe('Component vnIconMenu', () => {
});
it(`should perform a search and store the result in controller items`, () => {
let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
let search = 'The Joker';
let json = JSON.stringify({where: {name: {regexp: search}}});
$httpBackend.whenGET(`test.com?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
$httpBackend.expectGET(`test.com?filter=${json}`);
$httpBackend.whenGET(`${controller.url}?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
$httpBackend.expectGET(`${controller.url}?filter=${json}`);
controller.findItems(search);
$httpBackend.flush();
@ -49,7 +51,6 @@ describe('Component vnIconMenu', () => {
});
it(`should call getItems function if there's no search value`, () => {
let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
spyOn(controller, 'getItems');
controller.findItems();
@ -57,18 +58,27 @@ describe('Component vnIconMenu', () => {
});
});
// implementation pending.
describe('getItems()', () => {
it(`should perform a query and then push elements found into controller.items`, () => {
controller.items = [];
$httpBackend.whenGET(`${controller.url}?filter={}`).respond([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
$httpBackend.expectGET(`${controller.url}?filter={}`);
controller.getItems();
$httpBackend.flush();
// describe('getItems()', () => {
// it(`should perfom a query to fill the items without filter`, () => {
// let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
// $httpBackend.whenGET(`test.com?filter={}`).respond([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
// $httpBackend.expectGET(`test.com?filter={}`);
// controller.getItems();
// $httpBackend.flush();
expect(controller.items).toEqual([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
});
// expect(controller.items).toEqual([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
// });
// });
it(`should perform a query and then set controller.maxRow to false if there are no items in the controller`, () => {
controller.items = [];
controller.maxRow = true;
$httpBackend.whenGET(`${controller.url}?filter={"skip":0,"limit":true,"order":"name ASC"}`).respond(controller.items);
$httpBackend.expectGET(`${controller.url}?filter={"skip":0,"limit":true,"order":"name ASC"}`);
controller.getItems();
$httpBackend.flush();
expect(controller.maxRow).toBeFalsy();
});
});
});
});

View File

@ -2,6 +2,7 @@ import './multi-check.js';
describe('Component vnMultiCheck', () => {
let $componentController;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -9,11 +10,11 @@ describe('Component vnMultiCheck', () => {
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
controller = $componentController('vnMultiCheck', {});
}));
describe('models()', () => {
it(`should set controller _models property with the argument received`, () => {
let controller = $componentController('vnMultiCheck', {});
let argument = 'I am the model';
controller.models = argument;
@ -23,7 +24,6 @@ describe('Component vnMultiCheck', () => {
describe('checkAll()', () => {
it(`should set controller _checkAll property with the argument received then call switchChecks()`, () => {
let controller = $componentController('vnMultiCheck', {});
let argument = 'I am the model';
spyOn(controller, 'switchChecks');
controller.checkAll = argument;
@ -35,7 +35,6 @@ describe('Component vnMultiCheck', () => {
describe('switchChecks()', () => {
it(`should set checked property inside each existing elemenet when begings with no-`, () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'no-name'};
controller.models = [
{name: 'name'},
@ -52,7 +51,6 @@ describe('Component vnMultiCheck', () => {
});
it(`should set checked property inside each existing elemenet when begings with equal-`, () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'equal-name', name: 'name'};
controller.models = [
{name: null},
@ -69,7 +67,6 @@ describe('Component vnMultiCheck', () => {
});
it(`should set checked property inside each existing elemenet when begings with anything but any, all, no- or equal-`, () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'name'};
controller.models = [
{name: null},
@ -87,7 +84,6 @@ describe('Component vnMultiCheck', () => {
describe('when id is any', () => {
it('should set element checked property based on controller._checkAll', () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'any'};
controller.models = [
{name: 'name'}
@ -111,7 +107,6 @@ describe('Component vnMultiCheck', () => {
describe('when id is all', () => {
it('should set element checked property based on controller._checkAll property', () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'all'};
controller.models = [
{name: 'name'}
@ -136,7 +131,6 @@ describe('Component vnMultiCheck', () => {
describe('$onChanges()', () => {
it('should set controller.type to empty object and checkAll to zero', () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'all'};
controller._checkAll = 1;
controller.$onChanges();
@ -148,7 +142,6 @@ describe('Component vnMultiCheck', () => {
describe('$doCheck()', () => {
it('should set controller.type to empty object and checkAll based on controller.type.id', () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'all'};
controller._checkAll = 0;
controller.$doCheck();

View File

@ -4,6 +4,7 @@ describe('Component vnPaging', () => {
let $componentController;
let $scope;
let $httpBackend;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -13,11 +14,11 @@ describe('Component vnPaging', () => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
controller = $componentController('vnPaging', {$scope, $httpBackend});
}));
describe('$onChanges()', () => {
it(`should define numberPage and currentPage based on index.filter properties`, () => {
let controller = $componentController('vnPaging', {$scope, $httpBackend});
controller.index = {filter: {size: 'something', page: 'something else'}};
controller.$onChanges({index: 'simpleChange', currentValue: 'current value', previousValue: 'previous value'});
@ -26,7 +27,6 @@ describe('Component vnPaging', () => {
});
it(`should define numItems based on changes.total.currentValue`, () => {
let controller = $componentController('vnPaging', {$scope, $httpBackend});
controller.index = {filter: {size: 'something', page: 'something else'}};
controller.$onChanges({total: {currentValue: 'current value'}});
@ -36,7 +36,6 @@ describe('Component vnPaging', () => {
describe('onModelUpdated()', () => {
it(`should define controllers numItems as the result of page times size plus one`, () => {
let controller = $componentController('vnPaging', {$scope, $httpBackend});
controller.numPerPage = 2;
controller.index = {
filter: {size: 10, page: 10},
@ -50,8 +49,7 @@ describe('Component vnPaging', () => {
describe('onPageChange()', () => {
it(`should call accept() since pageChange property is undefined`, () => {
let myIndex = {accept: () => {}, filter: {page: 0}};
let controller = $componentController('vnPaging', {$scope, $httpBackend}, {index: myIndex});
controller.index = {accept: () => {}, filter: {page: 0}};
spyOn(controller.index, 'accept');
controller.onPageChange(100);
@ -59,8 +57,7 @@ describe('Component vnPaging', () => {
});
it(`should call pageChange() since pageChange property isn't undefined`, () => {
let myIndex = {accept: () => {}, filter: {page: 0}};
let controller = $componentController('vnPaging', {$scope, $httpBackend}, {index: myIndex});
controller.index = {accept: () => {}, filter: {page: 0}};
controller.pageChange = true;
spyOn(controller, 'pageChange');
controller.onPageChange(100);

View File

@ -4,6 +4,7 @@ describe('Component vnSpinner', () => {
let $componentController;
let $scope;
let $element;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -13,11 +14,11 @@ describe('Component vnSpinner', () => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$element = angular.element('<div><div></div></div>');
controller = $componentController('vnSpinner', {$scope, $element});
}));
describe('enable()', () => {
it(`should call start() based on a boolean value passed as argument`, () => {
let controller = $componentController('vnSpinner', {$scope, $element});
spyOn(controller, 'start');
spyOn(controller, 'stop');
controller.enable = true;
@ -27,7 +28,6 @@ describe('Component vnSpinner', () => {
});
it(`should call stop() based on a boolean value passed as argument`, () => {
let controller = $componentController('vnSpinner', {$scope, $element});
spyOn(controller, 'start');
spyOn(controller, 'stop');
controller.enable = false;
@ -39,7 +39,6 @@ describe('Component vnSpinner', () => {
describe('start()', () => {
it(`should call start() on the controller.materialSpinner then set controllers._enable to be truthy`, () => {
let controller = $componentController('vnSpinner', {$scope, $element});
controller.spinner = {MaterialSpinner: {start: () => {}}};
spyOn(controller.spinner.MaterialSpinner, 'start');
controller._enable = false;
@ -52,7 +51,6 @@ describe('Component vnSpinner', () => {
describe('stop()', () => {
it(`should call stop() on the controller.materialSpinner then set controllers._enable to be truthy`, () => {
let controller = $componentController('vnSpinner', {$scope, $element});
controller.spinner = {MaterialSpinner: {stop: () => {}}};
spyOn(controller.spinner.MaterialSpinner, 'stop');
controller._enable = true;

View File

@ -6,6 +6,7 @@ describe('Component vnTextfield', () => {
let $attrs;
let $timeout;
let $element;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -17,11 +18,11 @@ describe('Component vnTextfield', () => {
$attrs = {};
$timeout = _$timeout_;
$element = angular.element('<div><input></div>');
controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout});
}));
describe('value() setter', () => {
it(`should set _value, input.value and hasValue properties to null, '' and false then call mdlUpdate()`, () => {
let controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout});
spyOn(controller, 'mdlUpdate');
let testValue = '';
controller.value = testValue;
@ -33,7 +34,6 @@ describe('Component vnTextfield', () => {
});
it(`should set _value, input.value and hasValue propertiest to test, test and true then call mdlUpdate()`, () => {
let controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout});
spyOn(controller, 'mdlUpdate');
let testValue = 'test';
controller.value = testValue;

View File

@ -10,6 +10,7 @@ describe('Component vnWatcher', () => {
let $httpBackend;
let vnApp;
let $translate;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -24,11 +25,11 @@ describe('Component vnWatcher', () => {
$transitions = _$transitions_;
$httpBackend = _$httpBackend_;
$translate = _$translate_;
controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
}));
describe('$onInit()', () => {
it(`should call fetchData() if controllers get and url properties are defined`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
controller.get = () => {};
controller.url = 'test.com';
spyOn(controller, 'fetchData');
@ -38,7 +39,6 @@ describe('Component vnWatcher', () => {
});
it(`should throw an error if $onInit is called without url defined`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
controller.get = () => {};
expect(function() {
@ -49,7 +49,6 @@ describe('Component vnWatcher', () => {
describe('$onChanges()', () => {
it(`should call updateOriginalData() if controllers data is defined`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
controller.data = [];
spyOn(controller, 'updateOriginalData');
controller.$onChanges();
@ -60,7 +59,6 @@ describe('Component vnWatcher', () => {
describe('$onDestroy()', () => {
it(`should call deregisterCallback()`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
spyOn(controller, 'deregisterCallback');
controller.$onDestroy();
@ -70,7 +68,6 @@ describe('Component vnWatcher', () => {
describe('fetchData()', () => {
it(`should perform a query then store the received data into controller.data and call updateOriginalData()`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
spyOn(controller, 'updateOriginalData');
let json = {data: 'some data'};
controller.data = [1];
@ -88,7 +85,6 @@ describe('Component vnWatcher', () => {
describe('submitBack()', () => {
it(`should call controller.window.history.back() function after calling controllers submit() function`, done => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
spyOn(controller, 'submit').and.returnValue(Promise.resolve());
spyOn(controller.window.history, 'back');
controller.submitBack()
@ -102,7 +98,6 @@ describe('Component vnWatcher', () => {
describe('submitGo()', () => {
it(`should call controller.$state.go() function after calling controllers submit() function`, done => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
spyOn(controller, 'submit').and.returnValue(Promise.resolve());
spyOn(controller.$state, 'go');
let state = 'the state';
@ -118,7 +113,6 @@ describe('Component vnWatcher', () => {
describe('submit()', () => {
describe('when controller.form', () => {
it(`should call controller.form.setSubminted if controller.form is defined`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
controller.form = {$setSubmitted: () => {}};
spyOn(controller.form, '$setSubmitted');
controller.submit();
@ -127,7 +121,6 @@ describe('Component vnWatcher', () => {
});
it(`should call controller.invalidForm if controller.form.$valid is not defined`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
controller.form = {$setSubmitted: () => {}};
spyOn(controller, 'invalidForm');
controller.submit();
@ -138,7 +131,6 @@ describe('Component vnWatcher', () => {
describe('when !controller.dataChanged()', () => {
it(`should call controller.noChanges()`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
spyOn(controller, 'noChanges');
controller.submit();
@ -148,7 +140,6 @@ describe('Component vnWatcher', () => {
describe('when controller.save()', () => {
it(`should set controller.save.model property`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
controller.save = {};
controller.data = {originalInfo: 'original data', info: 'new data'};
controller.orgData = {originalInfo: 'original data'};
@ -158,7 +149,6 @@ describe('Component vnWatcher', () => {
});
it(`should call controller.save.accept() then controller.writeData`, done => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
controller.save = {accept: () => {}};
controller.data = {originalInfo: 'original data', info: 'new data'};
controller.orgData = {originalInfo: 'original data'};
@ -175,9 +165,9 @@ describe('Component vnWatcher', () => {
describe('when id is defined', () => {
it(`should perform a query then call controller.writeData()`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate}, {dataChanged: () => {
controller.dataChanged = () => {
return true;
}});
};
controller.data = {id: 2};
controller.orgData = {id: 1};
let changedData = getModifiedData(controller.data, controller.orgData);
@ -197,9 +187,9 @@ describe('Component vnWatcher', () => {
});
it(`should perform a POST query then call controller.writeData()`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate}, {dataChanged: () => {
controller.dataChanged = () => {
return true;
}});
};
controller.data = {id: 2};
controller.orgData = {id: 1};
controller.url = 'test.com';
@ -218,7 +208,6 @@ describe('Component vnWatcher', () => {
describe('writeData()', () => {
it(`should call Object.asssign() function over controllers.data with json.data, then call updateOriginalData function and finally call resolve() function`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
spyOn(controller, 'updateOriginalData');
controller.data = {};
let json = {data: 'some data'};
@ -232,7 +221,6 @@ describe('Component vnWatcher', () => {
describe('copyInNewObject()', () => {
it(`should return newCopy object if data was an object`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
let data = {id: 1, Heroname: 'Batman', name: 'Bruce Wayne'};
let result = controller.copyInNewObject(data);
@ -243,7 +231,6 @@ describe('Component vnWatcher', () => {
describe('callback()', () => {
describe(`when dataChanged() returns true and there's no state in the controller`, () => {
it(`should define controller.state, call controller.$scope.confirm.show() and return false`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
$scope.confirm = {show: jasmine.createSpy('show')};
controller.dataChanged = () => {
return true;
@ -262,7 +249,6 @@ describe('Component vnWatcher', () => {
describe(`when dataChanged() returns false and/or there's a state in the controller`, () => {
it(`should return true`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
$scope.confirm = {show: jasmine.createSpy('show')};
controller.dataChanged = () => {
return false;
@ -281,7 +267,6 @@ describe('Component vnWatcher', () => {
describe(`onConfirmResponse()`, () => {
describe(`when response is ACCEPT`, () => {
it(`should call Object.assing on controlle.data with controller.orgData then call go() on state`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
let response = 'ACCEPT';
controller.data = {};
controller.orgData = {name: 'Batman'};
@ -296,7 +281,6 @@ describe('Component vnWatcher', () => {
describe(`when response is not ACCEPT`, () => {
it(`should set controller.state to null`, () => {
let controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
let response = 'anything but ACCEPT';
controller.state = 'Batman';
controller.onConfirmResponse(response);
@ -306,3 +290,4 @@ describe('Component vnWatcher', () => {
});
});
});
// 309