getEventsUrlFromDiscoverQueryWithConditions.spec.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {getEventsUrlFromDiscoverQueryWithConditions} from 'app/views/dashboards/utils/getEventsUrlFromDiscoverQueryWithConditions';
  2. describe('getEventsUrlFromDiscoverQueryWithConditions', function() {
  3. const organization = TestStubs.Organization();
  4. it('single field', function() {
  5. const query = {
  6. fields: ['browser.name'],
  7. conditions: [],
  8. aggregations: ['count()', null, 'count'],
  9. limit: 1000,
  10. orderby: 'count',
  11. };
  12. expect(
  13. getEventsUrlFromDiscoverQueryWithConditions({
  14. organization,
  15. selection: {
  16. datetime: {
  17. start: null,
  18. end: null,
  19. period: '14d',
  20. },
  21. },
  22. query,
  23. values: ['Chrome'],
  24. })
  25. ).toBe(
  26. '/organizations/org-slug/events/?query=browser.name%3A%22Chrome%22&statsPeriod=14d'
  27. );
  28. });
  29. it('multiple fields', function() {
  30. const query = {
  31. fields: ['browser.name', 'device'],
  32. conditions: [],
  33. aggregations: ['count()', null, 'count'],
  34. limit: 1000,
  35. orderby: 'count',
  36. };
  37. expect(
  38. getEventsUrlFromDiscoverQueryWithConditions({
  39. organization,
  40. selection: {
  41. datetime: {
  42. start: null,
  43. end: null,
  44. period: '14d',
  45. },
  46. },
  47. query,
  48. values: ['Chrome', 'iPhone'],
  49. })
  50. ).toBe(
  51. '/organizations/org-slug/events/?query=browser.name%3A%22Chrome%22%20device%3A%22iPhone%22&statsPeriod=14d'
  52. );
  53. });
  54. it('handles null values and spaces', function() {
  55. const query = {
  56. fields: ['browser.name', 'device'],
  57. conditions: [],
  58. aggregations: ['count()', null, 'count'],
  59. limit: 1000,
  60. orderby: 'count',
  61. };
  62. expect(
  63. getEventsUrlFromDiscoverQueryWithConditions({
  64. organization,
  65. selection: {
  66. datetime: {
  67. start: null,
  68. end: null,
  69. period: '14d',
  70. },
  71. },
  72. query,
  73. values: [null, 'iPhone X'],
  74. })
  75. ).toBe(
  76. '/organizations/org-slug/events/?query=browser.name%3A%22%22%20device%3A%22iPhone%20X%22&statsPeriod=14d'
  77. );
  78. });
  79. });