salix/modules/supplier/front/account/index.spec.js

84 lines
2.8 KiB
JavaScript

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