teamSettings.spec.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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
  22. team={team}
  23. onTeamChange={() => {}}
  24. params={{orgId: 'org', teamId: team.slug}}
  25. />
  26. );
  27. wrapper
  28. .find('input[name="slug"]')
  29. .simulate('change', {target: {value: 'NEW SLUG'}})
  30. .simulate('blur');
  31. wrapper.find('button[aria-label="Save"]').simulate('click');
  32. expect(putMock).toHaveBeenCalledWith(
  33. `/teams/org/${team.slug}/`,
  34. expect.objectContaining({
  35. data: {
  36. slug: 'new-slug',
  37. },
  38. })
  39. );
  40. await tick();
  41. expect(browserHistory.replace).toHaveBeenCalledWith(
  42. '/settings/org/teams/new-slug/settings/'
  43. );
  44. });
  45. it('needs team:admin in order to see an enabled Remove Team button', function () {
  46. const team = TestStubs.Team();
  47. const wrapper = mountWithTheme(
  48. <TeamSettings
  49. team={team}
  50. onTeamChange={() => {}}
  51. params={{orgId: 'org', teamId: team.slug}}
  52. />,
  53. TestStubs.routerContext([
  54. {
  55. organization: TestStubs.Organization({access: []}),
  56. },
  57. ])
  58. );
  59. expect(wrapper.find('Panel').last().find('Button').prop('disabled')).toBe(true);
  60. });
  61. it('can remove team', async function () {
  62. const team = TestStubs.Team({hasAccess: true});
  63. const deleteMock = MockApiClient.addMockResponse({
  64. url: `/teams/org/${team.slug}/`,
  65. method: 'DELETE',
  66. });
  67. jest.spyOn(TeamStore, 'trigger');
  68. TeamStore.loadInitialData([
  69. {
  70. slug: 'team-slug',
  71. hasAccess: true,
  72. },
  73. ]);
  74. const wrapper = mountWithTheme(
  75. <TeamSettings
  76. params={{orgId: 'org', teamId: team.slug}}
  77. team={team}
  78. onTeamChange={() => {}}
  79. />
  80. );
  81. // Click "Remove Team button
  82. wrapper.find('Button[priority="danger"] button').simulate('click');
  83. TeamStore.trigger.mockReset();
  84. // Wait for modal
  85. const modal = await mountGlobalModal();
  86. modal.find('Button[priority="danger"] button').simulate('click');
  87. expect(deleteMock).toHaveBeenCalledWith(
  88. `/teams/org/${team.slug}/`,
  89. expect.objectContaining({
  90. method: 'DELETE',
  91. })
  92. );
  93. await tick();
  94. await tick();
  95. expect(browserHistory.replace).toHaveBeenCalledWith('/settings/org/teams/');
  96. expect(TeamStore.getAll()).toEqual([]);
  97. TeamStore.trigger.mockRestore();
  98. });
  99. });