2021-01-07 14:14:38 +00:00
|
|
|
import './index.js';
|
|
|
|
|
2021-01-15 10:24:32 +00:00
|
|
|
describe('Supplier Component vnSupplierAccount', () => {
|
|
|
|
let $scope;
|
|
|
|
let $element;
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
2021-08-31 14:37:09 +00:00
|
|
|
let $httpParamSerializer;
|
2021-01-15 10:24:32 +00:00
|
|
|
beforeEach(ngModule('supplier'));
|
2021-01-07 14:14:38 +00:00
|
|
|
|
2021-08-31 14:37:09 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
2021-01-15 10:24:32 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2021-08-31 14:37:09 +00:00
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
2021-01-15 10:24:32 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$scope.bankEntity = {
|
2021-02-17 12:32:09 +00:00
|
|
|
open: () => {}
|
2021-01-15 10:24:32 +00:00
|
|
|
};
|
2021-08-18 10:36:18 +00:00
|
|
|
$httpBackend.whenRoute('GET', 'PayMethods')
|
|
|
|
.respond([{id: 1}]);
|
2021-01-15 10:24:32 +00:00
|
|
|
$element = angular.element('<vn-supplier-accounts></supplier-accounts>');
|
|
|
|
controller = $componentController('vnSupplierAccount', {$element, $scope});
|
|
|
|
controller.supplierAccount = {
|
|
|
|
supplierFk: 442,
|
|
|
|
name: 'Verdnatura'
|
|
|
|
};
|
|
|
|
}));
|
2021-01-07 14:14:38 +00:00
|
|
|
|
2021-01-15 10:24:32 +00:00
|
|
|
describe('showBankEntity()', () => {
|
|
|
|
it('should do nothing if it default is prevented', () => {
|
|
|
|
const event = {
|
|
|
|
defaultPrevented: true,
|
|
|
|
preventDefault: () => {}
|
|
|
|
};
|
|
|
|
jest.spyOn(event, 'preventDefault');
|
2021-02-17 12:32:09 +00:00
|
|
|
jest.spyOn(controller.$.bankEntity, 'open');
|
2021-01-07 14:14:38 +00:00
|
|
|
|
2021-01-15 10:24:32 +00:00
|
|
|
controller.showBankEntity(event);
|
2021-01-07 14:14:38 +00:00
|
|
|
|
2021-01-15 10:24:32 +00:00
|
|
|
expect(event.preventDefault).not.toHaveBeenCalledWith();
|
2021-02-17 12:32:09 +00:00
|
|
|
expect(controller.$.bankEntity.open).not.toHaveBeenCalledWith();
|
2021-01-15 10:24:32 +00:00
|
|
|
});
|
|
|
|
|
2021-02-17 12:32:09 +00:00
|
|
|
it('should call preventDefault() and open() when the default is not prevented', () => {
|
2021-01-15 10:24:32 +00:00
|
|
|
const event = {
|
|
|
|
defaultPrevented: false,
|
|
|
|
preventDefault: () => {}
|
|
|
|
};
|
2021-02-17 12:32:09 +00:00
|
|
|
|
2021-01-15 10:24:32 +00:00
|
|
|
jest.spyOn(event, 'preventDefault');
|
2021-02-17 12:32:09 +00:00
|
|
|
jest.spyOn(controller.$.bankEntity, 'open');
|
2021-01-15 10:24:32 +00:00
|
|
|
|
|
|
|
controller.showBankEntity(event);
|
2021-01-07 14:14:38 +00:00
|
|
|
|
2021-01-15 10:24:32 +00:00
|
|
|
expect(event.preventDefault).toHaveBeenCalledWith();
|
2021-02-17 12:32:09 +00:00
|
|
|
expect(controller.$.bankEntity.open).toHaveBeenCalledWith();
|
2021-01-15 10:24:32 +00:00
|
|
|
});
|
|
|
|
|
2021-09-02 15:49:25 +00:00
|
|
|
it('should set pay method to wireTransfer', () => {
|
2021-01-15 10:24:32 +00:00
|
|
|
controller.bankEntity = {
|
|
|
|
name: 'My new bank entity',
|
|
|
|
bic: 'ES1234',
|
|
|
|
countryFk: 1,
|
|
|
|
id: 2200
|
|
|
|
};
|
2021-08-31 14:37:09 +00:00
|
|
|
const expectedParams = {
|
|
|
|
filter: {
|
|
|
|
where: {code: 'wireTransfer'}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const serializedParams = $httpParamSerializer(expectedParams);
|
|
|
|
|
|
|
|
$httpBackend.when('GET', `payMethods/findOne?${serializedParams}`).respond({id: 1});
|
2021-02-11 17:35:23 +00:00
|
|
|
|
|
|
|
const query = `SupplierAccounts/${controller.$.bankEntity.id}/createBankEntity`;
|
|
|
|
$httpBackend.expectPATCH(query).respond({id: 2200});
|
2021-01-15 10:24:32 +00:00
|
|
|
controller.onBankEntityAccept();
|
|
|
|
$httpBackend.flush();
|
2021-01-07 14:14:38 +00:00
|
|
|
|
2021-01-15 10:24:32 +00:00
|
|
|
expect(controller.supplierAccount.bankEntityFk).toEqual(controller.bankEntity.id);
|
2021-01-07 14:14:38 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-01-15 10:24:32 +00:00
|
|
|
|