utils.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import {
  2. combineStatus,
  3. getFileName,
  4. getStatusWeight,
  5. } from 'sentry/components/events/interfaces/debugMeta-v2/utils';
  6. import {ImageStatus} from 'sentry/types/debugImage';
  7. describe('DebugMeta - utils', () => {
  8. describe('getStatusWeight function', () => {
  9. const data = [
  10. {
  11. parameter: ImageStatus.FOUND,
  12. result: 1,
  13. },
  14. {
  15. parameter: ImageStatus.UNUSED,
  16. result: 0,
  17. },
  18. {
  19. parameter: null,
  20. result: 0,
  21. },
  22. {
  23. parameter: ImageStatus.MISSING,
  24. result: 2,
  25. },
  26. {
  27. parameter: ImageStatus.MALFORMED,
  28. result: 2,
  29. },
  30. {
  31. parameter: ImageStatus.FETCHING_FAILED,
  32. result: 2,
  33. },
  34. {
  35. parameter: ImageStatus.TIMEOUT,
  36. result: 2,
  37. },
  38. {
  39. parameter: ImageStatus.OTHER,
  40. result: 2,
  41. },
  42. ];
  43. it('should return a number according to the passed parameter', () => {
  44. for (const {parameter, result} of data) {
  45. const statusWeight = getStatusWeight(parameter);
  46. expect(statusWeight).toEqual(result);
  47. }
  48. });
  49. });
  50. describe('getFileName function', () => {
  51. const filePaths = [
  52. {
  53. fileName: 'libsystem_kernel.dylib',
  54. directory: '/usr/lib/system/',
  55. },
  56. {
  57. fileName: 'libsentry.dylib',
  58. directory: '/Users/user/Coding/sentry-native/build/',
  59. },
  60. ];
  61. it('should return the file name of a provided filepath', () => {
  62. for (const {directory, fileName} of filePaths) {
  63. const result = getFileName(`${directory}${fileName}`);
  64. expect(result).toEqual(fileName);
  65. }
  66. });
  67. });
  68. describe('combineStatus function', () => {
  69. const status = [
  70. {
  71. debugStatus: ImageStatus.MISSING,
  72. unwindStatus: ImageStatus.UNUSED,
  73. combinedStatus: ImageStatus.MISSING,
  74. },
  75. {
  76. debugStatus: ImageStatus.FOUND,
  77. unwindStatus: ImageStatus.MISSING,
  78. combinedStatus: ImageStatus.MISSING,
  79. },
  80. {
  81. debugStatus: ImageStatus.FOUND,
  82. unwindStatus: ImageStatus.UNUSED,
  83. combinedStatus: ImageStatus.FOUND,
  84. },
  85. {
  86. debugStatus: ImageStatus.FOUND,
  87. unwindStatus: null,
  88. combinedStatus: ImageStatus.FOUND,
  89. },
  90. {
  91. debugStatus: undefined,
  92. unwindStatus: undefined,
  93. combinedStatus: ImageStatus.UNUSED,
  94. },
  95. {
  96. debugStatus: undefined,
  97. unwindStatus: null,
  98. combinedStatus: ImageStatus.UNUSED,
  99. },
  100. {
  101. debugStatus: null,
  102. unwindStatus: null,
  103. combinedStatus: ImageStatus.UNUSED,
  104. },
  105. ];
  106. it('should return the status according to the passed parameters', () => {
  107. for (const {debugStatus, unwindStatus, combinedStatus} of status) {
  108. const result = combineStatus(debugStatus, unwindStatus);
  109. expect(result).toEqual(combinedStatus);
  110. }
  111. });
  112. });
  113. });