teamDetails.spec.tsx 1.8 KB

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