issueDiff.spec.jsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import React from 'react';
  2. import {mountWithTheme, shallow} from 'sentry-test/enzyme';
  3. import {IssueDiff} from 'app/components/issueDiff';
  4. import {Client} from 'app/api';
  5. jest.mock('app/api');
  6. describe('IssueDiff', function() {
  7. const entries = TestStubs.Entries();
  8. const routerContext = TestStubs.routerContext();
  9. const api = new MockApiClient();
  10. it('is loading when initially rendering', function() {
  11. const wrapper = shallow(
  12. <IssueDiff
  13. api={api}
  14. baseIssueId="base"
  15. targetIssueId="target"
  16. orgId="org-slug"
  17. projectId="project-slug"
  18. />
  19. );
  20. expect(wrapper.find('SplitDiff')).toHaveLength(0);
  21. expect(wrapper).toMatchSnapshot();
  22. });
  23. it('can dynamically import SplitDiff', async function() {
  24. Client.addMockResponse({
  25. url: '/issues/target/events/latest/',
  26. body: {
  27. entries: entries[0],
  28. },
  29. });
  30. Client.addMockResponse({
  31. url: '/issues/base/events/latest/',
  32. body: {
  33. platform: 'javascript',
  34. entries: entries[1],
  35. },
  36. });
  37. // Need `mount` because of componentDidMount in <IssueDiff>
  38. const wrapper = mountWithTheme(
  39. <IssueDiff
  40. api={api}
  41. baseIssueId="base"
  42. targetIssueId="target"
  43. orgId="org-slug"
  44. projectId="project-slug"
  45. />,
  46. routerContext
  47. );
  48. await tick();
  49. wrapper.update();
  50. expect(wrapper.find('SplitDiff')).toHaveLength(1);
  51. expect(wrapper).toMatchSnapshot();
  52. });
  53. it('can diff message', async function() {
  54. Client.addMockResponse({
  55. url: '/issues/target/events/latest/',
  56. body: {
  57. entries: [{type: 'message', data: {formatted: 'Hello World'}}],
  58. },
  59. });
  60. Client.addMockResponse({
  61. url: '/issues/base/events/latest/',
  62. body: {
  63. platform: 'javascript',
  64. entries: [{type: 'message', data: {formatted: 'Foo World'}}],
  65. },
  66. });
  67. // Need `mount` because of componentDidMount in <IssueDiff>
  68. const wrapper = mountWithTheme(
  69. <IssueDiff
  70. api={api}
  71. baseIssueId="base"
  72. targetIssueId="target"
  73. orgId="org-slug"
  74. projectId="project-slug"
  75. />,
  76. routerContext
  77. );
  78. await tick();
  79. wrapper.update();
  80. expect(wrapper.find('SplitDiff')).toHaveLength(1);
  81. expect(wrapper).toMatchSnapshot();
  82. });
  83. });