index.spec.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import ProjectsStore from 'sentry/stores/projectsStore';
  3. import TeamStore from 'sentry/stores/teamStore';
  4. import TeamInsightsContainer from 'sentry/views/organizationStats/teamInsights';
  5. describe('TeamInsightsContainer', () => {
  6. afterEach(() => {
  7. ProjectsStore.reset();
  8. });
  9. it('blocks access if org is missing flag', () => {
  10. const organization = TestStubs.Organization();
  11. const context = TestStubs.routerContext([{organization}]);
  12. render(
  13. <TeamInsightsContainer organization={organization}>
  14. <div>test</div>
  15. </TeamInsightsContainer>,
  16. {context}
  17. );
  18. expect(screen.queryByText('test')).not.toBeInTheDocument();
  19. });
  20. it('allows access for orgs with flag', () => {
  21. ProjectsStore.loadInitialData([TestStubs.Project()]);
  22. const team = TestStubs.Team({slug: 'team-slug', isMember: true});
  23. TeamStore.loadInitialData([{...team, access: ['team:read']}]);
  24. const organization = TestStubs.Organization({features: ['team-insights']});
  25. const context = TestStubs.routerContext([{organization}]);
  26. render(
  27. <TeamInsightsContainer organization={organization}>
  28. <div>test</div>
  29. </TeamInsightsContainer>,
  30. {context}
  31. );
  32. expect(screen.getByText('test')).toBeInTheDocument();
  33. });
  34. it('shows message for users with no teams', () => {
  35. ProjectsStore.loadInitialData([]);
  36. const organization = TestStubs.Organization({features: ['team-insights']});
  37. const context = TestStubs.routerContext([{organization}]);
  38. render(<TeamInsightsContainer organization={organization} />, {context});
  39. expect(
  40. screen.getByText('You need at least one project to use this view')
  41. ).toBeInTheDocument();
  42. });
  43. });