demoEndModal.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {act, renderGlobalModal, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {openModal} from 'sentry/actionCreators/modal';
  3. import DemoEndModal from 'sentry/components/modals/demoEndModal';
  4. describe('DemoEndModal', function () {
  5. const organization = TestStubs.Organization();
  6. it('closes on close button click', async function () {
  7. const closeModal = jest.fn();
  8. renderGlobalModal();
  9. act(() =>
  10. openModal(
  11. modalProps => (
  12. <DemoEndModal {...modalProps} orgSlug={organization.slug} tour="issues" />
  13. ),
  14. {onClose: closeModal}
  15. )
  16. );
  17. await userEvent.click(screen.getByRole('button', {name: 'Close Modal'}));
  18. expect(closeModal).toHaveBeenCalled();
  19. });
  20. it('restarts tour on button click', async function () {
  21. const finishMock = MockApiClient.addMockResponse({
  22. method: 'PUT',
  23. url: '/assistant/',
  24. });
  25. // Tests that fetchGuide is being called when tour is restarted
  26. MockApiClient.addMockResponse({
  27. method: 'GET',
  28. url: '/assistant/',
  29. });
  30. const {waitForModalToHide} = renderGlobalModal();
  31. act(() =>
  32. openModal(modalProps => (
  33. <DemoEndModal {...modalProps} orgSlug={organization.slug} tour="issues" />
  34. ))
  35. );
  36. await userEvent.click(screen.getByRole('button', {name: 'Restart Tour'}));
  37. await waitForModalToHide();
  38. expect(finishMock).toHaveBeenCalledWith(
  39. '/assistant/',
  40. expect.objectContaining({
  41. method: 'PUT',
  42. data: {
  43. guide: 'issues_v3',
  44. status: 'restart',
  45. },
  46. })
  47. );
  48. });
  49. it('opens sign up page on button click', function () {
  50. renderGlobalModal();
  51. act(() =>
  52. openModal(modalProps => (
  53. <DemoEndModal {...modalProps} orgSlug={organization.slug} tour="issues" />
  54. ))
  55. );
  56. const signUpButton = screen.getByRole('button', {name: 'Sign up for Sentry'});
  57. expect(signUpButton).toBeInTheDocument();
  58. expect(signUpButton).toHaveAttribute('href', 'https://sentry.io/signup/');
  59. });
  60. });