noProjectMessage.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {Organization} from 'fixtures/js-stubs/organization';
  2. import {Project} from 'fixtures/js-stubs/project';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import NoProjectMessage from 'sentry/components/noProjectMessage';
  5. import ConfigStore from 'sentry/stores/configStore';
  6. import ProjectsStore from 'sentry/stores/projectsStore';
  7. describe('NoProjectMessage', function () {
  8. beforeEach(function () {
  9. ProjectsStore.reset();
  10. });
  11. const org = Organization();
  12. it('renders', function () {
  13. const organization = Organization({slug: 'org-slug'});
  14. const childrenMock = jest.fn().mockReturnValue(null);
  15. delete organization.projects;
  16. ProjectsStore.loadInitialData([]);
  17. render(
  18. <NoProjectMessage organization={organization}>{childrenMock}</NoProjectMessage>
  19. );
  20. expect(childrenMock).not.toHaveBeenCalled();
  21. expect(screen.getByText('Remain Calm')).toBeInTheDocument();
  22. });
  23. it('shows "Create Project" button when there are no projects', function () {
  24. ProjectsStore.loadInitialData([]);
  25. render(<NoProjectMessage organization={org} />);
  26. expect(screen.getByRole('button', {name: 'Create project'})).toBeInTheDocument();
  27. });
  28. it('"Create Project" is disabled when no access to `project:write`', function () {
  29. ProjectsStore.loadInitialData([]);
  30. render(<NoProjectMessage organization={Organization({access: []})} />);
  31. expect(screen.getByRole('button', {name: 'Create project'})).toBeDisabled();
  32. });
  33. it('has no "Join a Team" button when projects are missing', function () {
  34. ProjectsStore.loadInitialData([]);
  35. render(<NoProjectMessage organization={org} />);
  36. expect(screen.queryByRole('button', {name: 'Join a Team'})).not.toBeInTheDocument();
  37. expect(screen.getByRole('button', {name: 'Create project'})).toBeInTheDocument();
  38. });
  39. it('has a "Join a Team" button when no projects but org has projects', function () {
  40. ProjectsStore.loadInitialData([Project({hasAccess: false})]);
  41. render(<NoProjectMessage organization={org} />);
  42. expect(screen.getByRole('button', {name: 'Join a Team'})).toBeInTheDocument();
  43. });
  44. it('has a disabled "Join a Team" button if no access to `team:read`', function () {
  45. ProjectsStore.loadInitialData([Project({hasAccess: false})]);
  46. render(<NoProjectMessage organization={{...org, access: []}} />);
  47. expect(screen.getByRole('button', {name: 'Join a Team'})).toBeDisabled();
  48. });
  49. it('shows empty message to superusers that are not members', function () {
  50. ProjectsStore.loadInitialData([Project({hasAccess: true, isMember: false})]);
  51. ConfigStore.set('user', {...ConfigStore.get('user'), isSuperuser: true});
  52. render(
  53. <NoProjectMessage organization={org} superuserNeedsToBeProjectMember>
  54. {null}
  55. </NoProjectMessage>
  56. );
  57. expect(
  58. screen.getByText('You need at least one project to use this view')
  59. ).toBeInTheDocument();
  60. });
  61. });