errorRobot.spec.jsx 2.0 KB

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