2018-08-09 12:42:02 +00:00
|
|
|
import './index';
|
2019-02-28 07:55:34 +00:00
|
|
|
import crudModel from 'core/mocks/crud-model';
|
2018-08-09 12:42:02 +00:00
|
|
|
|
|
|
|
describe('Client', () => {
|
|
|
|
describe('Component vnClientAddressIndex', () => {
|
|
|
|
let controller;
|
|
|
|
let $scope;
|
2019-02-28 07:55:34 +00:00
|
|
|
let $stateParams;
|
2018-08-09 12:42:02 +00:00
|
|
|
let $httpBackend;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2018-08-09 12:42:02 +00:00
|
|
|
|
2019-02-28 07:55:34 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$stateParams_, _$httpBackend_) => {
|
|
|
|
$stateParams = _$stateParams_;
|
|
|
|
$stateParams.id = 1;
|
2018-08-09 12:42:02 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$scope = $rootScope.$new();
|
2020-03-17 10:17:50 +00:00
|
|
|
const $element = angular.element('<vn-client-address-index></vn-client-address-index>');
|
|
|
|
controller = $componentController('vnClientAddressIndex', {$element, $scope});
|
2019-02-28 07:55:34 +00:00
|
|
|
controller.client = {id: 101, defaultAddressFk: 121};
|
2020-03-17 10:17:50 +00:00
|
|
|
controller.$.model = crudModel;
|
2018-08-09 12:42:02 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('setDefault()', () => {
|
2019-02-28 07:55:34 +00:00
|
|
|
it('should perform a PATCH and set a value to defaultAddressFk property', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'sortAddresses');
|
2019-02-28 07:55:34 +00:00
|
|
|
let address = {id: 1};
|
|
|
|
let data = {defaultAddressFk: address.id};
|
|
|
|
let expectedResult = {defaultAddressFk: address.id};
|
2018-08-09 12:42:02 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('PATCH', `Clients/1`, data).respond(200, expectedResult);
|
|
|
|
$httpBackend.expect('PATCH', `Clients/1`, data);
|
2018-08-09 12:42:02 +00:00
|
|
|
controller.setDefault(address);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2019-02-28 07:55:34 +00:00
|
|
|
expect(controller.client.defaultAddressFk).toEqual(1);
|
|
|
|
expect(controller.sortAddresses).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('isDefaultAddress()', () => {
|
|
|
|
it('should return true if a passed address is the current default one', () => {
|
|
|
|
let address = {id: 121};
|
|
|
|
let result = controller.isDefaultAddress(address);
|
|
|
|
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if a passed address is the current default one', () => {
|
|
|
|
let address = {id: 1};
|
|
|
|
let result = controller.isDefaultAddress(address);
|
|
|
|
|
|
|
|
expect(result).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('sortAddresses()', () => {
|
|
|
|
it('should return an array of addresses sorted by client defaultAddressFk', () => {
|
|
|
|
controller.client.defaultAddressFk = 123;
|
|
|
|
controller.addresses = [
|
|
|
|
{id: 121, nickname: 'My address one'},
|
|
|
|
{id: 122, nickname: 'My address two'},
|
|
|
|
{id: 123, nickname: 'My address three'}];
|
|
|
|
|
|
|
|
controller.sortAddresses();
|
|
|
|
|
|
|
|
expect(controller.addresses[0].id).toEqual(123);
|
2018-08-09 12:42:02 +00:00
|
|
|
});
|
|
|
|
});
|
2020-06-12 08:53:33 +00:00
|
|
|
|
|
|
|
describe('exprBuilder()', () => {
|
|
|
|
it('should return a filter based on a search by id', () => {
|
|
|
|
const filter = controller.exprBuilder('search', '123');
|
|
|
|
|
|
|
|
expect(filter).toEqual({id: '123'});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return a filter based on a search by name', () => {
|
|
|
|
const filter = controller.exprBuilder('search', 'Bruce Wayne');
|
|
|
|
|
|
|
|
expect(filter).toEqual({nickname: {like: '%Bruce Wayne%'}});
|
|
|
|
});
|
|
|
|
});
|
2018-08-09 12:42:02 +00:00
|
|
|
});
|
|
|
|
});
|