feat(claim_summary): parentReload(), and test

This commit is contained in:
Alex Moreno 2022-02-28 12:40:44 +01:00
parent 5434dd3baf
commit 60e908d82a
10 changed files with 61 additions and 36 deletions

View File

@ -97,12 +97,11 @@ module.exports = Self => {
{'cl.socialName': {like: `%${value}%`}}
]
};
case 'workerFk':
return {['cl.workerFk']: value};
case 'id':
case 'claimStateFk':
case 'priority':
return {[`cl.${param}`]: value};
case 'salesPersonFk':
case 'attenderFk':
return {'cl.workerFk': value};
case 'created':

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethod('getSummary', {
Self.remoteMethodCtx('getSummary', {
description: 'Return the claim summary',
accessType: 'READ',
accepts: [{
@ -19,7 +19,7 @@ module.exports = Self => {
}
});
Self.getSummary = async(id, options) => {
Self.getSummary = async(ctx, id, options) => {
const myOptions = {};
if (typeof options == 'object')
@ -135,6 +135,7 @@ module.exports = Self => {
const res = await Promise.all(promises);
summary.isEditable = await Self.isEditable(ctx, id, myOptions);
[summary.claim] = res[0];
summary.salesClaimed = res[1];
summary.developments = res[2];

View File

@ -25,7 +25,7 @@ describe('claim filter()', () => {
try {
const options = {transaction: tx};
const result = await app.models.Claim.filter({args: {filter: {}, search: 'Tony Stark'}}, null, options);
const result = await app.models.Claim.filter({args: {filter: {}, search: 'Iron man'}}, null, options);
expect(result.length).toEqual(1);
expect(result[0].id).toEqual(4);

View File

@ -3,17 +3,24 @@ const app = require('vn-loopback/server/server');
describe('claim getSummary()', () => {
it('should return summary with claim, salesClaimed, developments and actions defined ', async() => {
const tx = await app.models.Claim.beginTransaction({});
const ctx = {
req: {
accessToken: {
userId: 9
}
}
};
try {
const options = {transaction: tx};
const result = await app.models.Claim.getSummary(1, options);
const result = await app.models.Claim.getSummary(ctx, 1, options);
const keys = Object.keys(result);
expect(keys).toContain('claim');
expect(keys).toContain('salesClaimed');
expect(keys).toContain('developments');
expect(keys).toContain('actions');
expect(keys).toContain('isEditable');
await tx.rollback();
} catch (e) {

View File

@ -19,7 +19,7 @@
<th field="created" center shrink-date>
<span translate>Created</span>
</th>
<th field="workerFk">
<th field="salesPersonFk">
<span translate>Worker</span>
</th>
<th field="claimStateFk">

View File

@ -49,10 +49,10 @@ class Controller extends Section {
case 'clientFk':
return {['cl.socialName']: value};
case 'id':
case 'workerFk':
case 'claimStateFk':
case 'priority':
return {[`cl.${param}`]: value};
case 'salesPersonFk':
case 'attenderFk':
return {'cl.workerFk': value};
case 'created':
@ -79,6 +79,10 @@ class Controller extends Section {
this.claimSelected = claim;
this.$.summary.show();
}
reload() {
this.$.model.refresh();
}
}
ngModule.vnComponent('vnClaimIndex', {

View File

@ -1,9 +1,13 @@
import ngModule from '../module';
import ModuleMain from 'salix/components/module-main';
export default class Claim extends ModuleMain {}
export default class Claims extends ModuleMain {
constructor($element, $) {
super($element, $);
}
}
ngModule.vnComponent('vnClaim', {
controller: Claim,
controller: Claims,
template: require('./index.html')
});

View File

@ -13,7 +13,7 @@
</a>
<span>{{::$ctrl.summary.claim.id}} - {{::$ctrl.summary.claim.client.name}}</span>
<vn-button-menu
disabled="!$ctrl.isEditable"
disabled="!$ctrl.summary.isEditable"
class="message"
label="Change state"
value-field="id"

View File

@ -10,21 +10,27 @@ class Controller extends Summary {
$onChanges() {
if (this.claim && this.claim.id)
this.getSummary();
this.loadData();
}
loadData() {
this.getSummary();
return this.$http.get(`Claims/${this.claim.id}/getSummary`).then(res => {
if (res && res.data)
this.summary = res.data;
});
}
reload() {
if (this.card) {
console.log('CARD');
this.card.reload();
}
if (this.parentReload)
this.parentReload();
this.loadData()
.then(() => {
if (this.card)
this.card.reload();
// Refresh index model
if (this.parentReload)
this.parentReload();
});
}
get isSalesPerson() {
return this.aclService.hasAny(['salesPerson']);
}
@ -54,15 +60,6 @@ class Controller extends Summary {
this.$.model.refresh();
}
getSummary() {
this.$http.get(`Claims/${this.claim.id}/getSummary`).then(response => {
this.summary = response.data;
});
this.$http.get(`Claims/${this.claim.id}/isEditable`).then(response => {
this.isEditable = response.data;
});
}
getImagePath(dmsId) {
return this.vnFile.getPath(`/api/dms/${dmsId}/downloadFile`);
}

View File

@ -18,24 +18,37 @@ describe('Claim', () => {
controller.$.model = crudModel;
}));
describe('getSummary()', () => {
describe('loadData()', () => {
it('should perform a query to set summary', () => {
$httpBackend.expect('GET', `Claims/1/getSummary`).respond(200, 24);
controller.getSummary();
$httpBackend.expect('GET', `Claims/1/isEditable`).respond(200, true);
$httpBackend.when('GET', `Claims/1/getSummary`).respond(200, 24);
controller.loadData();
$httpBackend.flush();
expect(controller.summary).toEqual(24);
});
});
describe('changeState()', () => {
it('should make an HTTP post query, then call the showSuccess(), reload() and resetChanges() methods', () => {
jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis();
const expectedParams = {id: 1, claimStateFk: 1};
$httpBackend.when('GET', `Claims/1/getSummary`).respond(200, 24);
$httpBackend.expect('PATCH', `Claims/updateClaim/1`, expectedParams).respond(200);
controller.changeState(1);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
describe('$onChanges()', () => {
it('should call getSummary when item.id is defined', () => {
jest.spyOn(controller, 'getSummary');
it('should call loadData when item.id is defined', () => {
jest.spyOn(controller, 'loadData');
controller.$onChanges();
expect(controller.getSummary).toHaveBeenCalledWith();
expect(controller.loadData).toHaveBeenCalledWith();
});
});
});