feat(invoiceOut): separate index.js and jest test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
a52c06057f
commit
f34130cbd7
|
@ -3,8 +3,10 @@ import Section from 'salix/components/section';
|
|||
import './style.scss';
|
||||
|
||||
class Controller extends Section {
|
||||
constructor($element, $) {
|
||||
constructor($element, $, vnReport, vnEmail) {
|
||||
super($element, $);
|
||||
this.vnReport = vnReport;
|
||||
this.vnEmail = vnEmail;
|
||||
}
|
||||
|
||||
get invoiceOut() {
|
||||
|
@ -13,6 +15,8 @@ class Controller extends Section {
|
|||
|
||||
set invoiceOut(value) {
|
||||
this._invoiceOut = value;
|
||||
if (value)
|
||||
this.id = value.id;
|
||||
}
|
||||
|
||||
loadData() {
|
||||
|
@ -31,8 +35,8 @@ class Controller extends Section {
|
|||
}
|
||||
]
|
||||
};
|
||||
return this.getData(`InvoiceOuts/${this.invoiceOut.id}`, {filter})
|
||||
.then(res => this.invoice = res.data);
|
||||
return this.$http.get(`InvoiceOuts/${this.invoiceOut.id}`, {filter})
|
||||
.then(res => this.invoiceOut = res.data);
|
||||
}
|
||||
reload() {
|
||||
return this.loadData().then(() => {
|
||||
|
@ -48,8 +52,8 @@ class Controller extends Section {
|
|||
deleteInvoiceOut() {
|
||||
return this.$http.post(`InvoiceOuts/${this.invoiceOut.id}/delete`)
|
||||
.then(() => this.$state.go('invoiceOut.index'))
|
||||
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted')))
|
||||
.then(() => this.close());
|
||||
.then(() => this.$state.reload())
|
||||
.then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted')));
|
||||
}
|
||||
|
||||
bookInvoiceOut() {
|
||||
|
@ -59,8 +63,7 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
createPdfInvoice() {
|
||||
const invoiceId = this.invoiceOut.id;
|
||||
return this.$http.post(`InvoiceOuts/${invoiceId}/createPdf`)
|
||||
return this.$http.post(`InvoiceOuts/${this.id}/createPdf`)
|
||||
.then(() => this.reload())
|
||||
.then(() => {
|
||||
const snackbarMessage = this.$t(
|
||||
|
@ -72,7 +75,7 @@ class Controller extends Section {
|
|||
showCsvInvoice() {
|
||||
this.vnReport.showCsv('invoice', {
|
||||
recipientId: this.invoiceOut.client.id,
|
||||
invoiceId: this.id,
|
||||
invoiceId: this.id
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -95,17 +98,18 @@ class Controller extends Section {
|
|||
showExportationLetter() {
|
||||
this.vnReport.show('exportation', {
|
||||
recipientId: this.invoiceOut.client.id,
|
||||
invoiceId: this.id,
|
||||
invoiceId: this.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope'];
|
||||
Controller.$inject = ['$element', '$scope', 'vnReport', 'vnEmail'];
|
||||
|
||||
ngModule.vnComponent('vnInvoiceOutDescriptorMenu', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
invoiceOut: '<',
|
||||
parentReload: '&'
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import './index';
|
||||
|
||||
describe('vnInvoiceOutDescriptor', () => {
|
||||
describe('vnInvoiceOutDescriptorMenu', () => {
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $httpParamSerializer;
|
||||
|
@ -14,22 +14,9 @@ describe('vnInvoiceOutDescriptor', () => {
|
|||
beforeEach(inject(($componentController, _$httpParamSerializer_, _$httpBackend_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
controller = $componentController('vnInvoiceOutDescriptor', {$element: null});
|
||||
controller = $componentController('vnInvoiceOutDescriptorMenu', {$element: null});
|
||||
}));
|
||||
|
||||
describe('loadData()', () => {
|
||||
it(`should perform a get query to store the invoice in data into the controller`, () => {
|
||||
const id = 1;
|
||||
const response = {id: 1};
|
||||
|
||||
$httpBackend.expectGET(`InvoiceOuts/${id}`).respond(response);
|
||||
controller.id = id;
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.invoiceOut).toEqual(response);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createPdfInvoice()', () => {
|
||||
it('should make a query to the createPdf() endpoint and show a success snackbar', () => {
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<slot-dot-menu>
|
||||
<vn-invoice-out-descriptor-menu
|
||||
invoice-out="$ctrl.invoiceOut"
|
||||
parent-reload="$ctrl.cardReload()"
|
||||
parent-reload="$ctrl.reload()"
|
||||
/>
|
||||
</slot-dot-menu>
|
||||
<slot-body>
|
||||
|
|
|
@ -3,17 +3,11 @@ import './index';
|
|||
describe('vnInvoiceOutDescriptor', () => {
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $httpParamSerializer;
|
||||
const invoiceOut = {
|
||||
id: 1,
|
||||
client: {id: 1101}
|
||||
};
|
||||
|
||||
beforeEach(ngModule('invoiceOut'));
|
||||
|
||||
beforeEach(inject(($componentController, _$httpParamSerializer_, _$httpBackend_) => {
|
||||
beforeEach(inject(($componentController, _$httpBackend_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpParamSerializer = _$httpParamSerializer_;
|
||||
controller = $componentController('vnInvoiceOutDescriptor', {$element: null});
|
||||
}));
|
||||
|
||||
|
@ -29,81 +23,4 @@ describe('vnInvoiceOutDescriptor', () => {
|
|||
expect(controller.invoiceOut).toEqual(response);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createPdfInvoice()', () => {
|
||||
it('should make a query to the createPdf() endpoint and show a success snackbar', () => {
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
|
||||
controller.invoiceOut = invoiceOut;
|
||||
|
||||
$httpBackend.whenGET(`InvoiceOuts/${invoiceOut.id}`).respond();
|
||||
$httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.id}/createPdf`).respond();
|
||||
controller.createPdfInvoice();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('showCsvInvoice()', () => {
|
||||
it('should make a query to the csv invoice download endpoint and show a message snackbar', () => {
|
||||
jest.spyOn(window, 'open').mockReturnThis();
|
||||
|
||||
controller.invoiceOut = invoiceOut;
|
||||
|
||||
const expectedParams = {
|
||||
invoiceId: invoiceOut.id,
|
||||
recipientId: invoiceOut.client.id
|
||||
};
|
||||
const serializedParams = $httpParamSerializer(expectedParams);
|
||||
const expectedPath = `api/csv/invoice/download?${serializedParams}`;
|
||||
controller.showCsvInvoice();
|
||||
|
||||
expect(window.open).toHaveBeenCalledWith(expectedPath);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sendPdfInvoice()', () => {
|
||||
it('should make a query to the email invoice endpoint and show a message snackbar', () => {
|
||||
jest.spyOn(controller.vnApp, 'showMessage');
|
||||
|
||||
controller.invoiceOut = invoiceOut;
|
||||
|
||||
const $data = {email: 'brucebanner@gothamcity.com'};
|
||||
const expectedParams = {
|
||||
invoiceId: invoiceOut.id,
|
||||
recipient: $data.email,
|
||||
recipientId: invoiceOut.client.id
|
||||
};
|
||||
const serializedParams = $httpParamSerializer(expectedParams);
|
||||
|
||||
$httpBackend.expectGET(`email/invoice?${serializedParams}`).respond();
|
||||
controller.sendPdfInvoice($data);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showMessage).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('sendCsvInvoice()', () => {
|
||||
it('should make a query to the csv invoice send endpoint and show a message snackbar', () => {
|
||||
jest.spyOn(controller.vnApp, 'showMessage');
|
||||
|
||||
controller.invoiceOut = invoiceOut;
|
||||
|
||||
const $data = {email: 'brucebanner@gothamcity.com'};
|
||||
const expectedParams = {
|
||||
invoiceId: invoiceOut.id,
|
||||
recipient: $data.email,
|
||||
recipientId: invoiceOut.client.id
|
||||
};
|
||||
const serializedParams = $httpParamSerializer(expectedParams);
|
||||
|
||||
$httpBackend.expectGET(`csv/invoice/send?${serializedParams}`).respond();
|
||||
controller.sendCsvInvoice($data);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showMessage).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue