withTeamsForUser.spec.jsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import ProjectActions from 'sentry/actions/projectActions';
  3. import TeamActions from 'sentry/actions/teamActions';
  4. import withTeamsForUser from 'sentry/utils/withTeamsForUser';
  5. describe('withUserTeams HoC', function () {
  6. const api = new MockApiClient();
  7. const organization = TestStubs.Organization();
  8. delete organization.projects;
  9. function Output({error, teams}) {
  10. if (error) {
  11. return <p>Error: {error.responseText}</p>;
  12. }
  13. return (
  14. <p>
  15. {teams.map(team => (
  16. <span key={team.slug}>{team.slug}</span>
  17. ))}
  18. </p>
  19. );
  20. }
  21. beforeEach(function () {
  22. MockApiClient.clearMockResponses();
  23. jest.spyOn(ProjectActions, 'loadProjects');
  24. jest.spyOn(TeamActions, 'loadTeams');
  25. });
  26. it('forwards errors', async function () {
  27. MockApiClient.addMockResponse({
  28. url: `/organizations/${organization.slug}/user-teams/`,
  29. statusCode: 400,
  30. });
  31. const Container = withTeamsForUser(Output);
  32. render(<Container organization={organization} api={api} />);
  33. expect(await screen.findByText(/Error:/)).toBeInTheDocument();
  34. });
  35. it('fetches teams and loads stores', async function () {
  36. const mockProjectA = TestStubs.Project({slug: 'a', id: '1'});
  37. const mockProjectB = TestStubs.Project({slug: 'b', id: '2'});
  38. const mockTeams = [
  39. {
  40. slug: 'sentry',
  41. projects: [mockProjectB],
  42. },
  43. {
  44. slug: 'captainplanet',
  45. projects: [mockProjectA, mockProjectB],
  46. },
  47. ];
  48. MockApiClient.addMockResponse({
  49. url: `/organizations/${organization.slug}/user-teams/`,
  50. body: mockTeams,
  51. });
  52. const Container = withTeamsForUser(Output);
  53. render(<Container organization={organization} api={api} />);
  54. expect(await screen.findByText('sentry')).toBeInTheDocument();
  55. expect(screen.getByText('captainplanet')).toBeInTheDocument();
  56. });
  57. });