projectCreationModal.spec.tsx 3.9 KB

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