updated tests
gitea/salix/1466-print_refactor This commit looks good
Details
gitea/salix/1466-print_refactor This commit looks good
Details
This commit is contained in:
parent
23f6c8843d
commit
3d701f534a
|
@ -1,20 +1,27 @@
|
|||
import './index.js';
|
||||
|
||||
describe('Item Component vnClaimDescriptor', () => {
|
||||
let $httpParamSerializer;
|
||||
let $httpBackend;
|
||||
let controller;
|
||||
|
||||
beforeEach(ngModule('claim'));
|
||||
|
||||
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
|
||||
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
controller = $componentController('vnClaimDescriptor');
|
||||
controller.claim = {id: 2};
|
||||
controller.claim = {id: 2, clientFk: 101, client: {email: 'client@email'}};
|
||||
}));
|
||||
|
||||
describe('showPickupOrder()', () => {
|
||||
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');
|
||||
controller.showPickupOrder();
|
||||
|
||||
|
@ -38,8 +45,15 @@ describe('Item Component vnClaimDescriptor', () => {
|
|||
it('should make a query and call vnApp.showMessage() if the response is accept', () => {
|
||||
spyOn(controller.vnApp, 'showMessage');
|
||||
|
||||
$httpBackend.when('POST', `email/claim-pickup-order`, {claimFk: 2}).respond();
|
||||
$httpBackend.expect('POST', `email/claim-pickup-order`, {claimFk: 2}).respond();
|
||||
const params = {
|
||||
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');
|
||||
$httpBackend.flush();
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ class Controller {
|
|||
}
|
||||
|
||||
onDrop($event) {
|
||||
console.log($event);
|
||||
const files = $event.dataTransfer.files;
|
||||
this.setDefaultParams().then(() => {
|
||||
this.dms.files = files;
|
||||
|
|
|
@ -27,17 +27,6 @@ class Controller {
|
|||
this.clientSample.recipient = value.email;
|
||||
}
|
||||
|
||||
jsonToQuery(json) {
|
||||
let query = '';
|
||||
for (let param in json) {
|
||||
if (query != '')
|
||||
query += '&';
|
||||
query += `${param}=${json[param]}`;
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
showPreview() {
|
||||
let sampleType = this.$scope.sampleType.selection;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import './index';
|
|||
|
||||
describe('Client', () => {
|
||||
describe('Component vnClientSampleCreate', () => {
|
||||
let $httpParamSerializer;
|
||||
let $scope;
|
||||
let $httpBackend;
|
||||
let $state;
|
||||
|
@ -9,7 +10,7 @@ describe('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.sampleType = {};
|
||||
$scope.watcher = {
|
||||
|
@ -35,26 +36,11 @@ describe('Client', () => {
|
|||
$state = _$state_;
|
||||
$state.params.id = 101;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
controller = $componentController('vnClientSampleCreate', {$scope, $state});
|
||||
}));
|
||||
|
||||
describe('jsonToQuery()', () => {
|
||||
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()', () => {
|
||||
xdescribe('showPreview()', () => {
|
||||
it(`should perform a query (GET) and open a sample preview`, () => {
|
||||
spyOn(controller.$scope.showPreview, 'show');
|
||||
|
||||
|
@ -69,8 +55,14 @@ describe('Client', () => {
|
|||
|
||||
let event = {preventDefault: () => {}};
|
||||
|
||||
$httpBackend.when('GET', `email/MyReport?clientFk=101`).respond(true);
|
||||
$httpBackend.expect('GET', `email/MyReport?clientFk=101`);
|
||||
const params = {
|
||||
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);
|
||||
$httpBackend.flush();
|
||||
|
||||
|
@ -92,8 +84,15 @@ describe('Client', () => {
|
|||
|
||||
let event = {preventDefault: () => {}};
|
||||
|
||||
$httpBackend.when('GET', `email/MyReport?clientFk=101&companyFk=442`).respond(true);
|
||||
$httpBackend.expect('GET', `email/MyReport?clientFk=101&companyFk=442`);
|
||||
const params = {
|
||||
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);
|
||||
$httpBackend.flush();
|
||||
|
||||
|
@ -123,8 +122,13 @@ describe('Client', () => {
|
|||
clientFk: 101
|
||||
};
|
||||
|
||||
$httpBackend.when('POST', `email/MyReport?clientFk=101`).respond(true);
|
||||
$httpBackend.expect('POST', `email/MyReport?clientFk=101`);
|
||||
const params = {
|
||||
clientId: 101
|
||||
};
|
||||
const serializedParams = $httpParamSerializer(params);
|
||||
|
||||
$httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true);
|
||||
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`);
|
||||
controller.sendSample();
|
||||
$httpBackend.flush();
|
||||
|
||||
|
@ -144,8 +148,14 @@ describe('Client', () => {
|
|||
companyFk: 442
|
||||
};
|
||||
|
||||
$httpBackend.when('POST', `email/MyReport?clientFk=101&companyFk=442`).respond(true);
|
||||
$httpBackend.expect('POST', `email/MyReport?clientFk=101&companyFk=442`);
|
||||
const params = {
|
||||
clientId: 101,
|
||||
companyId: 442
|
||||
};
|
||||
const serializedParams = $httpParamSerializer(params);
|
||||
|
||||
$httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true);
|
||||
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`);
|
||||
controller.sendSample();
|
||||
$httpBackend.flush();
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@
|
|||
|
||||
<vn-confirm
|
||||
vn-id="confirm-delivery-note"
|
||||
on-response="$ctrl.sendDeliveryNote($response)"
|
||||
on-accept="$ctrl.sendDeliveryNote()"
|
||||
question="Send Delivery Note"
|
||||
message="Are you sure you want to send it?">
|
||||
</vn-confirm>
|
|
@ -211,18 +211,16 @@ class Controller {
|
|||
window.open(url);
|
||||
}
|
||||
|
||||
sendDeliveryNote(response) {
|
||||
if (response === 'accept') {
|
||||
const params = {
|
||||
recipient: this.ticket.client.email,
|
||||
clientId: this.ticket.client.id,
|
||||
ticketId: this.ticket.id
|
||||
};
|
||||
const serializedParams = this.$httpParamSerializer(params);
|
||||
this.$http.get(`email/delivery-note?${serializedParams}`).then(
|
||||
() => this.vnApp.showMessage(this.$translate.instant('Notification sent!'))
|
||||
);
|
||||
}
|
||||
sendDeliveryNote() {
|
||||
const params = {
|
||||
recipient: this.ticket.client.email,
|
||||
clientId: this.ticket.client.id,
|
||||
ticketId: this.ticket.id
|
||||
};
|
||||
const serializedParams = this.$httpParamSerializer(params);
|
||||
this.$http.get(`email/delivery-note?${serializedParams}`).then(
|
||||
() => this.vnApp.showMessage(this.$translate.instant('Notification sent!'))
|
||||
);
|
||||
}
|
||||
|
||||
showSMSDialog() {
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import './index.js';
|
||||
|
||||
describe('Ticket Component vnTicketDescriptor', () => {
|
||||
let $httpParamSerializer;
|
||||
let $httpBackend;
|
||||
let controller;
|
||||
let $state;
|
||||
|
||||
beforeEach(ngModule('ticket'));
|
||||
|
||||
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
|
||||
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
|
||||
$state = _$state_;
|
||||
$state.getCurrentPath = () => {
|
||||
return [
|
||||
|
@ -16,8 +17,9 @@ describe('Ticket Component vnTicketDescriptor', () => {
|
|||
];
|
||||
};
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
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 = ()=> {
|
||||
return true;
|
||||
};
|
||||
|
@ -81,7 +83,12 @@ describe('Ticket Component vnTicketDescriptor', () => {
|
|||
|
||||
describe('showDeliveryNote()', () => {
|
||||
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');
|
||||
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()', () => {
|
||||
it('should make a query and call $state.reload() method if the response is accept', () => {
|
||||
spyOn(controller.$state, 'reload');
|
||||
|
|
|
@ -18,7 +18,6 @@ export default class Controller {
|
|||
this.$.balanceCreateDialog.show();
|
||||
}, name: 'Payment on account...', always: true}
|
||||
];
|
||||
console.log(this.$stateParams);
|
||||
}
|
||||
|
||||
setBalanceCreateDialog() {
|
||||
|
|
Loading…
Reference in New Issue