utils.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import {LocationFixture} from 'sentry-fixture/locationFixture';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {viewSamplesTarget} from 'sentry/views/explore/utils';
  4. describe('viewSamplesTarget', function () {
  5. const project = ProjectFixture();
  6. const extras = {projects: [project]};
  7. it('simple drill down with no group bys', function () {
  8. const location = LocationFixture();
  9. const target = viewSamplesTarget(location, '', [], {}, extras);
  10. expect(target).toMatchObject({
  11. query: {
  12. mode: 'samples',
  13. query: '',
  14. },
  15. });
  16. });
  17. it('simple drill down with single group by', function () {
  18. const location = LocationFixture();
  19. const target = viewSamplesTarget(
  20. location,
  21. '',
  22. ['foo'],
  23. {foo: 'foo', 'count()': 10},
  24. extras
  25. );
  26. expect(target).toMatchObject({
  27. query: {
  28. mode: 'samples',
  29. query: 'foo:foo',
  30. },
  31. });
  32. });
  33. it('simple drill down with multiple group bys', function () {
  34. const location = LocationFixture();
  35. const target = viewSamplesTarget(
  36. location,
  37. '',
  38. ['foo', 'bar', 'baz'],
  39. {
  40. foo: 'foo',
  41. bar: 'bar',
  42. baz: 'baz',
  43. 'count()': 10,
  44. },
  45. extras
  46. );
  47. expect(target).toMatchObject({
  48. query: {
  49. mode: 'samples',
  50. query: 'foo:foo bar:bar baz:baz',
  51. },
  52. });
  53. });
  54. it('simple drill down with on environment', function () {
  55. const location = LocationFixture();
  56. const target = viewSamplesTarget(
  57. location,
  58. '',
  59. ['environment'],
  60. {
  61. environment: 'prod',
  62. 'count()': 10,
  63. },
  64. extras
  65. );
  66. expect(target).toMatchObject({
  67. query: {
  68. mode: 'samples',
  69. query: '',
  70. environment: 'prod',
  71. },
  72. });
  73. });
  74. it('simple drill down with on project id', function () {
  75. const location = LocationFixture();
  76. const target = viewSamplesTarget(
  77. location,
  78. '',
  79. ['project.id'],
  80. {
  81. 'project.id': 1,
  82. 'count()': 10,
  83. },
  84. extras
  85. );
  86. expect(target).toMatchObject({
  87. query: {
  88. mode: 'samples',
  89. query: '',
  90. project: '1',
  91. },
  92. });
  93. });
  94. it('simple drill down with on project slug', function () {
  95. const location = LocationFixture();
  96. const target = viewSamplesTarget(
  97. location,
  98. '',
  99. ['project'],
  100. {
  101. project: project.slug,
  102. 'count()': 10,
  103. },
  104. extras
  105. );
  106. expect(target).toMatchObject({
  107. query: {
  108. mode: 'samples',
  109. query: '',
  110. project: String(project.id),
  111. },
  112. });
  113. });
  114. });