create the tests fields for create Account section
This commit is contained in:
parent
daa8bafb09
commit
c5ace0a939
|
@ -166,5 +166,7 @@
|
||||||
"The selected ticket is not suitable for this route": "El ticket seleccionado no es apto para esta ruta",
|
"The selected ticket is not suitable for this route": "El ticket seleccionado no es apto para esta ruta",
|
||||||
"Sorts whole route": "Reordena ruta entera",
|
"Sorts whole route": "Reordena ruta entera",
|
||||||
"New ticket request has been created with price": "Se ha creado una nueva petición de compra '{{description}}' para el día <strong>{{shipped}}</strong>, con una cantidad de <strong>{{quantity}}</strong> y un precio de <strong>{{price}} €</strong>",
|
"New ticket request has been created with price": "Se ha creado una nueva petición de compra '{{description}}' para el día <strong>{{shipped}}</strong>, con una cantidad de <strong>{{quantity}}</strong> y un precio de <strong>{{price}} €</strong>",
|
||||||
"New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día <strong>{{shipped}}</strong>, con una cantidad de <strong>{{quantity}}</strong>"
|
"New ticket request has been created": "Se ha creado una nueva petición de compra '{{description}}' para el día <strong>{{shipped}}</strong>, con una cantidad de <strong>{{quantity}}</strong>",
|
||||||
|
"Swift / BIC cannot be empty": "Swift / BIC no puede estar vacío",
|
||||||
|
"This BIC already exist.": "Este BIC ya existe."
|
||||||
}
|
}
|
|
@ -1,8 +1,11 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.validatesPresenceOf('name', {
|
Self.validatesPresenceOf('name', {
|
||||||
message: `Name cannot be blank`
|
message: 'Name cannot be blank'
|
||||||
});
|
});
|
||||||
Self.validatesPresenceOf('bic', {
|
Self.validatesPresenceOf('bic', {
|
||||||
message: `Swift / BIC can't be empty`
|
message: 'Swift / BIC cannot be empty'
|
||||||
|
});
|
||||||
|
Self.validatesUniquenessOf('bic', {
|
||||||
|
message: 'This BIC already exist.'
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
</vn-button-bar>
|
</vn-button-bar>
|
||||||
</form>
|
</form>
|
||||||
<!-- New bankentity dialog -->
|
<!-- New bankentity dialog -->
|
||||||
<vn-new-bankentity
|
<vn-new-bank-entity
|
||||||
vn-id="bankentity"
|
vn-id="bankentity"
|
||||||
on-response="$ctrl.onResponse($response)">
|
on-response="$ctrl.onResponse($response)">
|
||||||
</vn-new-bankentity>
|
</vn-new-bank-entity>
|
|
@ -1,34 +1,68 @@
|
||||||
import './index.js';
|
import './index.js';
|
||||||
import crudModel from 'core/mocks/crud-model';
|
|
||||||
|
|
||||||
describe('Item', () => {
|
describe('Supplier Component vnSupplierAccount', () => {
|
||||||
describe('Component vnItemTags', () => {
|
let $scope;
|
||||||
let $scope;
|
let $element;
|
||||||
let controller;
|
let controller;
|
||||||
|
let $httpBackend;
|
||||||
|
beforeEach(ngModule('supplier'));
|
||||||
|
|
||||||
beforeEach(ngModule('item'));
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
||||||
|
$httpBackend = _$httpBackend_;
|
||||||
|
$scope = $rootScope.$new();
|
||||||
|
$scope.bankEntity = {
|
||||||
|
show: () => {}
|
||||||
|
};
|
||||||
|
$element = angular.element('<vn-supplier-accounts></supplier-accounts>');
|
||||||
|
controller = $componentController('vnSupplierAccount', {$element, $scope});
|
||||||
|
controller.supplierAccount = {
|
||||||
|
supplierFk: 442,
|
||||||
|
name: 'Verdnatura'
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
|
||||||
beforeEach(inject(($componentController, $rootScope) => {
|
describe('showBankEntity()', () => {
|
||||||
$scope = $rootScope.$new();
|
it('should do nothing if it default is prevented', () => {
|
||||||
$scope.model = crudModel;
|
const event = {
|
||||||
$scope.model.data = [{priority: 1}, {priority: 2}, {priority: 1}];
|
defaultPrevented: true,
|
||||||
const $element = angular.element('<vn-item-tags></vn-item-tags>');
|
preventDefault: () => {}
|
||||||
controller = $componentController('vnItemTags', {$element, $scope});
|
};
|
||||||
}));
|
jest.spyOn(event, 'preventDefault');
|
||||||
|
jest.spyOn(controller.$.bankEntity, 'show');
|
||||||
|
|
||||||
describe('getHighestPriority', () => {
|
controller.showBankEntity(event);
|
||||||
it('should return the highest priority value + 1 from the array', () => {
|
|
||||||
let result = controller.getHighestPriority();
|
|
||||||
|
|
||||||
expect(result).toEqual(3);
|
expect(event.preventDefault).not.toHaveBeenCalledWith();
|
||||||
});
|
expect(controller.$.bankEntity.show).not.toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
|
||||||
it('should return 1 when there is no priority defined', () => {
|
it('should call preventDefault() and show() when the default is not prevented', () => {
|
||||||
$scope.model.data = [];
|
const event = {
|
||||||
let result = controller.getHighestPriority();
|
defaultPrevented: false,
|
||||||
|
preventDefault: () => {}
|
||||||
|
};
|
||||||
|
jest.spyOn(event, 'preventDefault');
|
||||||
|
jest.spyOn(controller.$.bankEntity, 'show');
|
||||||
|
|
||||||
expect(result).toEqual(1);
|
controller.showBankEntity(event);
|
||||||
});
|
|
||||||
|
expect(event.preventDefault).toHaveBeenCalledWith();
|
||||||
|
expect(controller.$.bankEntity.show).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should request to create a new bank entity', () => {
|
||||||
|
controller.bankEntity = {
|
||||||
|
name: 'My new bank entity',
|
||||||
|
bic: 'ES1234',
|
||||||
|
countryFk: 1,
|
||||||
|
id: 2200
|
||||||
|
};
|
||||||
|
$httpBackend.expectPATCH(`SupplierAccounts/${controller.$.bankEntity.id}/createBankEntity`).respond({id: 2200});
|
||||||
|
controller.onBankEntityAccept();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.supplierAccount.bankEntityFk).toEqual(controller.bankEntity.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<vn-dialog class="edit"
|
<vn-dialog class="edit"
|
||||||
vn-id="bankEntityDialog"
|
vn-id="bankEntityDialog"
|
||||||
on-open="$ctrl.onOpen()"
|
on-open="$ctrl.resetLocation()"
|
||||||
on-accept="$ctrl.onAccept()"
|
on-accept="$ctrl.onAccept()"
|
||||||
message="New bank entity">
|
message="New bank entity">
|
||||||
<tpl-body>
|
<tpl-body>
|
||||||
|
|
|
@ -3,11 +3,7 @@ import Component from 'core/lib/component';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
class Controller extends Component {
|
class Controller extends Component {
|
||||||
open() {
|
resetLocation() {
|
||||||
this.$.bankEntityDialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
onOpen() {
|
|
||||||
this.location = {};
|
this.location = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +16,7 @@ class Controller extends Component {
|
||||||
if (!this.location.countryFk)
|
if (!this.location.countryFk)
|
||||||
throw new Error(`The country can't be empty`);
|
throw new Error(`The country can't be empty`);
|
||||||
|
|
||||||
this.$http.patch(`bankentities`, this.location).then(() => {
|
this.$http.post(`Bankentities`, this.location).then(() => {
|
||||||
this.vnApp.showMessage(this.$t('The bank entity has been created. You can save the data now'));
|
this.vnApp.showMessage(this.$t('The bank entity has been created. You can save the data now'));
|
||||||
this.emit('response', {$response: this.location});
|
this.emit('response', {$response: this.location});
|
||||||
});
|
});
|
||||||
|
@ -32,7 +28,7 @@ class Controller extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnNewBankentity', {
|
ngModule.vnComponent('vnNewBankEntity', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
controller: Controller,
|
controller: Controller,
|
||||||
bindings: {
|
bindings: {
|
||||||
|
|
|
@ -1,34 +1,53 @@
|
||||||
import './index';
|
import './index';
|
||||||
|
|
||||||
describe('Supplier', () => {
|
describe('Supplier Component vnNewBankEntity', () => {
|
||||||
describe('Component vnNewBankentity', () => {
|
let controller;
|
||||||
let controller;
|
let $httpBackend;
|
||||||
let $httpBackend;
|
let $scope;
|
||||||
let $scope;
|
let $element;
|
||||||
|
let vnApp;
|
||||||
|
|
||||||
beforeEach(ngModule('supplier'));
|
beforeEach(ngModule('supplier'));
|
||||||
|
|
||||||
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => {
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
$scope = $rootScope.$new();
|
vnApp = _vnApp_;
|
||||||
const $element = angular.element('<vn-dialog></vn-dialog>');
|
jest.spyOn(vnApp, 'showError');
|
||||||
controller = $componentController('vnNewBankentity', {$element, $scope});
|
$scope = $rootScope.$new();
|
||||||
controller.client = {id: 101};
|
$element = angular.element('<vn-dialog></dialog>');
|
||||||
}));
|
controller = $componentController('vnNewBankEntity', {$element, $scope});
|
||||||
|
}));
|
||||||
|
|
||||||
describe('onAccept()', () => {
|
describe('resetLocation()', () => {
|
||||||
it('should perform a POST query and show a success snackbar', () => {
|
it('should reset the location in the controller', () => {
|
||||||
let params = {countryFk: 1};
|
expect(controller.location).toBeUndefined();
|
||||||
controller.location = {countryFk: 1};
|
|
||||||
|
|
||||||
jest.spyOn(controller.vnApp, 'showMessage');
|
controller.resetLocation();
|
||||||
$httpBackend.expect('PATCH', `bankentity`, params).respond(200, params);
|
|
||||||
|
|
||||||
controller.onAccept();
|
expect(controller.location).toEqual({});
|
||||||
$httpBackend.flush();
|
});
|
||||||
|
});
|
||||||
|
|
||||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The bank entity has been created. You can save the data now');
|
describe('onAccept()', () => {
|
||||||
});
|
it('should throw an error if there is no country id in the location', () => {
|
||||||
|
jest.spyOn(controller.vnApp, 'showMessage');
|
||||||
|
|
||||||
|
controller.location = {};
|
||||||
|
|
||||||
|
controller.onAccept();
|
||||||
|
|
||||||
|
expect(controller.vnApp.showError).toHaveBeenCalledWith(`The country can't be empty`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should do add the new bank entity', () => {
|
||||||
|
controller.location = {
|
||||||
|
countryFk: 1
|
||||||
|
};
|
||||||
|
|
||||||
|
$httpBackend.expectPOST('Bankentities', controller.location).respond(200, controller.location);
|
||||||
|
|
||||||
|
controller.onAccept();
|
||||||
|
$httpBackend.flush();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
@import "variables";
|
@import "variables";
|
||||||
|
|
||||||
vn-new-bankentity {
|
vn-new-bank-entity {
|
||||||
vn-dialog {
|
vn-dialog {
|
||||||
p {
|
p {
|
||||||
color: $color-alert
|
color: $color-alert
|
||||||
|
|
Loading…
Reference in New Issue