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",
|
||||
"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": "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 => {
|
||||
Self.validatesPresenceOf('name', {
|
||||
message: `Name cannot be blank`
|
||||
message: 'Name cannot be blank'
|
||||
});
|
||||
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>
|
||||
</form>
|
||||
<!-- New bankentity dialog -->
|
||||
<vn-new-bankentity
|
||||
<vn-new-bank-entity
|
||||
vn-id="bankentity"
|
||||
on-response="$ctrl.onResponse($response)">
|
||||
</vn-new-bankentity>
|
||||
</vn-new-bank-entity>
|
|
@ -1,34 +1,68 @@
|
|||
import './index.js';
|
||||
import crudModel from 'core/mocks/crud-model';
|
||||
|
||||
describe('Item', () => {
|
||||
describe('Component vnItemTags', () => {
|
||||
let $scope;
|
||||
let controller;
|
||||
describe('Supplier Component vnSupplierAccount', () => {
|
||||
let $scope;
|
||||
let $element;
|
||||
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) => {
|
||||
$scope = $rootScope.$new();
|
||||
$scope.model = crudModel;
|
||||
$scope.model.data = [{priority: 1}, {priority: 2}, {priority: 1}];
|
||||
const $element = angular.element('<vn-item-tags></vn-item-tags>');
|
||||
controller = $componentController('vnItemTags', {$element, $scope});
|
||||
}));
|
||||
describe('showBankEntity()', () => {
|
||||
it('should do nothing if it default is prevented', () => {
|
||||
const event = {
|
||||
defaultPrevented: true,
|
||||
preventDefault: () => {}
|
||||
};
|
||||
jest.spyOn(event, 'preventDefault');
|
||||
jest.spyOn(controller.$.bankEntity, 'show');
|
||||
|
||||
describe('getHighestPriority', () => {
|
||||
it('should return the highest priority value + 1 from the array', () => {
|
||||
let result = controller.getHighestPriority();
|
||||
controller.showBankEntity(event);
|
||||
|
||||
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', () => {
|
||||
$scope.model.data = [];
|
||||
let result = controller.getHighestPriority();
|
||||
it('should call preventDefault() and show() when the default is not prevented', () => {
|
||||
const event = {
|
||||
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-id="bankEntityDialog"
|
||||
on-open="$ctrl.onOpen()"
|
||||
on-open="$ctrl.resetLocation()"
|
||||
on-accept="$ctrl.onAccept()"
|
||||
message="New bank entity">
|
||||
<tpl-body>
|
||||
|
|
|
@ -3,11 +3,7 @@ import Component from 'core/lib/component';
|
|||
import './style.scss';
|
||||
|
||||
class Controller extends Component {
|
||||
open() {
|
||||
this.$.bankEntityDialog.show();
|
||||
}
|
||||
|
||||
onOpen() {
|
||||
resetLocation() {
|
||||
this.location = {};
|
||||
}
|
||||
|
||||
|
@ -20,7 +16,7 @@ class Controller extends Component {
|
|||
if (!this.location.countryFk)
|
||||
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.emit('response', {$response: this.location});
|
||||
});
|
||||
|
@ -32,7 +28,7 @@ class Controller extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
ngModule.vnComponent('vnNewBankentity', {
|
||||
ngModule.vnComponent('vnNewBankEntity', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
|
|
|
@ -1,34 +1,53 @@
|
|||
import './index';
|
||||
|
||||
describe('Supplier', () => {
|
||||
describe('Component vnNewBankentity', () => {
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $scope;
|
||||
describe('Supplier Component vnNewBankEntity', () => {
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $scope;
|
||||
let $element;
|
||||
let vnApp;
|
||||
|
||||
beforeEach(ngModule('supplier'));
|
||||
beforeEach(ngModule('supplier'));
|
||||
|
||||
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$scope = $rootScope.$new();
|
||||
const $element = angular.element('<vn-dialog></vn-dialog>');
|
||||
controller = $componentController('vnNewBankentity', {$element, $scope});
|
||||
controller.client = {id: 101};
|
||||
}));
|
||||
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _vnApp_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
vnApp = _vnApp_;
|
||||
jest.spyOn(vnApp, 'showError');
|
||||
$scope = $rootScope.$new();
|
||||
$element = angular.element('<vn-dialog></dialog>');
|
||||
controller = $componentController('vnNewBankEntity', {$element, $scope});
|
||||
}));
|
||||
|
||||
describe('onAccept()', () => {
|
||||
it('should perform a POST query and show a success snackbar', () => {
|
||||
let params = {countryFk: 1};
|
||||
controller.location = {countryFk: 1};
|
||||
describe('resetLocation()', () => {
|
||||
it('should reset the location in the controller', () => {
|
||||
expect(controller.location).toBeUndefined();
|
||||
|
||||
jest.spyOn(controller.vnApp, 'showMessage');
|
||||
$httpBackend.expect('PATCH', `bankentity`, params).respond(200, params);
|
||||
controller.resetLocation();
|
||||
|
||||
controller.onAccept();
|
||||
$httpBackend.flush();
|
||||
expect(controller.location).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
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";
|
||||
|
||||
vn-new-bankentity {
|
||||
vn-new-bank-entity {
|
||||
vn-dialog {
|
||||
p {
|
||||
color: $color-alert
|
||||
|
|
Loading…
Reference in New Issue