2021-01-07 14:14:38 +00:00
|
|
|
import './index.js';
|
2021-09-08 07:44:46 +00:00
|
|
|
import watcher from 'core/mocks/watcher';
|
|
|
|
import crudModel from 'core/mocks/crud-model';
|
2021-01-07 14:14:38 +00:00
|
|
|
|
2021-01-15 10:24:32 +00:00
|
|
|
describe('Supplier Component vnSupplierAccount', () => {
|
|
|
|
let $scope;
|
|
|
|
let controller;
|
|
|
|
beforeEach(ngModule('supplier'));
|
2021-01-07 14:14:38 +00:00
|
|
|
|
2021-01-15 10:24:32 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
|
|
|
$scope = $rootScope.$new();
|
2021-09-08 07:44:46 +00:00
|
|
|
$scope.model = crudModel;
|
|
|
|
$scope.watcher = watcher;
|
|
|
|
|
2021-01-15 10:24:32 +00:00
|
|
|
$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-09-08 07:44:46 +00:00
|
|
|
|
|
|
|
const $element = angular.element('<vn-supplier-account></vn-supplier-account>');
|
2021-01-15 10:24:32 +00:00
|
|
|
controller = $componentController('vnSupplierAccount', {$element, $scope});
|
|
|
|
controller.supplierAccount = {
|
|
|
|
supplierFk: 442,
|
|
|
|
name: 'Verdnatura'
|
|
|
|
};
|
|
|
|
}));
|
2021-01-07 14:14:38 +00:00
|
|
|
|
2021-09-15 15:58:58 +00:00
|
|
|
describe('onAccept()', () => {
|
|
|
|
it('should set the created bank entity id into the target account', () => {
|
|
|
|
controller.supplierAccounts = [{}, {}, {}];
|
2021-01-07 14:14:38 +00:00
|
|
|
|
2021-09-15 15:58:58 +00:00
|
|
|
const data = {
|
|
|
|
id: 999,
|
|
|
|
index: 1
|
2021-08-31 14:37:09 +00:00
|
|
|
};
|
|
|
|
|
2021-09-15 15:58:58 +00:00
|
|
|
controller.onAccept(data);
|
2021-02-11 17:35:23 +00:00
|
|
|
|
2021-09-15 15:58:58 +00:00
|
|
|
const targetAccount = controller.supplierAccounts[data.index];
|
2021-01-07 14:14:38 +00:00
|
|
|
|
2021-09-15 15:58:58 +00:00
|
|
|
expect(targetAccount.bankEntityFk).toEqual(data.id);
|
2021-01-07 14:14:38 +00:00
|
|
|
});
|
|
|
|
});
|
2021-09-08 07:44:46 +00:00
|
|
|
|
|
|
|
describe('onSubmit__()', () => {
|
|
|
|
it(`should reload the card`, () => {
|
|
|
|
controller.card = {reload: () => {}};
|
|
|
|
jest.spyOn($scope.watcher, 'check');
|
|
|
|
jest.spyOn($scope.watcher, 'notifySaved');
|
|
|
|
jest.spyOn($scope.watcher, 'updateOriginalData');
|
|
|
|
jest.spyOn(controller.card, 'reload');
|
|
|
|
jest.spyOn($scope.model, 'save');
|
|
|
|
console.log($scope.model);
|
|
|
|
controller.onSubmit();
|
|
|
|
|
|
|
|
expect($scope.model.save).toHaveBeenCalledWith();
|
|
|
|
expect($scope.watcher.updateOriginalData).toHaveBeenCalledWith();
|
|
|
|
expect($scope.watcher.check).toHaveBeenCalledWith();
|
|
|
|
expect($scope.watcher.notifySaved).toHaveBeenCalledWith();
|
|
|
|
expect(controller.card.reload).toHaveBeenCalledWith();
|
|
|
|
|
|
|
|
expect(controller.$.payMethodToTransfer.show).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
fdescribe('onSubmit()', () => {
|
|
|
|
it(`should reload the card`, done => {
|
|
|
|
controller.card = {reload: () => {}};
|
|
|
|
controller.$.payMethodToTransfer = {show: () => {}};
|
|
|
|
jest.spyOn(controller.$.payMethodToTransfer, 'show');
|
|
|
|
jest.spyOn(controller.$.model, 'save').mockReturnValue(new Promise(resolve => {
|
|
|
|
return resolve({
|
|
|
|
id: 1234
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
jest.spyOn(controller.card, 'reload').mockReturnValue(new Promise(resolve => {
|
|
|
|
return resolve({
|
|
|
|
id: 1234
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
controller.wireTransferFk = 'a';
|
|
|
|
controller.supplier = {payMethodFk: 'b'};
|
|
|
|
controller.onSubmit().then(() => {
|
|
|
|
expect(controller.card.reload).toHaveBeenCalledWith();
|
|
|
|
expect(controller.$.payMethodToTransfer.show).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
}).catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
2021-01-07 14:14:38 +00:00
|
|
|
});
|
2021-01-15 10:24:32 +00:00
|
|
|
|