teamDetails.spec.jsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {Client} from 'sentry/api';
  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. const context = TestStubs.routerContext();
  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. render(
  25. <TeamDetails params={{orgId: organization.slug, teamId: team.slug}}>
  26. <div data-test-id="test" />
  27. </TeamDetails>,
  28. {
  29. organization,
  30. context,
  31. }
  32. );
  33. userEvent.click(screen.getByRole('button', {name: 'Request Access'}));
  34. expect(joinMock).toHaveBeenCalled();
  35. expect(screen.queryByTestId('test')).not.toBeInTheDocument();
  36. });
  37. it('displays children', () => {
  38. render(
  39. <TeamDetails params={{orgId: organization.slug, teamId: teamHasAccess.slug}}>
  40. <div data-test-id="test" />
  41. </TeamDetails>,
  42. {
  43. organization,
  44. context,
  45. }
  46. );
  47. expect(screen.getByTestId('test')).toBeInTheDocument();
  48. });
  49. });