teamSettings.spec.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import TeamStore from 'app/stores/teamStore';
  4. import TeamSettings from 'app/views/settings/organizationTeams/teamSettings';
  5. describe('TeamSettings', function() {
  6. beforeEach(function() {
  7. MockApiClient.clearMockResponses();
  8. jest.spyOn(window.location, 'assign');
  9. });
  10. afterEach(function() {
  11. window.location.assign.mockRestore();
  12. });
  13. it('can change name and slug', async function() {
  14. const team = TestStubs.Team();
  15. const putMock = MockApiClient.addMockResponse({
  16. url: `/teams/org/${team.slug}/`,
  17. method: 'PUT',
  18. });
  19. const mountOptions = TestStubs.routerContext();
  20. const {router} = mountOptions.context;
  21. const wrapper = mountWithTheme(
  22. <TeamSettings
  23. routes={[]}
  24. router={router}
  25. params={{orgId: 'org', teamId: team.slug}}
  26. team={team}
  27. onTeamChange={() => {}}
  28. />,
  29. mountOptions
  30. );
  31. wrapper
  32. .find('input[name="name"]')
  33. .simulate('change', {target: {value: 'New Name'}})
  34. .simulate('blur');
  35. expect(putMock).toHaveBeenCalledWith(
  36. `/teams/org/${team.slug}/`,
  37. expect.objectContaining({
  38. data: {
  39. name: 'New Name',
  40. },
  41. })
  42. );
  43. wrapper
  44. .find('input[name="slug"]')
  45. .simulate('change', {target: {value: 'NEW SLUG'}})
  46. .simulate('blur');
  47. wrapper.find('SaveButton').simulate('click');
  48. expect(putMock).toHaveBeenCalledWith(
  49. `/teams/org/${team.slug}/`,
  50. expect.objectContaining({
  51. data: {
  52. slug: 'new-slug',
  53. },
  54. })
  55. );
  56. await tick();
  57. expect(router.replace).toHaveBeenCalledWith('/settings/org/teams/new-slug/settings/');
  58. });
  59. it('needs team:admin in order to see an enabled Remove Team button', function() {
  60. const team = TestStubs.Team();
  61. const wrapper = mountWithTheme(
  62. <TeamSettings
  63. routes={[]}
  64. params={{orgId: 'org', teamId: team.slug}}
  65. team={team}
  66. onTeamChange={() => {}}
  67. />,
  68. TestStubs.routerContext([{organization: TestStubs.Organization({access: []})}])
  69. );
  70. expect(
  71. wrapper
  72. .find('Panel')
  73. .last()
  74. .find('Button')
  75. .prop('disabled')
  76. ).toBe(true);
  77. });
  78. it('can remove team', async function() {
  79. const team = TestStubs.Team({hasAccess: true});
  80. const deleteMock = MockApiClient.addMockResponse({
  81. url: `/teams/org/${team.slug}/`,
  82. method: 'DELETE',
  83. });
  84. const routerPushMock = jest.fn();
  85. jest.spyOn(TeamStore, 'trigger');
  86. TeamStore.loadInitialData([
  87. {
  88. slug: 'team-slug',
  89. hasAccess: true,
  90. },
  91. ]);
  92. const wrapper = mountWithTheme(
  93. <TeamSettings
  94. router={{replace: routerPushMock}}
  95. routes={[]}
  96. params={{orgId: 'org', teamId: team.slug}}
  97. team={team}
  98. onTeamChange={() => {}}
  99. />,
  100. TestStubs.routerContext()
  101. );
  102. // Click "Remove Team button
  103. wrapper.find('Button[priority="danger"] button').simulate('click');
  104. TeamStore.trigger.mockReset();
  105. // Wait for modal
  106. wrapper.find('ModalDialog Button[priority="danger"] button').simulate('click');
  107. expect(deleteMock).toHaveBeenCalledWith(
  108. `/teams/org/${team.slug}/`,
  109. expect.objectContaining({
  110. method: 'DELETE',
  111. })
  112. );
  113. await tick();
  114. await tick();
  115. expect(routerPushMock).toHaveBeenCalledWith('/settings/org/teams/');
  116. expect(TeamStore.items).toEqual([]);
  117. TeamStore.trigger.mockRestore();
  118. });
  119. });