test(client_defaulter): getBalanceDueTotal tested
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-06-13 07:44:21 +02:00
parent 15f8a261d2
commit 5e586bf1d0
4 changed files with 27 additions and 14 deletions

View File

@ -15,10 +15,7 @@ export default function currency($translate) {
maximumFractionDigits: fractionSize
};
let lang = $translate.use();
if (lang == 'es')
lang = 'de';
const lang = $translate.use() == 'es' ? 'de' : $translate.use();
if (typeof input == 'number') {
return new Intl.NumberFormat(lang, options)
.format(input);

View File

@ -27,7 +27,7 @@
<h6 translate>Total</h6>
<vn-label-value
label="Balance due"
value="{{::$ctrl.balanceDueTotal | currency: 'EUR': 2}}">
value="{{$ctrl.balanceDueTotal | currency: 'EUR': 2}}">
</vn-label-value>
</div>
</div>

View File

@ -54,15 +54,7 @@ export default class Controller extends Section {
]
};
this.$http.get('Defaulters/filter')
.then(res => {
if (!res.data) return 0;
this.balanceDueTotal = res.data.reduce(
(accumulator, currentValue) => {
return accumulator + (currentValue['amount'] || 0);
}, 0);
});
this.getBalanceDueTotal();
}
get checked() {
@ -76,6 +68,18 @@ export default class Controller extends Section {
return checkedLines;
}
getBalanceDueTotal() {
this.$http.get('Defaulters/filter')
.then(res => {
if (!res.data) return 0;
this.balanceDueTotal = res.data.reduce(
(accumulator, currentValue) => {
return accumulator + (currentValue['amount'] || 0);
}, 0);
});
}
chipColor(date) {
const day = 24 * 60 * 60 * 1000;
const today = new Date();

View File

@ -105,5 +105,17 @@ describe('client defaulter', () => {
expect(expr).toEqual({'d.clientFk': '5'});
});
});
describe('getBalanceDueTotal()', () => {
it('should return balance due total', () => {
const defaulters = controller.$.model.data;
$httpBackend.when('GET', `Defaulters/filter`).respond(defaulters);
controller.getBalanceDueTotal();
$httpBackend.flush();
expect(controller.balanceDueTotal).toEqual(875);
});
});
});
});