projectCreationModal.spec.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {MOCK_RESP_VERBOSE} from 'sentry-fixture/ruleConditions';
  3. import {TeamFixture} from 'sentry-fixture/team';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import {
  6. makeClosableHeader,
  7. makeCloseButton,
  8. ModalBody,
  9. ModalFooter,
  10. } from 'sentry/components/globalModal/components';
  11. import ProjectCreationModal from 'sentry/components/modals/projectCreationModal';
  12. import OrganizationStore from 'sentry/stores/organizationStore';
  13. import TeamStore from 'sentry/stores/teamStore';
  14. describe('Project Creation Modal', function () {
  15. const closeModal = jest.fn();
  16. const organization = OrganizationFixture();
  17. it('renders modal', async function () {
  18. render(
  19. <ProjectCreationModal
  20. defaultCategory="browser"
  21. Body={ModalBody}
  22. closeModal={jest.fn()}
  23. CloseButton={makeCloseButton(jest.fn())}
  24. Header={makeClosableHeader(jest.fn())}
  25. Footer={ModalFooter}
  26. />
  27. );
  28. expect(await screen.findByText('Create a Project')).toBeInTheDocument();
  29. });
  30. it('closes modal when closed', async function () {
  31. render(
  32. <ProjectCreationModal
  33. defaultCategory="browser"
  34. Body={ModalBody}
  35. closeModal={closeModal}
  36. CloseButton={makeCloseButton(closeModal)}
  37. Header={makeClosableHeader(closeModal)}
  38. Footer={ModalFooter}
  39. />
  40. );
  41. await userEvent.click(screen.getByRole('button', {name: 'Close Modal'}));
  42. expect(closeModal).toHaveBeenCalled();
  43. });
  44. it('creates project', async function () {
  45. const team = TeamFixture({
  46. access: ['team:admin', 'team:write', 'team:read'],
  47. });
  48. MockApiClient.addMockResponse({
  49. url: `/projects/${organization.slug}/rule-conditions/`,
  50. body: MOCK_RESP_VERBOSE,
  51. });
  52. MockApiClient.addMockResponse({
  53. url: `/organizations/${organization.slug}/teams/`,
  54. body: [team],
  55. });
  56. MockApiClient.addMockResponse({
  57. url: `/teams/${organization.slug}/${team.slug}/projects/`,
  58. method: 'POST',
  59. body: {slug: 'test-react-project'},
  60. });
  61. MockApiClient.addMockResponse({
  62. url: `/organizations/${organization.slug}/`,
  63. body: organization,
  64. });
  65. MockApiClient.addMockResponse({
  66. url: `/organizations/${organization.slug}/projects/`,
  67. body: [],
  68. });
  69. OrganizationStore.onUpdate(organization);
  70. TeamStore.loadUserTeams([team]);
  71. render(
  72. <ProjectCreationModal
  73. defaultCategory="browser"
  74. Body={ModalBody}
  75. closeModal={closeModal}
  76. CloseButton={makeCloseButton(closeModal)}
  77. Header={makeClosableHeader(closeModal)}
  78. Footer={ModalFooter}
  79. />
  80. );
  81. expect(screen.getByRole('button', {name: 'Next Step'})).toBeDisabled();
  82. await userEvent.click(screen.getByTestId('platform-javascript-react'));
  83. expect(screen.getByRole('button', {name: 'Next Step'})).toBeEnabled();
  84. await userEvent.click(screen.getByRole('button', {name: 'Next Step'}));
  85. expect(screen.getByRole('button', {name: 'Create Project'})).toBeDisabled();
  86. expect(await screen.findByText('Set your alert frequency')).toBeInTheDocument();
  87. await userEvent.click(screen.getByText("I'll create my own alerts later"));
  88. expect(
  89. await screen.findByText('Name your project and assign it a team')
  90. ).toBeInTheDocument();
  91. await userEvent.type(
  92. screen.getByPlaceholderText('project-name'),
  93. 'test-react-project'
  94. );
  95. await userEvent.type(screen.getByLabelText('Select a Team'), team.slug);
  96. await userEvent.click(screen.getByText(`#${team.slug}`));
  97. expect(screen.getByRole('button', {name: 'Create Project'})).toBeEnabled();
  98. await userEvent.click(screen.getByRole('button', {name: 'Create Project'}));
  99. expect(closeModal).toHaveBeenCalled();
  100. });
  101. });