From 9ff9f63dd2485bfeb2712b8da7be31bb679e73c3 Mon Sep 17 00:00:00 2001 From: Brandon Farmer Date: Thu, 12 Apr 2018 13:29:27 -0700 Subject: [PATCH] Ensure that values are displayed on gauges --- ui/src/shared/components/GaugeChart.tsx | 2 +- ui/src/shared/parsing/lastValues.ts | 4 ++- ui/test/shared/components/GaugeChart.test.tsx | 26 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ui/src/shared/components/GaugeChart.tsx b/ui/src/shared/components/GaugeChart.tsx index b4e5e77000..dc563fa7c5 100644 --- a/ui/src/shared/components/GaugeChart.tsx +++ b/ui/src/shared/components/GaugeChart.tsx @@ -101,7 +101,7 @@ class GaugeChart extends PureComponent { const {lastValues} = getLastValues(data) const precision = 100.0 - return Math.round(_.get(lastValues, 1, 0) * precision) / precision + return Math.round(_.get(lastValues, 0, 0) * precision) / precision } } diff --git a/ui/src/shared/parsing/lastValues.ts b/ui/src/shared/parsing/lastValues.ts index 1184c0a45a..e6227e012f 100644 --- a/ui/src/shared/parsing/lastValues.ts +++ b/ui/src/shared/parsing/lastValues.ts @@ -9,7 +9,7 @@ type SeriesValue = number | string interface Series { name: string - values: SeriesValue[] | null + values: SeriesValue[][] | null columns: string[] | null } @@ -38,6 +38,8 @@ export default function( ['', ''] ).slice(1) + console.dir(values) + const lastValues = values[values.length - 1].slice(1) // remove time with slice 1 return {lastValues, series} diff --git a/ui/test/shared/components/GaugeChart.test.tsx b/ui/test/shared/components/GaugeChart.test.tsx index b05f997f5e..3a35e568df 100644 --- a/ui/test/shared/components/GaugeChart.test.tsx +++ b/ui/test/shared/components/GaugeChart.test.tsx @@ -3,6 +3,23 @@ import React from 'react' import Gauge from 'src/shared/components/Gauge' import GaugeChart from 'src/shared/components/GaugeChart' +const data = [ + { + response: { + results: [ + { + series: [ + { + values: [[1, 2]], + columns: ['time', 'value'], + }, + ], + }, + ], + }, + }, +] + const defaultProps = { data: [], isFetchingInitially: false, @@ -30,5 +47,14 @@ describe('GaugeChart', () => { expect(wrapper.find(Gauge).props().gaugePosition).toBe(0) }) }) + + describe('when data has a value', () => { + it('renders the correct number', () => { + const wrapper = setup({data}) + + expect(wrapper.find(Gauge).exists()).toBe(true) + expect(wrapper.find(Gauge).props().gaugePosition).toBe(2) + }) + }) }) })