teamDetails.spec.jsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import {Client} from 'sentry/api';
  4. import TeamStore from 'sentry/stores/teamStore';
  5. import TeamDetails from 'sentry/views/settings/organizationTeams/teamDetails';
  6. describe('TeamMembers', () => {
  7. let joinMock;
  8. const organization = TestStubs.Organization();
  9. const team = TestStubs.Team({hasAccess: false});
  10. const teamHasAccess = TestStubs.Team({id: '1337', slug: 'django', hasAccess: true});
  11. beforeEach(() => {
  12. TeamStore.init();
  13. TeamStore.loadInitialData([team, teamHasAccess]);
  14. joinMock = Client.addMockResponse({
  15. url: `/organizations/${organization.slug}/members/me/teams/${team.slug}/`,
  16. method: 'POST',
  17. });
  18. });
  19. afterEach(() => {
  20. Client.clearMockResponses();
  21. TeamStore.reset();
  22. });
  23. it('can request membership', () => {
  24. const {routerContext} = initializeOrg({
  25. organization,
  26. router: {
  27. params: {orgId: organization.slug, teamId: team.slug},
  28. },
  29. });
  30. render(
  31. <TeamDetails params={routerContext.context.router.params}>
  32. <div data-test-id="test" />
  33. </TeamDetails>,
  34. {
  35. organization,
  36. context: routerContext,
  37. }
  38. );
  39. userEvent.click(screen.getByRole('button', {name: 'Request Access'}));
  40. expect(joinMock).toHaveBeenCalled();
  41. expect(screen.queryByTestId('test')).not.toBeInTheDocument();
  42. });
  43. it('displays children', () => {
  44. const {routerContext} = initializeOrg({
  45. organization,
  46. router: {
  47. params: {orgId: organization.slug, teamId: teamHasAccess.slug},
  48. },
  49. });
  50. render(
  51. <TeamDetails params={routerContext.context.router.params}>
  52. <div data-test-id="test" />
  53. </TeamDetails>,
  54. {
  55. organization,
  56. context: routerContext,
  57. }
  58. );
  59. expect(screen.getByTestId('test')).toBeInTheDocument();
  60. });
  61. });