utils.spec.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {getInitialTimeOffset} from 'sentry/views/replays/utils';
  2. describe('getInitialTimeOffset', () => {
  3. it('should return the initialTimeOffset if provided', () => {
  4. expect(
  5. getInitialTimeOffset({
  6. initialTimeOffset: 123,
  7. eventTimestamp: '1666047045297',
  8. startTimestampMs: 1666047046000,
  9. })
  10. ).toBe(123);
  11. });
  12. it('should return 0 if no required params are provided', () => {
  13. expect(getInitialTimeOffset({startTimestampMs: 1666047046000})).toBe(0);
  14. expect(getInitialTimeOffset({})).toBe(0);
  15. expect(getInitialTimeOffset({eventTimestamp: '1666047045297'})).toBe(0);
  16. });
  17. it('should return 0 if the eventTimestamp is not the correct format', () => {
  18. expect(getInitialTimeOffset({eventTimestamp: '123'})).toBe(0);
  19. });
  20. it('should return 0 if the eventTimestamp is not within the range of the replay', () => {
  21. expect(
  22. getInitialTimeOffset({
  23. eventTimestamp: '1666047045297',
  24. startTimestampMs: 1666047046000,
  25. })
  26. ).toBe(0);
  27. });
  28. it('should return the correct initialTimeOffset if the eventTimestamp is within the range of the replay', () => {
  29. expect(
  30. getInitialTimeOffset({
  31. eventTimestamp: '1666047046000',
  32. startTimestampMs: 1666047045000,
  33. })
  34. ).toBe(1);
  35. });
  36. it('should return the correct initialTimeOffset if the eventTimestamp is the correct format', () => {
  37. expect(
  38. getInitialTimeOffset({
  39. eventTimestamp: '1666047045297',
  40. startTimestampMs: 1666047045000,
  41. })
  42. ).toBe(0.297);
  43. expect(
  44. getInitialTimeOffset({
  45. eventTimestamp: '2022-10-17T22:50:46.000Z',
  46. startTimestampMs: 1666047045000,
  47. })
  48. ).toBe(1);
  49. });
  50. });