refactor(newBankEntity): client.billingData and supplier.account refactor to use newBankEntity Dialog
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
47e70f7c3c
commit
34038b885c
|
@ -11,7 +11,7 @@ class Controller extends Dialog {
|
||||||
throw new Error(`The country can't be empty`);
|
throw new Error(`The country can't be empty`);
|
||||||
|
|
||||||
return this.$http.post(`bankEntities`, this.data)
|
return this.$http.post(`bankEntities`, this.data)
|
||||||
.then(res => super.responseHandler(response))
|
.then(() => super.responseHandler(response))
|
||||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,49 +5,34 @@ describe('Salix Component vnNewBankEntity', () => {
|
||||||
let $httpBackend;
|
let $httpBackend;
|
||||||
let $scope;
|
let $scope;
|
||||||
let $element;
|
let $element;
|
||||||
let vnApp;
|
|
||||||
|
|
||||||
beforeEach(ngModule('salix'));
|
beforeEach(ngModule('salix'));
|
||||||
|
|
||||||
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => {
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
vnApp = _vnApp_;
|
|
||||||
jest.spyOn(vnApp, 'showError');
|
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
$element = angular.element('<vn-dialog></dialog>');
|
$element = angular.element('<vn-dialog></vn-dialog>');
|
||||||
controller = $componentController('vnNewBankEntity', {$element, $scope});
|
const $transclude = {
|
||||||
|
$$boundTransclude: {
|
||||||
|
$$slots: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
controller = $componentController('vnNewBankEntity', {$element, $scope, $transclude});
|
||||||
|
controller.vnApp = {showSuccess: jest.fn()};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('resetData()', () => {
|
describe('responseHandler()', () => {
|
||||||
it('should reset the location in the controller', () => {
|
it('should show a success message after the query to bankEntities', () => {
|
||||||
expect(controller.data).toBeUndefined();
|
|
||||||
|
|
||||||
controller.resetData();
|
|
||||||
|
|
||||||
expect(controller.data).toEqual({});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('onAccept()', () => {
|
|
||||||
it('should throw an error if there is no country id in the location', () => {
|
|
||||||
jest.spyOn(controller.vnApp, 'showMessage');
|
|
||||||
|
|
||||||
controller.data = {};
|
|
||||||
|
|
||||||
controller.onAccept();
|
|
||||||
|
|
||||||
expect(controller.vnApp.showError).toHaveBeenCalledWith(`The country can't be empty`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should do add the new bank entity', () => {
|
|
||||||
controller.data = {
|
controller.data = {
|
||||||
countryFk: 1
|
countryFk: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
$httpBackend.expectPOST('bankEntities', controller.data).respond(200, controller.data);
|
$httpBackend.expectPOST('bankEntities', controller.data).respond(200);
|
||||||
|
|
||||||
controller.onAccept();
|
controller.responseHandler('accept');
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
<vn-icon-button
|
<vn-icon-button
|
||||||
vn-auto
|
vn-auto
|
||||||
icon="add_circle"
|
icon="add_circle"
|
||||||
ng-click="$ctrl.onAddEntityClick($event)"
|
vn-click-stop="bankEntity.show({countryFk: $ctrl.client.countryFk})"
|
||||||
vn-tooltip="New bank entity"
|
vn-tooltip="New bank entity"
|
||||||
vn-acl="salesAssistant">
|
vn-acl="salesAssistant">
|
||||||
</vn-icon-button>
|
</vn-icon-button>
|
||||||
|
@ -111,5 +111,5 @@
|
||||||
<!-- New bankentity dialog -->
|
<!-- New bankentity dialog -->
|
||||||
<vn-new-bank-entity
|
<vn-new-bank-entity
|
||||||
vn-id="bankEntity"
|
vn-id="bankEntity"
|
||||||
on-response="$ctrl.onResponse($response)">
|
on-accept="$ctrl.onAccept($data)">
|
||||||
</vn-new-bank-entity>
|
</vn-new-bank-entity>
|
|
@ -37,16 +37,8 @@ export default class Controller extends Section {
|
||||||
return payMethod || iban || dueDay;
|
return payMethod || iban || dueDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddEntityClick(event) {
|
onAccept(data) {
|
||||||
event.preventDefault();
|
this.client.bankEntityFk = data.id;
|
||||||
this.newBankEntity = {
|
|
||||||
countryFk: Number.parseInt(this.client.countryFk)
|
|
||||||
};
|
|
||||||
this.$.bankEntity.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
onResponse(response) {
|
|
||||||
this.client.bankEntityFk = response.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get ibanCountry() {
|
get ibanCountry() {
|
||||||
|
|
|
@ -35,10 +35,10 @@ describe('Client', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onResponse()', () => {
|
describe('onAccept()', () => {
|
||||||
it('should assign the response id to the client bankEntityFk', () => {
|
it('should assign the response id to the client bankEntityFk', () => {
|
||||||
const expectedResponse = {id: 999};
|
const expectedResponse = {id: 999};
|
||||||
controller.onResponse(expectedResponse);
|
controller.onAccept(expectedResponse);
|
||||||
|
|
||||||
expect(controller.client.bankEntityFk).toEqual(expectedResponse.id);
|
expect(controller.client.bankEntityFk).toEqual(expectedResponse.id);
|
||||||
});
|
});
|
||||||
|
|
|
@ -30,9 +30,10 @@
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
<append>
|
<append>
|
||||||
<vn-icon-button
|
<vn-icon-button
|
||||||
|
vn-auto
|
||||||
icon="add_circle"
|
icon="add_circle"
|
||||||
vn-tooltip="New bank entity"
|
vn-click-stop="bankEntity.show({index: $index})"
|
||||||
ng-click="$ctrl.showBankEntity($event, $index)">
|
vn-tooltip="New bank entity">
|
||||||
</vn-icon-button>
|
</vn-icon-button>
|
||||||
</append>
|
</append>
|
||||||
<vn-textfield vn-three
|
<vn-textfield vn-three
|
||||||
|
@ -69,5 +70,5 @@
|
||||||
<!-- New bankentity dialog -->
|
<!-- New bankentity dialog -->
|
||||||
<vn-new-bank-entity
|
<vn-new-bank-entity
|
||||||
vn-id="bankEntity"
|
vn-id="bankEntity"
|
||||||
on-response="$ctrl.onResponse($response)">
|
on-accept="$ctrl.onAccept($data)">
|
||||||
</vn-new-bank-entity>
|
</vn-new-bank-entity>
|
|
@ -18,23 +18,10 @@ class Controller extends Section {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onResponse(response) {
|
onAccept(data) {
|
||||||
const data = this.$.model.data;
|
const accounts = this.supplierAccounts;
|
||||||
const supplierAccount = data[this.currentRowIndex];
|
const targetAccount = accounts[data.index];
|
||||||
supplierAccount.bankEntityFk = response.id;
|
targetAccount.bankEntityFk = data.id;
|
||||||
}
|
|
||||||
|
|
||||||
showBankEntity(event, $index) {
|
|
||||||
if (event.defaultPrevented) return;
|
|
||||||
event.preventDefault();
|
|
||||||
this.currentRowIndex = $index;
|
|
||||||
this.$.bankEntity.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
onBankEntityAccept() {
|
|
||||||
const query = `SupplierAccounts/${this.$params.id}/createBankEntity`;
|
|
||||||
return this.$http.patch(query, this.newBankEntity)
|
|
||||||
.then(res => this.supplierAccount.bankEntityFk = res.data.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
|
|
|
@ -4,11 +4,9 @@ describe('Supplier Component vnSupplierAccount', () => {
|
||||||
let $scope;
|
let $scope;
|
||||||
let $element;
|
let $element;
|
||||||
let controller;
|
let controller;
|
||||||
let $httpBackend;
|
|
||||||
beforeEach(ngModule('supplier'));
|
beforeEach(ngModule('supplier'));
|
||||||
|
|
||||||
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
||||||
$httpBackend = _$httpBackend_;
|
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
$scope.bankEntity = {
|
$scope.bankEntity = {
|
||||||
open: () => {}
|
open: () => {}
|
||||||
|
@ -21,50 +19,20 @@ describe('Supplier Component vnSupplierAccount', () => {
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('showBankEntity()', () => {
|
describe('onAccept()', () => {
|
||||||
it('should do nothing if it default is prevented', () => {
|
it('should set the created bank entity id into the target account', () => {
|
||||||
const event = {
|
controller.supplierAccounts = [{}, {}, {}];
|
||||||
defaultPrevented: true,
|
|
||||||
preventDefault: () => {}
|
|
||||||
};
|
|
||||||
jest.spyOn(event, 'preventDefault');
|
|
||||||
jest.spyOn(controller.$.bankEntity, 'open');
|
|
||||||
|
|
||||||
controller.showBankEntity(event);
|
const data = {
|
||||||
|
id: 999,
|
||||||
expect(event.preventDefault).not.toHaveBeenCalledWith();
|
index: 1
|
||||||
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');
|
controller.onAccept(data);
|
||||||
jest.spyOn(controller.$.bankEntity, 'open');
|
|
||||||
|
|
||||||
controller.showBankEntity(event);
|
const targetAccount = controller.supplierAccounts[data.index];
|
||||||
|
|
||||||
expect(event.preventDefault).toHaveBeenCalledWith();
|
expect(targetAccount.bankEntityFk).toEqual(data.id);
|
||||||
expect(controller.$.bankEntity.open).toHaveBeenCalledWith();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should now request to create a new bank entity', () => {
|
|
||||||
controller.bankEntity = {
|
|
||||||
name: 'My new bank entity',
|
|
||||||
bic: 'ES1234',
|
|
||||||
countryFk: 1,
|
|
||||||
id: 2200
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue