organizationTeams.spec.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import React from 'react';
  2. import {initializeOrg} from 'app-test/helpers/initializeOrg';
  3. import {mount} from 'enzyme';
  4. import {openCreateTeamModal} from 'app/actionCreators/modal';
  5. import OrganizationTeams from 'app/views/settings/organizationTeams/organizationTeams';
  6. import recreateRoute from 'app/utils/recreateRoute';
  7. recreateRoute.mockReturnValue('');
  8. jest.mock('app/actionCreators/modal', () => ({
  9. openCreateTeamModal: jest.fn(),
  10. }));
  11. describe('OrganizationTeams', function() {
  12. beforeEach(function() {
  13. MockApiClient.addMockResponse({
  14. url: '/organizations/org-slug/stats/',
  15. body: [],
  16. });
  17. });
  18. describe('Open Membership', function() {
  19. const {organization, project, routerContext} = initializeOrg({
  20. organization: {
  21. openMembership: true,
  22. },
  23. });
  24. const teams = [TestStubs.Team()];
  25. const createWrapper = props =>
  26. mount(
  27. <OrganizationTeams
  28. params={{orgId: organization.slug, projectId: project.slug}}
  29. routes={[]}
  30. features={new Set(['open-membership'])}
  31. access={new Set(['project:admin'])}
  32. allTeams={teams}
  33. activeTeams={[]}
  34. organization={organization}
  35. {...props}
  36. />,
  37. routerContext
  38. );
  39. it('opens "create team modal" when creating a new team from header', async function() {
  40. const wrapper = createWrapper();
  41. // Click "Create Team" in Panel Header
  42. wrapper.find('SettingsPageHeading Button').simulate('click');
  43. // action creator to open "create team modal" is called
  44. expect(openCreateTeamModal).toHaveBeenCalledWith(
  45. expect.objectContaining({
  46. organization: expect.objectContaining({
  47. slug: organization.slug,
  48. }),
  49. })
  50. );
  51. });
  52. it('can join team and have link to details', function() {
  53. const wrapper = createWrapper({
  54. allTeams: [TestStubs.Team({hasAccess: true, isMember: false})],
  55. access: new Set([]),
  56. });
  57. expect(wrapper.find('button[aria-label="Join Team"]')).toHaveLength(1);
  58. // Should also link to details
  59. expect(wrapper.find('Link')).toHaveLength(1);
  60. });
  61. });
  62. describe('Closed Membership', function() {
  63. const {organization, project, routerContext} = initializeOrg({
  64. organization: {
  65. openMembership: false,
  66. },
  67. });
  68. const createWrapper = props =>
  69. mount(
  70. <OrganizationTeams
  71. params={{orgId: organization.slug, projectId: project.slug}}
  72. routes={[]}
  73. features={new Set([])}
  74. access={new Set([])}
  75. allTeams={[]}
  76. activeTeams={[]}
  77. organization={organization}
  78. {...props}
  79. />,
  80. routerContext
  81. );
  82. it('can request access to team and does not have link to details', function() {
  83. const wrapper = createWrapper({
  84. allTeams: [TestStubs.Team({hasAccess: false, isMember: false})],
  85. access: new Set([]),
  86. });
  87. expect(wrapper.find('button[aria-label="Request Access"]')).toHaveLength(1);
  88. // Should also not link to details because of lack of access
  89. expect(wrapper.find('Link')).toHaveLength(0);
  90. });
  91. it('can leave team when you are a member', function() {
  92. const wrapper = createWrapper({
  93. allTeams: [TestStubs.Team({hasAccess: true, isMember: true})],
  94. access: new Set([]),
  95. });
  96. expect(wrapper.find('button[aria-label="Leave Team"]')).toHaveLength(1);
  97. });
  98. });
  99. });