errorRobot.spec.jsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 org={TestStubs.Organization()} project={TestStubs.Project()} />
  21. );
  22. });
  23. it('Renders a button for creating an event', function() {
  24. let button = wrapper.find('Button[priority="link"]');
  25. expect(button).toHaveLength(1);
  26. expect(button.props().onClick).toBeDefined();
  27. expect(button.props().disabled).toBeFalsy();
  28. expect(getIssues).toHaveBeenCalled();
  29. });
  30. it('Renders installation instructions', function() {
  31. let button = wrapper.find('Button[priority="primary"]');
  32. expect(button).toHaveLength(1);
  33. expect(button.props().to).toEqual(expect.stringContaining('getting-started'));
  34. });
  35. it('can create a sample event', async function() {
  36. Client.addMockResponse({
  37. url: '/projects/org-slug/project-slug/create-sample/',
  38. method: 'POST',
  39. body: {groupID: 999},
  40. });
  41. wrapper.find('Button[priority="link"]').simulate('click');
  42. await wrapper.update();
  43. expect(browserHistory.push).toHaveBeenCalled();
  44. });
  45. });
  46. describe('without a project', function() {
  47. let wrapper;
  48. beforeEach(function() {
  49. wrapper = shallow(<ErrorRobot org={TestStubs.Organization()} />);
  50. });
  51. it('Renders a disabled create event button', function() {
  52. let button = wrapper.find('Button[priority="link"]');
  53. expect(button).toHaveLength(1);
  54. expect(button.props().disabled).toBeTruthy();
  55. expect(getIssues).toHaveBeenCalledTimes(0);
  56. });
  57. it('does not display install instructions', function() {
  58. let button = wrapper.find('Button[priority="primary"]');
  59. expect(button).toHaveLength(0);
  60. });
  61. });
  62. });