All files / app/components/RatingsSlider getSliderColor.tsx

64.28% Statements 9/14
100% Branches 0/0
0% Functions 0/1
61.53% Lines 8/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 221x   1x 1x       1x 1x 1x 1x   1x                  
import { theme } from "theme";
 
const goodRatingRed = parseInt(theme.palette.success.main.substring(1, 3), 16);
const goodRatingGreen = parseInt(
  theme.palette.success.main.substring(3, 5),
  16
);
const goodRatingBlue = parseInt(theme.palette.success.main.substring(5, 7), 16);
const badRatingRed = parseInt(theme.palette.error.main.substring(1, 3), 16);
const badRatingGreen = parseInt(theme.palette.error.main.substring(3, 5), 16);
const badRatingBlue = parseInt(theme.palette.error.main.substring(5, 7), 16);
 
export const getSliderColor = (value: number) => {
  const r = Math.ceil(goodRatingRed * value + badRatingRed * (1 - value));
  const g = Math.ceil(goodRatingGreen * value + badRatingGreen * (1 - value));
  const b = Math.ceil(goodRatingBlue * value + badRatingBlue * (1 - value));
 
  const rgb = `rgb(${r}, ${g}, ${b})`;
 
  return rgb;
};