issueDiff.spec.jsx 2.2 KB

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