teamDetails.spec.tsx 1.9 KB

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