issueDiff.spec.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import {IssueDiff} from 'sentry/components/issueDiff';
  3. jest.mock('sentry/api');
  4. describe('IssueDiff', function () {
  5. const entries = TestStubs.Entries();
  6. const api = new MockApiClient();
  7. const project = TestStubs.ProjectDetails();
  8. beforeEach(function () {
  9. MockApiClient.addMockResponse({
  10. url: '/issues/base/events/latest/',
  11. body: {
  12. eventID: '123base',
  13. },
  14. });
  15. MockApiClient.addMockResponse({
  16. url: '/issues/target/events/latest/',
  17. body: {
  18. eventID: '123target',
  19. },
  20. });
  21. MockApiClient.addMockResponse({
  22. url: `/projects/org-slug/${project.slug}/events/123target/`,
  23. body: {
  24. entries: entries[0],
  25. },
  26. });
  27. MockApiClient.addMockResponse({
  28. url: `/projects/org-slug/${project.slug}/events/123base/`,
  29. body: {
  30. platform: 'javascript',
  31. entries: entries[1],
  32. },
  33. });
  34. });
  35. afterEach(function () {
  36. MockApiClient.clearMockResponses();
  37. });
  38. it('is loading when initially rendering', function () {
  39. const wrapper = render(
  40. <IssueDiff
  41. api={api}
  42. baseIssueId="base"
  43. targetIssueId="target"
  44. orgId="org-slug"
  45. project={project}
  46. />
  47. );
  48. expect(screen.queryByTestId('split-diff')).not.toBeInTheDocument();
  49. expect(wrapper.container).toSnapshot();
  50. });
  51. it('can dynamically import SplitDiff', async function () {
  52. const wrapper = render(
  53. <IssueDiff
  54. api={api}
  55. baseIssueId="base"
  56. targetIssueId="target"
  57. orgId="org-slug"
  58. project={project}
  59. />
  60. );
  61. expect(await screen.findByTestId('split-diff')).toBeInTheDocument();
  62. expect(wrapper.container).toSnapshot();
  63. });
  64. it('can diff message', async function () {
  65. MockApiClient.addMockResponse({
  66. url: `/projects/org-slug/${project.slug}/events/123target/`,
  67. body: {
  68. entries: [{type: 'message', data: {formatted: 'Hello World'}}],
  69. },
  70. });
  71. MockApiClient.addMockResponse({
  72. url: `/projects/org-slug/${project.slug}/events/123base/`,
  73. body: {
  74. platform: 'javascript',
  75. entries: [{type: 'message', data: {formatted: 'Foo World'}}],
  76. },
  77. });
  78. const wrapper = render(
  79. <IssueDiff
  80. api={api}
  81. baseIssueId="base"
  82. targetIssueId="target"
  83. orgId="org-slug"
  84. project={project}
  85. />
  86. );
  87. expect(await screen.findByTestId('split-diff')).toBeInTheDocument();
  88. expect(wrapper.container).toSnapshot();
  89. });
  90. });