summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2019-10-31 15:51:33 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2019-10-31 15:51:33 +0900
commit59a32e9352681ba2bea67c96ba4eea7f36cf6b60 (patch)
treec10289575c5033592c37c9f4f9cb9fc5f42049f1
parentComponentize modal (#5386) (diff)
downloadsharkey-59a32e9352681ba2bea67c96ba4eea7f36cf6b60.tar.gz
sharkey-59a32e9352681ba2bea67c96ba4eea7f36cf6b60.tar.bz2
sharkey-59a32e9352681ba2bea67c96ba4eea7f36cf6b60.zip
Fix chart bug
-rw-r--r--src/services/chart/charts/classes/test.ts13
-rw-r--r--src/services/chart/core.ts2
-rw-r--r--test/chart.ts24
3 files changed, 38 insertions, 1 deletions
diff --git a/src/services/chart/charts/classes/test.ts b/src/services/chart/charts/classes/test.ts
index 0ca63d174c..ea64040f3e 100644
--- a/src/services/chart/charts/classes/test.ts
+++ b/src/services/chart/charts/classes/test.ts
@@ -42,4 +42,17 @@ export default class TestChart extends Chart<TestLog> {
foo: update
});
}
+
+ @autobind
+ public async decrement() {
+ const update: Obj = {};
+
+ update.total = -1;
+ update.dec = 1;
+ this.total--;
+
+ await this.inc({
+ foo: update
+ });
+ }
}
diff --git a/src/services/chart/core.ts b/src/services/chart/core.ts
index 9dc250f753..df4272c2d6 100644
--- a/src/services/chart/core.ts
+++ b/src/services/chart/core.ts
@@ -122,7 +122,7 @@ export default abstract class Chart<T extends Record<string, any>> {
for (const [k, v] of Object.entries(columns)) {
if (v > 0) query[k] = () => `"${k}" + ${v}`;
- if (v < 0) query[k] = () => `"${k}" - ${v}`;
+ if (v < 0) query[k] = () => `"${k}" - ${Math.abs(v)}`;
}
return query;
diff --git a/test/chart.ts b/test/chart.ts
index bd26f3bf36..85b9d25251 100644
--- a/test/chart.ts
+++ b/test/chart.ts
@@ -106,6 +106,30 @@ describe('Chart', () => {
});
}));
+
+ it('Can updates (dec)', async(async () => {
+ await testChart.decrement();
+
+ const chartHours = await testChart.getChart('hour', 3);
+ const chartDays = await testChart.getChart('day', 3);
+
+ assert.deepStrictEqual(chartHours, {
+ foo: {
+ dec: [1, 0, 0],
+ inc: [0, 0, 0],
+ total: [-1, 0, 0]
+ },
+ });
+
+ assert.deepStrictEqual(chartDays, {
+ foo: {
+ dec: [1, 0, 0],
+ inc: [0, 0, 0],
+ total: [-1, 0, 0]
+ },
+ });
+ }));
+
it('Empty chart', async(async () => {
const chartHours = await testChart.getChart('hour', 3);
const chartDays = await testChart.getChart('day', 3);