index.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {TeamFixture} from 'sentry-fixture/team';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {
  5. render,
  6. renderGlobalModal,
  7. screen,
  8. userEvent,
  9. waitFor,
  10. } from 'sentry-test/reactTestingLibrary';
  11. import TeamStore from 'sentry/stores/teamStore';
  12. import TeamSettings from 'sentry/views/settings/organizationTeams/teamSettings';
  13. describe('TeamSettings', function () {
  14. const {router, routerProps} = initializeOrg();
  15. beforeEach(function () {
  16. TeamStore.reset();
  17. MockApiClient.clearMockResponses();
  18. jest.spyOn(window.location, 'assign');
  19. });
  20. afterEach(function () {
  21. jest.mocked(window.location.assign).mockRestore();
  22. });
  23. it('can change slug', async function () {
  24. const team = TeamFixture();
  25. const putMock = MockApiClient.addMockResponse({
  26. url: `/teams/org-slug/${team.slug}/`,
  27. method: 'PUT',
  28. body: {
  29. slug: 'new-slug',
  30. },
  31. });
  32. render(<TeamSettings {...routerProps} team={team} params={{teamId: team.slug}} />, {
  33. router,
  34. });
  35. const input = screen.getByRole('textbox', {name: 'Team Slug'});
  36. await userEvent.clear(input);
  37. await userEvent.type(input, 'NEW SLUG');
  38. await userEvent.click(screen.getByRole('button', {name: 'Save'}));
  39. expect(putMock).toHaveBeenCalledWith(
  40. `/teams/org-slug/${team.slug}/`,
  41. expect.objectContaining({
  42. data: {
  43. slug: 'new-slug',
  44. },
  45. })
  46. );
  47. await waitFor(() =>
  48. expect(router.replace).toHaveBeenCalledWith({
  49. pathname: '/settings/org-slug/teams/new-slug/settings/',
  50. })
  51. );
  52. });
  53. it('needs team:admin in order to see an enabled Remove Team button', function () {
  54. const team = TeamFixture();
  55. const organization = OrganizationFixture({access: []});
  56. render(<TeamSettings {...routerProps} team={team} params={{teamId: team.slug}} />, {
  57. organization,
  58. router,
  59. });
  60. expect(screen.getByTestId('button-remove-team')).toBeDisabled();
  61. });
  62. it('can remove team', async function () {
  63. const team = TeamFixture({hasAccess: true});
  64. const deleteMock = MockApiClient.addMockResponse({
  65. url: `/teams/org-slug/${team.slug}/`,
  66. method: 'DELETE',
  67. });
  68. TeamStore.loadInitialData([team]);
  69. render(<TeamSettings {...routerProps} params={{teamId: team.slug}} team={team} />, {
  70. router,
  71. });
  72. // Click "Remove Team button
  73. await userEvent.click(screen.getByRole('button', {name: 'Remove Team'}));
  74. // Wait for modal
  75. renderGlobalModal({router});
  76. await userEvent.click(screen.getByTestId('confirm-button'));
  77. expect(deleteMock).toHaveBeenCalledWith(
  78. `/teams/org-slug/${team.slug}/`,
  79. expect.objectContaining({
  80. method: 'DELETE',
  81. })
  82. );
  83. await waitFor(() =>
  84. expect(router.replace).toHaveBeenCalledWith({pathname: '/settings/org-slug/teams/'})
  85. );
  86. expect(TeamStore.getAll()).toEqual([]);
  87. });
  88. it('cannot modify idp:provisioned teams regardless of role', function () {
  89. const team = TeamFixture({hasAccess: true, flags: {'idp:provisioned': true}});
  90. const organization = OrganizationFixture({access: []});
  91. render(<TeamSettings {...routerProps} team={team} params={{teamId: team.slug}} />, {
  92. organization,
  93. router,
  94. });
  95. expect(
  96. screen.getByText(
  97. "This team is managed through your organization's identity provider. These settings cannot be modified."
  98. )
  99. ).toBeInTheDocument();
  100. expect(screen.getByRole('textbox', {name: 'Team Slug'})).toBeDisabled();
  101. expect(screen.getByTestId('button-remove-team')).toBeDisabled();
  102. });
  103. });