teamDetails.spec.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 {routerContext} = initializeOrg({
  24. organization,
  25. router: {
  26. params: {orgId: organization.slug, teamId: team.slug},
  27. },
  28. });
  29. render(
  30. <TeamDetails
  31. params={routerContext.context.router.params}
  32. route={routerContext.context.router.routes[0]}
  33. routes={routerContext.context.router.routes}
  34. router={routerContext.context.router}
  35. location={routerContext.context.router.location}
  36. routeParams={routerContext.context.router.routeParams}
  37. >
  38. <div data-test-id="test" />
  39. </TeamDetails>,
  40. {
  41. organization,
  42. context: routerContext,
  43. }
  44. );
  45. await userEvent.click(screen.getByRole('button', {name: 'Request Access'}));
  46. expect(joinMock).toHaveBeenCalled();
  47. expect(screen.queryByTestId('test')).not.toBeInTheDocument();
  48. });
  49. it('displays children', () => {
  50. const {routerContext} = initializeOrg({
  51. organization,
  52. router: {
  53. params: {orgId: organization.slug, teamId: teamHasAccess.slug},
  54. },
  55. });
  56. render(
  57. <TeamDetails
  58. params={routerContext.context.router.params}
  59. route={routerContext.context.router.routes[0]}
  60. routes={routerContext.context.router.routes}
  61. router={routerContext.context.router}
  62. location={routerContext.context.router.location}
  63. routeParams={routerContext.context.router.routeParams}
  64. >
  65. <div data-test-id="test" />
  66. </TeamDetails>,
  67. {
  68. organization,
  69. context: routerContext,
  70. }
  71. );
  72. expect(screen.getByTestId('test')).toBeInTheDocument();
  73. });
  74. });