teamSettings.spec.jsx 3.2 KB

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