teamDetails.spec.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  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 = 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 = MockApiClient.addMockResponse({
  15. url: `/organizations/${organization.slug}/members/me/teams/${team.slug}/`,
  16. method: 'POST',
  17. });
  18. });
  19. afterEach(() => {
  20. MockApiClient.clearMockResponses();
  21. TeamStore.reset();
  22. });
  23. it('can request membership', async () => {
  24. const {routerProps, routerContext} = initializeOrg({
  25. organization,
  26. router: {
  27. params: {orgId: organization.slug, teamId: team.slug},
  28. },
  29. });
  30. render(
  31. <TeamDetails {...routerProps}>
  32. <div data-test-id="test" />
  33. </TeamDetails>,
  34. {organization, context: routerContext}
  35. );
  36. await userEvent.click(screen.getByRole('button', {name: 'Request Access'}));
  37. expect(joinMock).toHaveBeenCalled();
  38. expect(screen.queryByTestId('test')).not.toBeInTheDocument();
  39. });
  40. it('displays children', () => {
  41. const {routerContext, routerProps} = initializeOrg({
  42. organization,
  43. router: {
  44. params: {orgId: organization.slug, teamId: teamHasAccess.slug},
  45. },
  46. });
  47. render(
  48. <TeamDetails {...routerProps}>
  49. <div data-test-id="test" />
  50. </TeamDetails>,
  51. {organization, context: routerContext}
  52. );
  53. expect(screen.getByTestId('test')).toBeInTheDocument();
  54. });
  55. });