index.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 {browserHistory} from 'sentry/utils/browserHistory';
  13. import TeamSettings from 'sentry/views/settings/organizationTeams/teamSettings';
  14. describe('TeamSettings', function () {
  15. const {routerProps} = initializeOrg();
  16. beforeEach(function () {
  17. TeamStore.reset();
  18. MockApiClient.clearMockResponses();
  19. jest.spyOn(window.location, 'assign');
  20. });
  21. afterEach(function () {
  22. jest.mocked(window.location.assign).mockRestore();
  23. });
  24. it('can change slug', async function () {
  25. const team = TeamFixture();
  26. const putMock = MockApiClient.addMockResponse({
  27. url: `/teams/org-slug/${team.slug}/`,
  28. method: 'PUT',
  29. body: {
  30. slug: 'new-slug',
  31. },
  32. });
  33. render(<TeamSettings {...routerProps} team={team} params={{teamId: team.slug}} />);
  34. const input = screen.getByRole('textbox', {name: 'Team Slug'});
  35. await userEvent.clear(input);
  36. await userEvent.type(input, 'NEW SLUG');
  37. await userEvent.click(screen.getByRole('button', {name: 'Save'}));
  38. expect(putMock).toHaveBeenCalledWith(
  39. `/teams/org-slug/${team.slug}/`,
  40. expect.objectContaining({
  41. data: {
  42. slug: 'new-slug',
  43. },
  44. })
  45. );
  46. await waitFor(() =>
  47. expect(browserHistory.replace).toHaveBeenCalledWith(
  48. '/settings/org-slug/teams/new-slug/settings/'
  49. )
  50. );
  51. });
  52. it('needs team:admin in order to see an enabled Remove Team button', function () {
  53. const team = TeamFixture();
  54. const organization = OrganizationFixture({access: []});
  55. render(<TeamSettings {...routerProps} team={team} params={{teamId: team.slug}} />, {
  56. organization,
  57. });
  58. expect(screen.getByTestId('button-remove-team')).toBeDisabled();
  59. });
  60. it('can remove team', async function () {
  61. const team = TeamFixture({hasAccess: true});
  62. const deleteMock = MockApiClient.addMockResponse({
  63. url: `/teams/org-slug/${team.slug}/`,
  64. method: 'DELETE',
  65. });
  66. TeamStore.loadInitialData([team]);
  67. render(<TeamSettings {...routerProps} params={{teamId: team.slug}} team={team} />);
  68. // Click "Remove Team button
  69. await userEvent.click(screen.getByRole('button', {name: 'Remove Team'}));
  70. // Wait for modal
  71. renderGlobalModal();
  72. await userEvent.click(screen.getByTestId('confirm-button'));
  73. expect(deleteMock).toHaveBeenCalledWith(
  74. `/teams/org-slug/${team.slug}/`,
  75. expect.objectContaining({
  76. method: 'DELETE',
  77. })
  78. );
  79. await waitFor(() =>
  80. expect(browserHistory.replace).toHaveBeenCalledWith('/settings/org-slug/teams/')
  81. );
  82. expect(TeamStore.getAll()).toEqual([]);
  83. });
  84. });