issueDiff.spec.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. let routerContext = TestStubs.routerContext();
  9. let api = new MockApiClient();
  10. it('is loading when initially rendering', function() {
  11. let wrapper = shallow(<IssueDiff baseIssueId="base" targetIssueId="target" />);
  12. expect(wrapper.find('SplitDiff')).toHaveLength(0);
  13. expect(wrapper).toMatchSnapshot();
  14. });
  15. it('can dynamically import SplitDiff', async function() {
  16. Client.addMockResponse({
  17. url: '/issues/target/events/latest/',
  18. body: {
  19. entries: entries[0],
  20. },
  21. });
  22. Client.addMockResponse({
  23. url: '/issues/base/events/latest/',
  24. body: {
  25. platform: 'javascript',
  26. entries: entries[1],
  27. },
  28. });
  29. // Need `mount` because of componentDidMount in <IssueDiff>
  30. let wrapper = mount(
  31. <IssueDiff api={api} baseIssueId="base" targetIssueId="target" />,
  32. routerContext
  33. );
  34. await tick();
  35. wrapper.update();
  36. expect(wrapper.find('SplitDiff')).toHaveLength(1);
  37. expect(wrapper).toMatchSnapshot();
  38. });
  39. it('can diff message', async function() {
  40. Client.addMockResponse({
  41. url: '/issues/target/events/latest/',
  42. body: {
  43. entries: [{type: 'message', data: {message: 'Hello World'}}],
  44. },
  45. });
  46. Client.addMockResponse({
  47. url: '/issues/base/events/latest/',
  48. body: {
  49. platform: 'javascript',
  50. entries: [{type: 'message', data: {message: 'Foo World'}}],
  51. },
  52. });
  53. // Need `mount` because of componentDidMount in <IssueDiff>
  54. let wrapper = mount(
  55. <IssueDiff api={api} baseIssueId="base" targetIssueId="target" />,
  56. routerContext
  57. );
  58. await tick();
  59. wrapper.update();
  60. expect(wrapper.find('SplitDiff')).toHaveLength(1);
  61. expect(wrapper).toMatchSnapshot();
  62. });
  63. });