Merge pull request '3044 - FIX: Load correct tickets on different situations' (#710) from 3044-summary_getTickets into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #710
Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
Joan Sanchez 2021-08-13 06:02:57 +00:00
commit 29ec883390
9 changed files with 2582 additions and 65 deletions

View File

@ -1,8 +1,7 @@
<vn-crud-model
vn-id="ticketsModel"
auto-load="true"
url="Tickets"
link="{clientFk: $ctrl.$params.id}"
link="{clientFk: $ctrl.client.id}"
filter="::$ctrl.ticketFilter"
limit="5"
data="tickets"
@ -297,8 +296,8 @@
<vn-th field="routeFk" expand>Route</vn-th>
<vn-th field="packages" shrink>Packages</vn-th>
<vn-th field="shipped" shrink-date>Date</vn-th>
<vn-th>State</vn-th>
<vn-th shrink>Total</vn-th>
<vn-th field="stateFk">State</vn-th>
<vn-th field="totalWithVat" shrink>Total</vn-th>
<vn-th></vn-th>
</vn-tr>
</vn-thead>

View File

@ -33,10 +33,19 @@ class Controller extends Summary {
};
}
$onChanges() {
if (!this.client)
return;
get client() {
return this._client;
}
set client(value) {
this._client = value;
if (value) {
this.loadData();
this.loadTickets();
}
}
loadData() {
this.$http.get(`Clients/${this.client.id}/summary`).then(res => {
if (res && res.data) {
this.summary = res.data;
@ -49,6 +58,10 @@ class Controller extends Summary {
});
}
loadTickets() {
this.$.$applyAsync(() => this.$.ticketsModel.refresh());
}
get isEmployee() {
return this.aclService.hasAny(['employee']);
}

View File

@ -1,4 +1,5 @@
import './index';
import crudModel from 'core/mocks/crud-model';
describe('Client', () => {
describe('Component vnClientSummary', () => {
@ -13,17 +14,30 @@ describe('Client', () => {
$httpBackend = _$httpBackend_;
const $element = angular.element('<vn-client-summary></vn-client-summary>');
controller = $componentController('vnClientSummary', {$element});
controller.client = {id: 1101};
controller._client = {id: 1101};
controller.$.ticketsModel = crudModel;
}));
describe('$onChanges()', () => {
describe('client() setter', () => {
it('should call to the loadData() and loadTickets() methods', () => {
controller.loadData = jest.fn();
controller.loadTickets = jest.fn();
controller.client = {id: 1102};
expect(controller.loadData).toHaveBeenCalledWith();
expect(controller.loadTickets).toHaveBeenCalledWith();
});
});
describe('loadData()', () => {
it('should perform a GET query and then define the summary property', () => {
let res = {name: 'Superman', classifications: []};
jest.spyOn(controller, 'sumRisk').mockReturnThis();
$httpBackend.expect('GET', `Clients/1101/summary`).respond(200, res);
controller.$onChanges();
controller.loadData();
$httpBackend.flush();
expect(controller.summary).toBeDefined();
@ -31,6 +45,17 @@ describe('Client', () => {
});
});
describe('loadTickets()', () => {
it('should call to the model refresh() method', () => {
jest.spyOn(controller.$.ticketsModel, 'refresh');
controller.loadTickets();
controller.$.$apply();
expect(controller.$.ticketsModel.refresh).toHaveBeenCalledWith();
});
});
describe('sumRisk()', () => {
it('should sum property amount of an array', () => {
controller.summary = {

View File

@ -1,2 +1,3 @@
Buys: Compras
Delete buy(s): Eliminar compra(s)
Delete buy(s): Eliminar compra(s)
Add buy: Añadir compra

View File

@ -1,7 +1,7 @@
<vn-crud-model
vn-id="ticketsModel"
url="InvoiceOuts/{{$ctrl.invoiceOut.id}}/getTickets"
limit="10"
auto-load="true"
data="tickets">
</vn-crud-model>
<vn-card class="summary">

View File

@ -3,22 +3,26 @@ import Summary from 'salix/components/summary';
import './style.scss';
class Controller extends Summary {
set invoiceOut(value) {
this._invoiceOut = value;
if (value && value.id) {
this.getSummary();
this.$.ticketsModel.url = `InvoiceOuts/${this.invoiceOut.id}/getTickets`;
}
}
get invoiceOut() {
return this._invoiceOut;
}
getSummary() {
return this.$http.get(`InvoiceOuts/${this.invoiceOut.id}/summary`)
set invoiceOut(value) {
this._invoiceOut = value;
if (value && value.id) {
this.loadData();
this.loadTickets();
}
}
loadData() {
this.$http.get(`InvoiceOuts/${this.invoiceOut.id}/summary`)
.then(res => this.summary = res.data);
}
loadTickets() {
this.$.$applyAsync(() => this.$.ticketsModel.refresh());
}
}
ngModule.vnComponent('vnInvoiceOutSummary', {

View File

@ -18,10 +18,10 @@ describe('InvoiceOut', () => {
controller.$.ticketsModel = crudModel;
}));
describe('getSummary()', () => {
describe('loadData()', () => {
it('should perform a query to set summary', () => {
$httpBackend.expect('GET', `InvoiceOuts/1/summary`).respond(200, 'the data you are looking for');
controller.getSummary();
controller.loadData();
$httpBackend.flush();
expect(controller.summary).toEqual('the data you are looking for');

View File

@ -42,7 +42,7 @@
<vn-th field="provinceFk" class="expendable">Province</vn-th>
<vn-th field="stateFk">State</vn-th>
<vn-th field="zoneFk">Zone</vn-th>
<vn-th shrink>Total</vn-th>
<vn-th field="totalWithVat" shrink>Total</vn-th>
<vn-th></vn-th>
</vn-tr>
</vn-thead>

2555
package-lock.json generated

File diff suppressed because it is too large Load Diff