dashboard.spec.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {MetricDisplayType} from 'sentry/utils/metrics';
  2. import {convertToDashboardWidget} from 'sentry/utils/metrics/dashboard';
  3. import {DisplayType} from 'sentry/views/dashboards/types';
  4. describe('convertToDashboardWidget', () => {
  5. it('should convert a metrics query to a dashboard widget (metrics mri, with grouping)', () => {
  6. expect(
  7. convertToDashboardWidget(
  8. {
  9. datetime: {
  10. start: '2021-06-01T00:00:00',
  11. end: '2021-06-02T00:00:00',
  12. period: '1d',
  13. utc: false,
  14. },
  15. groupBy: ['project'],
  16. query: 'event.type:transaction',
  17. projects: [1],
  18. environments: ['prod'],
  19. mri: 'c:custom/login@second',
  20. op: 'p95',
  21. },
  22. MetricDisplayType.AREA
  23. )
  24. ).toEqual({
  25. title: 'DDM Widget',
  26. displayType: DisplayType.AREA,
  27. widgetType: 'custom-metrics',
  28. limit: 10,
  29. queries: [
  30. {
  31. name: '',
  32. aggregates: ['p95(c:custom/login@second)'],
  33. columns: ['project'],
  34. fields: ['p95(c:custom/login@second)'],
  35. conditions: 'event.type:transaction',
  36. orderby: '',
  37. },
  38. ],
  39. });
  40. });
  41. it('should convert a metrics query to a dashboard widget (transaction mri, with grouping)', () => {
  42. expect(
  43. convertToDashboardWidget(
  44. {
  45. datetime: {
  46. start: '2021-06-01T00:00:00',
  47. end: '2021-06-02T00:00:00',
  48. period: '1d',
  49. utc: false,
  50. },
  51. groupBy: [],
  52. query: '',
  53. projects: [1],
  54. environments: ['prod'],
  55. mri: 'd:transactions/measurements.duration@second',
  56. op: 'p95',
  57. },
  58. MetricDisplayType.BAR
  59. )
  60. ).toEqual({
  61. title: 'DDM Widget',
  62. displayType: DisplayType.BAR,
  63. widgetType: 'discover',
  64. limit: 1,
  65. queries: [
  66. {
  67. name: '',
  68. aggregates: ['p95(measurements.duration)'],
  69. columns: [],
  70. fields: ['p95(measurements.duration)'],
  71. conditions: '',
  72. orderby: '',
  73. },
  74. ],
  75. });
  76. });
  77. });