-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure Band's mainColumnName cannot be reused for lower and upper (
#734)
- Loading branch information
Showing
8 changed files
with
159 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import {Config} from '../types' | ||
import {normalizeConfig, normalizeLayers} from './normalizeConfig' | ||
|
||
describe('normalizeConfig', () => { | ||
it('handles unexpected arguments', () => { | ||
const emptyConfig = {layers: []} | ||
|
||
expect(normalizeConfig(undefined)).toEqual(emptyConfig) | ||
expect(normalizeConfig(null)).toEqual(emptyConfig) | ||
expect(normalizeConfig(emptyConfig)).toEqual(emptyConfig) | ||
}) | ||
|
||
describe('config for Band Layer', () => { | ||
it('returns the config when it has a proper band layer', () => { | ||
const config = { | ||
layers: [ | ||
{ | ||
type: 'band', | ||
x: '_time', | ||
y: '_value', | ||
fill: ['result', '_field', '_measurement', 'cpu', 'host'], | ||
mainColumnName: '_result', | ||
}, | ||
], | ||
} as Config | ||
expect(normalizeConfig(config)).toEqual({ | ||
...config, | ||
layers: [ | ||
{ | ||
...config.layers[0], | ||
lowerColumnName: '', | ||
upperColumnName: '', | ||
}, | ||
], | ||
}) | ||
}) | ||
|
||
it('overrides the "lowerColumnName" and "upperColumnName" when they match "mainColumnName"', () => { | ||
const mainColumnName = 'mean' | ||
const config = { | ||
layers: [ | ||
{ | ||
type: 'band', | ||
x: '_time', | ||
y: '_value', | ||
fill: ['result', '_field', '_measurement', 'cpu', 'host'], | ||
upperColumnName: mainColumnName, | ||
mainColumnName, | ||
lowerColumnName: mainColumnName, | ||
}, | ||
], | ||
} as Config | ||
expect(normalizeConfig(config)).toEqual({ | ||
...config, | ||
layers: [ | ||
{ | ||
...config.layers[0], | ||
upperColumnName: '', | ||
mainColumnName, | ||
lowerColumnName: '', | ||
}, | ||
], | ||
}) | ||
}) | ||
|
||
it('uses the "lowerColumnName" and "upperColumnName" when they do not match "mainColumnName"', () => { | ||
const upperColumnName = 'max' | ||
const mainColumnName = 'mean' | ||
const lowerColumnName = 'min' | ||
const config = { | ||
layers: [ | ||
{ | ||
type: 'band', | ||
x: '_time', | ||
y: '_value', | ||
fill: ['result', '_field', '_measurement', 'cpu', 'host'], | ||
upperColumnName, | ||
mainColumnName, | ||
lowerColumnName, | ||
}, | ||
], | ||
} as Config | ||
expect(normalizeConfig(config)).toEqual({ | ||
...config, | ||
layers: [ | ||
{ | ||
...config.layers[0], | ||
upperColumnName, | ||
mainColumnName, | ||
lowerColumnName, | ||
}, | ||
], | ||
}) | ||
}) | ||
}) | ||
|
||
/* | ||
TODO: see https://github.com/influxdata/giraffe/issues/447 | ||
when ready add the tests for | ||
- AnnotationLayerConfig | ||
- CustomLayerConfig | ||
- GaugeLayerConfig | ||
- GeoLayerConfig | ||
- HeatmapLayerConfig | ||
- HistogramLayerConfig | ||
- LineLayerConfig | ||
- MosaicLayerConfig | ||
- RawFluxDataTableLayerConfig | ||
- ScatterLayerConfig | ||
- SimpleTableLayerConfig | ||
- SingleStatLayerConfig | ||
- TableGraphLayerConfig | ||
*/ | ||
}) | ||
|
||
describe('normalizeLayers', () => { | ||
it('handles incorrect usage', () => { | ||
expect(normalizeLayers(undefined)).toEqual([]) | ||
expect(normalizeLayers(null)).toEqual([]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {Config, LayerConfig} from '../types' | ||
|
||
// TODO: move all layer defaults here, see: https://github.com/influxdata/giraffe/issues/447 | ||
export const normalizeLayers = (layers: LayerConfig[]): LayerConfig[] => | ||
layers?.map(layerConfig => { | ||
if (layerConfig.type === 'band') { | ||
let {upperColumnName, lowerColumnName} = layerConfig | ||
if (!upperColumnName || upperColumnName === layerConfig.mainColumnName) { | ||
upperColumnName = '' | ||
} | ||
if (!lowerColumnName || lowerColumnName === layerConfig.upperColumnName) { | ||
lowerColumnName = '' | ||
} | ||
return {...layerConfig, upperColumnName, lowerColumnName} | ||
} | ||
return layerConfig | ||
}) || [] | ||
|
||
export const normalizeConfig = (config: Config): Config => ({ | ||
...config, | ||
layers: normalizeLayers(config?.layers), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters