updated tests
gitea/salix/1466-print_refactor This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-11-06 09:32:54 +01:00
parent 23f6c8843d
commit 3d701f534a
8 changed files with 96 additions and 60 deletions

View File

@ -1,20 +1,27 @@
import './index.js'; import './index.js';
describe('Item Component vnClaimDescriptor', () => { describe('Item Component vnClaimDescriptor', () => {
let $httpParamSerializer;
let $httpBackend; let $httpBackend;
let controller; let controller;
beforeEach(ngModule('claim')); beforeEach(ngModule('claim'));
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnClaimDescriptor'); controller = $componentController('vnClaimDescriptor');
controller.claim = {id: 2}; controller.claim = {id: 2, clientFk: 101, client: {email: 'client@email'}};
})); }));
describe('showPickupOrder()', () => { describe('showPickupOrder()', () => {
it('should open a new window showing a pickup order PDF document', () => { it('should open a new window showing a pickup order PDF document', () => {
let expectedPath = 'report/rpt-claim-pickup-order?claimFk=2'; const params = {
clientId: controller.claim.clientFk,
claimId: controller.claim.id
};
const serializedParams = $httpParamSerializer(params);
let expectedPath = `api/report/claim-pickup-order?${serializedParams}`;
spyOn(window, 'open'); spyOn(window, 'open');
controller.showPickupOrder(); controller.showPickupOrder();
@ -38,8 +45,15 @@ describe('Item Component vnClaimDescriptor', () => {
it('should make a query and call vnApp.showMessage() if the response is accept', () => { it('should make a query and call vnApp.showMessage() if the response is accept', () => {
spyOn(controller.vnApp, 'showMessage'); spyOn(controller.vnApp, 'showMessage');
$httpBackend.when('POST', `email/claim-pickup-order`, {claimFk: 2}).respond(); const params = {
$httpBackend.expect('POST', `email/claim-pickup-order`, {claimFk: 2}).respond(); recipient: 'client@email',
clientId: controller.claim.clientFk,
claimId: controller.claim.id
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `email/claim-pickup-order?${serializedParams}`).respond();
$httpBackend.expect('GET', `email/claim-pickup-order?${serializedParams}`).respond();
controller.sendPickupOrder('accept'); controller.sendPickupOrder('accept');
$httpBackend.flush(); $httpBackend.flush();

View File

@ -37,7 +37,6 @@ class Controller {
} }
onDrop($event) { onDrop($event) {
console.log($event);
const files = $event.dataTransfer.files; const files = $event.dataTransfer.files;
this.setDefaultParams().then(() => { this.setDefaultParams().then(() => {
this.dms.files = files; this.dms.files = files;

View File

@ -27,17 +27,6 @@ class Controller {
this.clientSample.recipient = value.email; this.clientSample.recipient = value.email;
} }
jsonToQuery(json) {
let query = '';
for (let param in json) {
if (query != '')
query += '&';
query += `${param}=${json[param]}`;
}
return query;
}
showPreview() { showPreview() {
let sampleType = this.$scope.sampleType.selection; let sampleType = this.$scope.sampleType.selection;

View File

@ -2,6 +2,7 @@ import './index';
describe('Client', () => { describe('Client', () => {
describe('Component vnClientSampleCreate', () => { describe('Component vnClientSampleCreate', () => {
let $httpParamSerializer;
let $scope; let $scope;
let $httpBackend; let $httpBackend;
let $state; let $state;
@ -9,7 +10,7 @@ describe('Client', () => {
beforeEach(ngModule('client')); beforeEach(ngModule('client'));
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope, _$state_) => { beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope, _$state_, _$httpParamSerializer_) => {
$scope = $rootScope.$new(); $scope = $rootScope.$new();
$scope.sampleType = {}; $scope.sampleType = {};
$scope.watcher = { $scope.watcher = {
@ -35,26 +36,11 @@ describe('Client', () => {
$state = _$state_; $state = _$state_;
$state.params.id = 101; $state.params.id = 101;
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnClientSampleCreate', {$scope, $state}); controller = $componentController('vnClientSampleCreate', {$scope, $state});
})); }));
describe('jsonToQuery()', () => { xdescribe('showPreview()', () => {
it(`should convert a JSON object with clientFk property to query params`, () => {
let myObject = {clientFk: 101};
let result = controller.jsonToQuery(myObject);
expect(result).toEqual('clientFk=101');
});
it(`should convert a JSON object with clientFk and companyFk properties to query params`, () => {
let myObject = {clientFk: 101, companyFk: 442};
let result = controller.jsonToQuery(myObject);
expect(result).toEqual('clientFk=101&companyFk=442');
});
});
describe('showPreview()', () => {
it(`should perform a query (GET) and open a sample preview`, () => { it(`should perform a query (GET) and open a sample preview`, () => {
spyOn(controller.$scope.showPreview, 'show'); spyOn(controller.$scope.showPreview, 'show');
@ -69,8 +55,14 @@ describe('Client', () => {
let event = {preventDefault: () => {}}; let event = {preventDefault: () => {}};
$httpBackend.when('GET', `email/MyReport?clientFk=101`).respond(true); const params = {
$httpBackend.expect('GET', `email/MyReport?clientFk=101`); clientId: 101,
isPreview: true
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true);
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`);
controller.showPreview(event); controller.showPreview(event);
$httpBackend.flush(); $httpBackend.flush();
@ -92,8 +84,15 @@ describe('Client', () => {
let event = {preventDefault: () => {}}; let event = {preventDefault: () => {}};
$httpBackend.when('GET', `email/MyReport?clientFk=101&companyFk=442`).respond(true); const params = {
$httpBackend.expect('GET', `email/MyReport?clientFk=101&companyFk=442`); clientId: 101,
companyId: 442,
isPreview: true
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true);
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`);
controller.showPreview(event); controller.showPreview(event);
$httpBackend.flush(); $httpBackend.flush();
@ -123,8 +122,13 @@ describe('Client', () => {
clientFk: 101 clientFk: 101
}; };
$httpBackend.when('POST', `email/MyReport?clientFk=101`).respond(true); const params = {
$httpBackend.expect('POST', `email/MyReport?clientFk=101`); clientId: 101
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true);
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`);
controller.sendSample(); controller.sendSample();
$httpBackend.flush(); $httpBackend.flush();
@ -144,8 +148,14 @@ describe('Client', () => {
companyFk: 442 companyFk: 442
}; };
$httpBackend.when('POST', `email/MyReport?clientFk=101&companyFk=442`).respond(true); const params = {
$httpBackend.expect('POST', `email/MyReport?clientFk=101&companyFk=442`); clientId: 101,
companyId: 442
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true);
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`);
controller.sendSample(); controller.sendSample();
$httpBackend.flush(); $httpBackend.flush();

View File

@ -197,7 +197,7 @@
<vn-confirm <vn-confirm
vn-id="confirm-delivery-note" vn-id="confirm-delivery-note"
on-response="$ctrl.sendDeliveryNote($response)" on-accept="$ctrl.sendDeliveryNote()"
question="Send Delivery Note" question="Send Delivery Note"
message="Are you sure you want to send it?"> message="Are you sure you want to send it?">
</vn-confirm> </vn-confirm>

View File

@ -211,18 +211,16 @@ class Controller {
window.open(url); window.open(url);
} }
sendDeliveryNote(response) { sendDeliveryNote() {
if (response === 'accept') { const params = {
const params = { recipient: this.ticket.client.email,
recipient: this.ticket.client.email, clientId: this.ticket.client.id,
clientId: this.ticket.client.id, ticketId: this.ticket.id
ticketId: this.ticket.id };
}; const serializedParams = this.$httpParamSerializer(params);
const serializedParams = this.$httpParamSerializer(params); this.$http.get(`email/delivery-note?${serializedParams}`).then(
this.$http.get(`email/delivery-note?${serializedParams}`).then( () => this.vnApp.showMessage(this.$translate.instant('Notification sent!'))
() => this.vnApp.showMessage(this.$translate.instant('Notification sent!')) );
);
}
} }
showSMSDialog() { showSMSDialog() {

View File

@ -1,13 +1,14 @@
import './index.js'; import './index.js';
describe('Ticket Component vnTicketDescriptor', () => { describe('Ticket Component vnTicketDescriptor', () => {
let $httpParamSerializer;
let $httpBackend; let $httpBackend;
let controller; let controller;
let $state; let $state;
beforeEach(ngModule('ticket')); beforeEach(ngModule('ticket'));
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => { beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
$state = _$state_; $state = _$state_;
$state.getCurrentPath = () => { $state.getCurrentPath = () => {
return [ return [
@ -16,8 +17,9 @@ describe('Ticket Component vnTicketDescriptor', () => {
]; ];
}; };
$httpBackend = _$httpBackend_; $httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnTicketDescriptor', {$state}); controller = $componentController('vnTicketDescriptor', {$state});
controller._ticket = {id: 2, invoiceOut: {id: 1}}; controller._ticket = {id: 2, invoiceOut: {id: 1}, client: {id: 101, email: 'client@email'}};
controller.cardReload = ()=> { controller.cardReload = ()=> {
return true; return true;
}; };
@ -81,7 +83,12 @@ describe('Ticket Component vnTicketDescriptor', () => {
describe('showDeliveryNote()', () => { describe('showDeliveryNote()', () => {
it('should open a new window showing a delivery note PDF document', () => { it('should open a new window showing a delivery note PDF document', () => {
let expectedPath = 'report/rpt-delivery-note?ticketFk=2'; const params = {
clientId: controller.ticket.client.id,
ticketId: controller.ticket.id
};
const serializedParams = $httpParamSerializer(params);
let expectedPath = `api/report/delivery-note?${serializedParams}`;
spyOn(window, 'open'); spyOn(window, 'open');
controller.showDeliveryNote(); controller.showDeliveryNote();
@ -89,6 +96,26 @@ describe('Ticket Component vnTicketDescriptor', () => {
}); });
}); });
describe('sendDeliveryNote()', () => {
it('should make a query and call vnApp.showMessage()', () => {
spyOn(controller.vnApp, 'showMessage');
const params = {
recipient: 'client@email',
clientId: controller.ticket.client.id,
ticketId: controller.ticket.id
};
const serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `email/delivery-note?${serializedParams}`).respond();
$httpBackend.expect('GET', `email/delivery-note?${serializedParams}`).respond();
controller.sendDeliveryNote();
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Notification sent!');
});
});
describe('makeInvoice()', () => { describe('makeInvoice()', () => {
it('should make a query and call $state.reload() method if the response is accept', () => { it('should make a query and call $state.reload() method if the response is accept', () => {
spyOn(controller.$state, 'reload'); spyOn(controller.$state, 'reload');

View File

@ -18,7 +18,6 @@ export default class Controller {
this.$.balanceCreateDialog.show(); this.$.balanceCreateDialog.show();
}, name: 'Payment on account...', always: true} }, name: 'Payment on account...', always: true}
]; ];
console.log(this.$stateParams);
} }
setBalanceCreateDialog() { setBalanceCreateDialog() {