errorRobot.spec.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {Organization} from 'fixtures/js-stubs/organization';
  2. import {Project} from 'fixtures/js-stubs/project';
  3. import {routerContext} from 'fixtures/js-stubs/routerContext';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import {Client} from 'sentry/api';
  6. import {ErrorRobot} from 'sentry/components/errorRobot';
  7. describe('ErrorRobot', function () {
  8. let getIssues;
  9. let routerContext;
  10. beforeEach(function () {
  11. routerContext = routerContext();
  12. getIssues = Client.addMockResponse({
  13. url: '/projects/org-slug/project-slug/issues/',
  14. method: 'GET',
  15. body: [],
  16. });
  17. });
  18. afterEach(() => {
  19. jest.clearAllMocks();
  20. Client.clearMockResponses();
  21. });
  22. describe('with a project', function () {
  23. function createWrapper() {
  24. return render(
  25. <ErrorRobot api={new MockApiClient()} org={Organization()} project={Project()} />,
  26. {context: routerContext}
  27. );
  28. }
  29. it('Renders a button for creating an event', function () {
  30. createWrapper();
  31. const button = screen.getByRole('button', {name: 'Create a sample event'});
  32. expect(button).toBeEnabled();
  33. expect(getIssues).toHaveBeenCalled();
  34. });
  35. it('Renders installation instructions', function () {
  36. createWrapper();
  37. userEvent.click(screen.getByText('Installation Instructions'));
  38. expect(routerContext.context.router.push).toHaveBeenCalledWith(
  39. '/org-slug/project-slug/getting-started/'
  40. );
  41. });
  42. });
  43. describe('without a project', function () {
  44. function createWrapper() {
  45. return render(<ErrorRobot api={new MockApiClient()} org={Organization()} />, {
  46. context: routerContext,
  47. });
  48. }
  49. it('Renders a disabled create event button', function () {
  50. createWrapper();
  51. const button = screen.getByRole('button', {name: 'Create a sample event'});
  52. expect(button).toBeDisabled();
  53. expect(getIssues).toHaveBeenCalledTimes(0);
  54. });
  55. it('does not display install instructions', function () {
  56. createWrapper();
  57. expect(screen.queryByText('Installation Instructions')).not.toBeInTheDocument();
  58. });
  59. });
  60. });