getCurrentUrl.spec.tsx 2.9 KB

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