utils.spec.jsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import {barColors, pickBarColor} from 'sentry/components/performance/waterfall/utils';
  2. import CHART_PALETTE from 'sentry/constants/chartPalette';
  3. describe('pickBarColor()', function () {
  4. it('returns blue when undefined', function () {
  5. expect(pickBarColor(undefined)).toEqual(barColors.default);
  6. });
  7. it('returns the predefined color when available', function () {
  8. expect(pickBarColor('transaction')).toEqual(barColors.transaction);
  9. });
  10. it('returns blue when the string is too short', function () {
  11. expect(pickBarColor('')).toEqual(barColors.default);
  12. expect(pickBarColor('c')).toEqual(barColors.default);
  13. });
  14. it('returns a random color when no predefined option is available', function () {
  15. const colorsAsArray = Object.keys(CHART_PALETTE).map(key => CHART_PALETTE[17][key]);
  16. let randomColor = pickBarColor('a normal string');
  17. expect(colorsAsArray).toContain(randomColor);
  18. randomColor = pickBarColor('this is a rather long string, it is longer than most');
  19. expect(colorsAsArray).toContain(randomColor);
  20. randomColor = pickBarColor('.periods.period');
  21. expect(colorsAsArray).toContain(randomColor);
  22. randomColor = pickBarColor('!!!!!!!!!!!');
  23. expect(colorsAsArray).toContain(randomColor);
  24. randomColor = pickBarColor(' ');
  25. expect(colorsAsArray).toContain(randomColor);
  26. });
  27. });