getCurrentUrl.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import type {Crumb} from 'sentry/types/breadcrumbs';
  2. import {BreadcrumbLevelType, BreadcrumbType} from 'sentry/types/breadcrumbs';
  3. import getCurrentUrl from 'sentry/utils/replays/getCurrentUrl';
  4. const START_DATE = new Date('2022-06-15T00:40:00.111Z');
  5. const PAGELOAD_DATE = new Date('2022-06-15T00:45:00.222Z');
  6. const NAVIGATION_DATE = new Date('2022-06-15T00:46:00.333Z');
  7. const NEW_DOMAIN_DATE = new Date('2022-06-15T00:47:00.444Z');
  8. const END_DATE = new Date('2022-06-15T00:50:00.555Z');
  9. const PAGELOAD_CRUMB: Crumb = {
  10. category: 'default',
  11. type: BreadcrumbType.NAVIGATION,
  12. timestamp: PAGELOAD_DATE.toISOString(),
  13. level: BreadcrumbLevelType.INFO,
  14. message: 'https://sourcemaps.io/',
  15. data: {
  16. to: 'https://sourcemaps.io/',
  17. },
  18. id: 6,
  19. color: 'green300',
  20. description: 'Navigation',
  21. };
  22. const NAV_CRUMB: Crumb = {
  23. type: BreadcrumbType.NAVIGATION,
  24. category: 'navigation',
  25. data: {
  26. from: '/',
  27. to: '/report/1655300817078_https%3A%2F%2Fmaxcdn.bootstrapcdn.com%2Fbootstrap%2F3.3.7%2Fjs%2Fbootstrap.min.js',
  28. },
  29. timestamp: NAVIGATION_DATE.toISOString(),
  30. id: 5,
  31. color: 'green300',
  32. description: 'Navigation',
  33. level: BreadcrumbLevelType.UNDEFINED,
  34. };
  35. const NEW_DOMAIN_CRUMB: Crumb = {
  36. category: 'default',
  37. type: BreadcrumbType.NAVIGATION,
  38. timestamp: NEW_DOMAIN_DATE.toISOString(),
  39. level: BreadcrumbLevelType.INFO,
  40. message: 'https://a062-174-94-6-155.ngrok.io/report/jquery.min.js',
  41. data: {
  42. to: 'https://a062-174-94-6-155.ngrok.io/report/jquery.min.js',
  43. },
  44. id: 29,
  45. color: 'green300',
  46. description: 'Navigation',
  47. };
  48. describe('getCurrentUrl', () => {
  49. const event = TestStubs.Event({
  50. tags: [
  51. {
  52. key: 'url',
  53. value: 'https://sourcemaps.io/#initial',
  54. },
  55. ],
  56. startTimestamp: Number(START_DATE) / 1000,
  57. endTimestamp: Number(END_DATE) / 1000,
  58. });
  59. it('should return the url from tags when the offset is early', () => {
  60. const crumbs = [PAGELOAD_CRUMB, NAV_CRUMB];
  61. const offsetMS = 0;
  62. const url = getCurrentUrl(event, crumbs, offsetMS);
  63. expect(url).toBe('https://sourcemaps.io/#initial');
  64. });
  65. it('should return the first navigation url when the offset is after that', () => {
  66. const crumbs = [PAGELOAD_CRUMB, NAV_CRUMB];
  67. const offsetMS = Number(NAVIGATION_DATE) - Number(START_DATE) + 10;
  68. const url = getCurrentUrl(event, crumbs, offsetMS);
  69. expect(url).toBe(
  70. 'https://sourcemaps.io/report/1655300817078_https%3A%2F%2Fmaxcdn.bootstrapcdn.com%2Fbootstrap%2F3.3.7%2Fjs%2Fbootstrap.min.js'
  71. );
  72. });
  73. it('should use the domain that is included in the crumb, if the crumb is a valid url', () => {
  74. const crumbs = [NEW_DOMAIN_CRUMB];
  75. const offsetMS = Number(NEW_DOMAIN_DATE) - Number(START_DATE) + 10;
  76. const url = getCurrentUrl(event, crumbs, offsetMS);
  77. expect(url).toBe('https://a062-174-94-6-155.ngrok.io/report/jquery.min.js');
  78. });
  79. });