noProjectMessage.spec.tsx 2.8 KB

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