index.spec.jsx 2.6 KB

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