teamMembers.spec.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React from 'react';
  2. import {Client} from 'app/api';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {mountWithTheme} from 'sentry-test/enzyme';
  5. import TeamMembers from 'app/views/settings/organizationTeams/teamMembers';
  6. describe('TeamMembers', function() {
  7. const {organization, routerContext} = initializeOrg();
  8. const team = TestStubs.Team();
  9. const members = TestStubs.Members();
  10. beforeEach(function() {
  11. Client.clearMockResponses();
  12. Client.addMockResponse({
  13. url: `/organizations/${organization.slug}/members/`,
  14. method: 'GET',
  15. body: members,
  16. });
  17. Client.addMockResponse({
  18. url: `/teams/${organization.slug}/${team.slug}/members/`,
  19. method: 'GET',
  20. body: members,
  21. });
  22. });
  23. it('renders', async function() {
  24. const wrapper = mountWithTheme(
  25. <TeamMembers
  26. params={{orgId: organization.slug, teamId: team.slug}}
  27. organization={organization}
  28. />,
  29. routerContext
  30. );
  31. await tick();
  32. wrapper.update();
  33. });
  34. it('can remove member from team', async function() {
  35. const endpoint = `/organizations/${organization.slug}/members/${
  36. members[0].id
  37. }/teams/${team.slug}/`;
  38. const mock = Client.addMockResponse({
  39. url: endpoint,
  40. method: 'DELETE',
  41. statusCode: 200,
  42. });
  43. const wrapper = mountWithTheme(
  44. <TeamMembers
  45. params={{orgId: organization.slug, teamId: team.slug}}
  46. organization={organization}
  47. />,
  48. routerContext
  49. );
  50. await tick();
  51. wrapper.update();
  52. expect(mock).not.toHaveBeenCalled();
  53. wrapper
  54. .find('Button')
  55. .at(1)
  56. .simulate('click');
  57. expect(mock).toHaveBeenCalledWith(
  58. endpoint,
  59. expect.objectContaining({
  60. method: 'DELETE',
  61. })
  62. );
  63. });
  64. it('can only remove self from team', async function() {
  65. const me = TestStubs.Member({
  66. id: '123',
  67. email: 'foo@example.com',
  68. });
  69. Client.addMockResponse({
  70. url: `/teams/${organization.slug}/${team.slug}/members/`,
  71. method: 'GET',
  72. body: [...members, me],
  73. });
  74. const endpoint = `/organizations/${organization.slug}/members/${me.id}/teams/${
  75. team.slug
  76. }/`;
  77. const mock = Client.addMockResponse({
  78. url: endpoint,
  79. method: 'DELETE',
  80. statusCode: 200,
  81. });
  82. const organizationMember = TestStubs.Organization({
  83. access: [],
  84. });
  85. const wrapper = mountWithTheme(
  86. <TeamMembers
  87. params={{orgId: organization.slug, teamId: team.slug}}
  88. organization={organizationMember}
  89. />,
  90. routerContext
  91. );
  92. await tick();
  93. wrapper.update();
  94. expect(mock).not.toHaveBeenCalled();
  95. expect(wrapper.find('IdBadge')).toHaveLength(members.length + 1);
  96. // Can only remove self
  97. expect(wrapper.find('button[aria-label="Remove"]')).toHaveLength(1);
  98. wrapper.find('button[aria-label="Remove"]').simulate('click');
  99. expect(mock).toHaveBeenCalledWith(
  100. endpoint,
  101. expect.objectContaining({
  102. method: 'DELETE',
  103. })
  104. );
  105. });
  106. });