errorRobot.spec.jsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React from 'react';
  2. import {browserHistory} from 'react-router';
  3. import {shallow} from 'enzyme';
  4. import {Client} from 'app/api';
  5. import {ErrorRobot} from 'app/components/errorRobot';
  6. describe('ErrorRobot', function() {
  7. let getIssues;
  8. beforeEach(function() {
  9. Client.clearMockResponses();
  10. getIssues = Client.addMockResponse({
  11. url: '/projects/org-slug/project-slug/issues/',
  12. method: 'GET',
  13. body: [],
  14. });
  15. });
  16. describe('with a project', function() {
  17. let wrapper;
  18. beforeEach(function() {
  19. wrapper = shallow(
  20. <ErrorRobot
  21. api={new MockApiClient()}
  22. org={TestStubs.Organization()}
  23. project={TestStubs.Project()}
  24. />
  25. );
  26. });
  27. it('Renders a button for creating an event', function() {
  28. const button = wrapper.find('Button[priority="link"]');
  29. expect(button).toHaveLength(1);
  30. expect(button.props().onClick).toBeDefined();
  31. expect(button.props().disabled).toBeFalsy();
  32. expect(getIssues).toHaveBeenCalled();
  33. });
  34. it('Renders installation instructions', function() {
  35. const button = wrapper.find('Button[priority="primary"]');
  36. expect(button).toHaveLength(1);
  37. expect(button.props().to).toEqual(expect.stringContaining('getting-started'));
  38. });
  39. it('can create a sample event', async function() {
  40. Client.addMockResponse({
  41. url: '/projects/org-slug/project-slug/create-sample/',
  42. method: 'POST',
  43. body: {groupID: 999},
  44. });
  45. wrapper.find('Button[priority="link"]').simulate('click');
  46. await wrapper.update();
  47. expect(browserHistory.push).toHaveBeenCalled();
  48. });
  49. });
  50. describe('without a project', function() {
  51. let wrapper;
  52. beforeEach(function() {
  53. wrapper = shallow(
  54. <ErrorRobot api={new MockApiClient()} org={TestStubs.Organization()} />
  55. );
  56. });
  57. it('Renders a disabled create event button', function() {
  58. const button = wrapper.find('Button[priority="link"]');
  59. expect(button).toHaveLength(1);
  60. expect(button.props().disabled).toBeTruthy();
  61. expect(getIssues).toHaveBeenCalledTimes(0);
  62. });
  63. it('does not display install instructions', function() {
  64. const button = wrapper.find('Button[priority="primary"]');
  65. expect(button).toHaveLength(0);
  66. });
  67. });
  68. });