71 lines
2.6 KiB
JavaScript
71 lines
2.6 KiB
JavaScript
import './index';
|
|
import crudModel from 'core/mocks/crud-model';
|
|
|
|
describe('Client', () => {
|
|
describe('Component vnClientAddressIndex', () => {
|
|
let controller;
|
|
let $scope;
|
|
let $stateParams;
|
|
let $httpBackend;
|
|
|
|
beforeEach(ngModule('client'));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$stateParams_, _$httpBackend_) => {
|
|
$stateParams = _$stateParams_;
|
|
$stateParams.id = 1;
|
|
$httpBackend = _$httpBackend_;
|
|
$scope = $rootScope.$new();
|
|
controller = $componentController('vnClientAddressIndex', {$stateParams, $scope});
|
|
controller.client = {id: 101, defaultAddressFk: 121};
|
|
controller.$scope.model = crudModel;
|
|
}));
|
|
|
|
describe('setDefault()', () => {
|
|
it('should perform a PATCH and set a value to defaultAddressFk property', () => {
|
|
jest.spyOn(controller, 'sortAddresses');
|
|
let address = {id: 1};
|
|
let data = {defaultAddressFk: address.id};
|
|
let expectedResult = {defaultAddressFk: address.id};
|
|
|
|
$httpBackend.when('PATCH', `Clients/1`, data).respond(200, expectedResult);
|
|
$httpBackend.expect('PATCH', `Clients/1`, data);
|
|
controller.setDefault(address);
|
|
$httpBackend.flush();
|
|
|
|
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);
|
|
});
|
|
});
|
|
});
|
|
});
|