baseChart.spec.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import ReactEchartsCore from 'echarts-for-react/lib/core';
  2. import {render} from 'sentry-test/reactTestingLibrary';
  3. import BaseChart from 'sentry/components/charts/baseChart';
  4. import theme from 'sentry/utils/theme';
  5. jest.mock('echarts-for-react/lib/core', () => {
  6. return jest.fn(() => null);
  7. });
  8. describe('BaseChart', function () {
  9. it('renders with grey dotted previous period when using only a single series', function () {
  10. render(
  11. <BaseChart
  12. colors={['#444674', '#d6567f', '#f2b712']}
  13. previousPeriod={[
  14. {seriesName: 'count()', data: [{value: 123, name: new Date().getTime()}]},
  15. ]}
  16. />
  17. );
  18. // @ts-expect-error
  19. const series = ReactEchartsCore.mock.calls[0][0].option.series;
  20. expect(series.length).toEqual(1);
  21. expect(series[0].lineStyle.color).toEqual(theme.gray200);
  22. expect(series[0].lineStyle.type).toEqual('dotted');
  23. });
  24. it('renders with lightened colored dotted previous period when using multiple series', function () {
  25. render(
  26. <BaseChart
  27. colors={['#444674', '#d6567f', '#f2b712']}
  28. previousPeriod={[
  29. {seriesName: 'count()', data: [{value: 123, name: new Date().getTime()}]},
  30. {
  31. seriesName: 'count_unique(user)',
  32. data: [{value: 123, name: new Date().getTime()}],
  33. },
  34. {
  35. seriesName: 'failure_count()',
  36. data: [{value: 123, name: new Date().getTime()}],
  37. },
  38. ]}
  39. />
  40. );
  41. const series =
  42. // @ts-expect-error
  43. ReactEchartsCore.mock.calls[ReactEchartsCore.mock.calls.length - 1][0].option
  44. .series;
  45. expect(series.length).toEqual(3);
  46. expect(series[0].lineStyle.color).toEqual('rgb(98, 100, 146)');
  47. expect(series[0].lineStyle.type).toEqual('dotted');
  48. expect(series[1].lineStyle.color).toEqual('rgb(244, 116, 157)');
  49. expect(series[1].lineStyle.type).toEqual('dotted');
  50. expect(series[2].lineStyle.color).toEqual('rgb(255, 213, 48)');
  51. expect(series[2].lineStyle.type).toEqual('dotted');
  52. });
  53. });