getCurrentUrl.spec.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import getCurrentUrl from 'sentry/utils/replays/getCurrentUrl';
  2. import {replayInitBreadcrumb} from 'sentry/utils/replays/hydrateBreadcrumbs';
  3. import hydrateSpans from 'sentry/utils/replays/hydrateSpans';
  4. const START_DATE = new Date('2022-06-15T00:40:00.111Z');
  5. const NAVIGATION_DATE = new Date('2022-06-15T00:46:00.333Z');
  6. const NEW_DOMAIN_DATE = new Date('2022-06-15T00:47:00.444Z');
  7. const END_DATE = new Date('2022-06-15T00:50:00.555Z');
  8. const replayRecord = TestStubs.ReplayRecord({
  9. started_at: START_DATE,
  10. finished_at: END_DATE,
  11. });
  12. const PAGELOAD_FRAME = replayInitBreadcrumb(replayRecord);
  13. const [NAV_FRAME, NEW_DOMAIN_FRAME] = hydrateSpans(replayRecord, [
  14. TestStubs.Replay.NavigationPushFrame({
  15. description:
  16. '/report/1655300817078_https%3A%2F%2Fmaxcdn.bootstrapcdn.com%2Fbootstrap%2F3.3.7%2Fjs%2Fbootstrap.min.js',
  17. startTimestamp: NAVIGATION_DATE,
  18. endTimestamp: NAVIGATION_DATE,
  19. }),
  20. TestStubs.Replay.NavigationFrame({
  21. description: 'https://a062-174-94-6-155.ngrok.io/report/jquery.min.js',
  22. startTimestamp: NEW_DOMAIN_DATE,
  23. endTimestamp: NEW_DOMAIN_DATE,
  24. }),
  25. ]);
  26. describe('getCurrentUrl', () => {
  27. it('should return the origin of the first url from the url array if the offset is early', () => {
  28. const frames = [PAGELOAD_FRAME, NAV_FRAME];
  29. const offsetMS = 0;
  30. const url = getCurrentUrl(TestStubs.ReplayRecord(), frames, offsetMS);
  31. expect(url).toBe('http://localhost:3000/');
  32. });
  33. it('should return the first navigation url when the offset is after that', () => {
  34. const frames = [PAGELOAD_FRAME, NAV_FRAME];
  35. const offsetMS = Number(NAVIGATION_DATE) - Number(START_DATE) + 10;
  36. const url = getCurrentUrl(TestStubs.ReplayRecord(), frames, offsetMS);
  37. expect(url).toBe(
  38. 'http://localhost:3000/report/1655300817078_https%3A%2F%2Fmaxcdn.bootstrapcdn.com%2Fbootstrap%2F3.3.7%2Fjs%2Fbootstrap.min.js'
  39. );
  40. });
  41. it('should use the domain that is included in the ReplayRecord, not the one in the frame', () => {
  42. const frames = [NEW_DOMAIN_FRAME];
  43. const offsetMS = Number(NEW_DOMAIN_DATE) - Number(START_DATE) + 10;
  44. const url = getCurrentUrl(TestStubs.ReplayRecord(), frames, offsetMS);
  45. expect(url).toBe('http://localhost:3000/report/jquery.min.js');
  46. });
  47. });