Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
graphieros committed Jan 28, 2024
1 parent 41f07f3 commit 0790909
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-data-ui",
"private": false,
"version": "1.9.67",
"version": "1.9.68",
"type": "module",
"description": "A user-empowering data visualization Vue components library",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4246,7 +4246,7 @@ const moodRadarConfig = ref({
</template>
</Box>

<Box @copy="copyConfig(PROD_CONFIG.vue_ui_candlestick)">
<Box open @copy="copyConfig(PROD_CONFIG.vue_ui_candlestick)">
<template #title>
<BaseIcon name="chartCandlestick" />
VueUiCandleStick
Expand Down
2 changes: 1 addition & 1 deletion src/components/vue-ui-candlestick.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const slot = computed(() => {
const extremes = computed(() => {
return {
max: Math.max(...datasetBreakdown.value.map(ds => ds.high)),
min: Math.min(...datasetBreakdown.value.map(ds => ds.low))
min: 0
}
});
Expand Down
53 changes: 53 additions & 0 deletions tests/lib.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
calcPercentageTrend,
calcPolygonPoints,
calcStarPoints,
calculateNiceScale,
checkArray,
checkNaN,
checkObj,
Expand All @@ -23,6 +24,7 @@ import {
makeDonut,
makePath,
matrixTimes,
niceNum,
rotateMatrix,
shiftHue,
sumByAttribute,
Expand Down Expand Up @@ -616,4 +618,55 @@ describe('makePath', () => {
test('creates a closed svg path from an array of plots', () => {
expect(makePath(plots)).toBe('M1,2 2,3 3,4 4,5 5,6 Z')
})
})

describe('calculateNiceScale', () => {
test('returns an object with nice scaling for y axis labels', () => {
expect(calculateNiceScale(0, 118, 10)).toStrictEqual({
max: 120,
min: 0,
tickSize: 20,
ticks: [
0,
20,
40,
60,
80,
100,
120,
],
})

expect(calculateNiceScale(0, 1, 10)).toStrictEqual({
max: 1,
min: 0,
tickSize: 0.1,
ticks: [
0,
0.1,
0.2,
0.30000000000000004,
0.4,
0.5,
0.6,
0.7,
0.7999999999999999,
0.8999999999999999,
0.9999999999999999,
],
})
})
})

describe('niceNum', () => {
test('returns a nice number', () => {
expect(niceNum(1.18, false)).toBe(2)
expect(niceNum(1.18, 1)).toBe(1)
expect(niceNum(11.8, false)).toBe(20)
expect(niceNum(11.8, 1)).toBe(10)
expect(niceNum(118, false)).toBe(200)
expect(niceNum(118, 1)).toBe(100)
expect(niceNum(1118, false)).toBe(2000)
expect(niceNum(1118, 1)).toBe(1000)
})
})

0 comments on commit 0790909

Please sign in to comment.