projectsTable.spec.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import type {ProjectionSamplePeriod} from 'sentry/views/settings/dynamicSampling/utils/useProjectSampleCounts';
  5. import {ProjectsTable} from './projectsTable';
  6. describe('ProjectsTable', () => {
  7. const organization = OrganizationFixture({
  8. access: ['org:write'],
  9. });
  10. const project = ProjectFixture();
  11. const defaultProps = {
  12. items: [
  13. {
  14. project,
  15. count: 1000,
  16. ownCount: 800,
  17. sampleRate: '10',
  18. initialSampleRate: '10',
  19. subProjects: [],
  20. },
  21. ],
  22. period: '24h' as ProjectionSamplePeriod,
  23. rateHeader: 'Sample Rate',
  24. isLoading: false,
  25. emptyMessage: 'No projects found',
  26. };
  27. it('disables input when user does not have access', () => {
  28. const orgWithoutAccess = OrganizationFixture({
  29. access: [], // No org:write access
  30. });
  31. render(<ProjectsTable {...defaultProps} canEdit />, {
  32. organization: orgWithoutAccess,
  33. });
  34. expect(screen.getByRole('spinbutton')).toBeDisabled();
  35. });
  36. it('enables input when user has access and canEdit is true', () => {
  37. render(<ProjectsTable {...defaultProps} canEdit />, {
  38. organization,
  39. });
  40. expect(screen.getByRole('spinbutton')).toBeEnabled();
  41. });
  42. it('disables input when canEdit is false, regardless of access', () => {
  43. render(<ProjectsTable {...defaultProps} canEdit={false} />, {
  44. organization,
  45. });
  46. expect(screen.getByRole('spinbutton')).toBeDisabled();
  47. });
  48. it('does not show settings button when user does not have project:write access', () => {
  49. render(<ProjectsTable {...defaultProps} />, {
  50. organization,
  51. });
  52. expect(
  53. screen.queryByRole('button', {name: 'Open Project Settings'})
  54. ).not.toBeInTheDocument();
  55. });
  56. it('shows settings button only when user has project:write access', () => {
  57. const orgWithProjectAccess = OrganizationFixture({
  58. access: ['org:write', 'project:write'],
  59. });
  60. render(<ProjectsTable {...defaultProps} />, {
  61. organization: orgWithProjectAccess,
  62. });
  63. expect(
  64. screen.getByRole('button', {name: 'Open Project Settings'})
  65. ).toBeInTheDocument();
  66. });
  67. });