From 6aa3aa898531bfc7eda81484b791e531d7c66a9c Mon Sep 17 00:00:00 2001 From: Uladzislau Lasitsa Date: Fri, 21 Jan 2022 13:17:29 +0300 Subject: [PATCH] Fix tests --- .../charts/public/services/palettes/helpers.ts | 11 +++++------ .../coloring/palette_configuration.test.tsx | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/plugins/charts/public/services/palettes/helpers.ts b/src/plugins/charts/public/services/palettes/helpers.ts index 15635e75c5750..e8553d6f52069 100644 --- a/src/plugins/charts/public/services/palettes/helpers.ts +++ b/src/plugins/charts/public/services/palettes/helpers.ts @@ -22,7 +22,7 @@ function findColorSegment( // what about values in range const index = colors.findIndex((c, i) => comparison(value, rangeMin + (1 + i) * step) <= 0); return ( - colors[index] || + colors[index] ?? (value > rangeMin + colors.length * step ? colors[colors.length - 1] : colors[0]) ); } @@ -34,14 +34,13 @@ function findColorsByStops( stops: number[] ) { const index = stops.findIndex((s) => comparison(value, s) < 0); - return colors[index] || value > stops[stops.length - 1] ? colors[colors.length - 1] : colors[0]; + return colors[index] ?? (value > stops[stops.length - 1] ? colors[colors.length - 1] : colors[0]); } function getNormalizedValueByRange( value: number, - { range, rangeMax, rangeMin }: CustomPaletteState, - minMax: { min: number; max: number }, - isMaxContinuity: boolean + { range, rangeMin }: CustomPaletteState, + minMax: { min: number; max: number } ) { let result = value; if (range === 'percent') { @@ -103,7 +102,7 @@ export function workoutColorForValue( const isMaxContinuity = checkIsMaxContinuity(continuity); // ranges can be absolute numbers or percentages // normalized the incoming value to the same format as range to make easier comparisons - const normalizedValue = getNormalizedValueByRange(value, params, minMax, isMaxContinuity); + const normalizedValue = getNormalizedValueByRange(value, params, minMax); const [min, max]: [number, number] = range === 'percent' ? [0, 100] : [minMax.min, minMax.max]; diff --git a/x-pack/plugins/lens/public/shared_components/coloring/palette_configuration.test.tsx b/x-pack/plugins/lens/public/shared_components/coloring/palette_configuration.test.tsx index 850c31708c650..a97f3d3f04112 100644 --- a/x-pack/plugins/lens/public/shared_components/coloring/palette_configuration.test.tsx +++ b/x-pack/plugins/lens/public/shared_components/coloring/palette_configuration.test.tsx @@ -154,7 +154,7 @@ describe('palette panel', () => { describe('percentage / number modes', () => { beforeEach(() => { props = { - activePalette: { type: 'palette', name: 'positive' }, + activePalette: { type: 'palette', name: 'custom' }, palettes: paletteRegistry, setPalette: jest.fn(), dataBounds: { min: 5, max: 200 },