teamSettings.spec.jsx 2.9 KB

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