demoEndModal.spec.tsx 2.1 KB

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