organizationMembershipSettingsForm.spec.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import {LocationFixture} from 'sentry-fixture/locationFixture';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import organizationMembershipSettingsFields from 'sentry/data/forms/organizationMembershipSettings';
  5. import type {Organization} from 'sentry/types/organization';
  6. import OrganizationMembershipSettingsForm from 'getsentry/hooks/organizationMembershipSettingsForm';
  7. describe('OrganizationMembershipSettings', function () {
  8. const location = LocationFixture();
  9. const getComponent = (organization: Organization) => {
  10. const access = new Set(organization.access);
  11. const jsonFormSettings = {
  12. features: new Set(organization.features),
  13. access,
  14. location,
  15. disabled: !access.has('org:write'),
  16. };
  17. return (
  18. <OrganizationMembershipSettingsForm
  19. jsonFormSettings={jsonFormSettings}
  20. forms={organizationMembershipSettingsFields}
  21. />
  22. );
  23. };
  24. it('renders alert banner and disables settings if org does not have invite-members', function () {
  25. const organization = OrganizationFixture({features: [], access: []});
  26. render(getComponent(organization), {organization});
  27. expect(
  28. screen.getByText('You must be on a paid plan to invite additional members.')
  29. ).toBeInTheDocument();
  30. expect(screen.getByRole('checkbox', {name: 'Open Team Membership'})).toBeDisabled();
  31. });
  32. it('renders alert banner and disables settings if org does not have invite-members and user has org:write access', function () {
  33. const organization = OrganizationFixture({features: [], access: ['org:write']});
  34. render(getComponent(organization), {organization});
  35. expect(
  36. screen.getByText('You must be on a paid plan to invite additional members.')
  37. ).toBeInTheDocument();
  38. expect(screen.getByRole('checkbox', {name: 'Open Team Membership'})).toBeDisabled();
  39. });
  40. it('does not render alert banner if org does not have invite-members', function () {
  41. const organization = OrganizationFixture({features: ['invite-members'], access: []});
  42. render(getComponent(organization), {organization});
  43. expect(
  44. screen.queryByText('You must be on a paid plan to invite additional members.')
  45. ).not.toBeInTheDocument();
  46. expect(screen.getByRole('checkbox', {name: 'Open Team Membership'})).toBeDisabled();
  47. });
  48. it('does not render alert banner and enables settings if org has invite-members and user has org:write access', function () {
  49. const organization = OrganizationFixture({
  50. features: ['invite-members'],
  51. access: ['org:write'],
  52. });
  53. render(getComponent(organization), {organization});
  54. expect(
  55. screen.queryByText('You must be on a paid plan to invite additional members.')
  56. ).not.toBeInTheDocument();
  57. expect(screen.getByRole('checkbox', {name: 'Open Team Membership'})).toBeEnabled();
  58. });
  59. it('disables default role selection if user does not have invite-members', function () {
  60. const organization = OrganizationFixture({
  61. features: [],
  62. access: ['org:admin'],
  63. });
  64. render(getComponent(organization), {organization});
  65. expect(screen.getByRole('textbox', {name: 'Default Role'})).toBeDisabled();
  66. });
  67. it('disables default role selection if user does not have org:admin access', function () {
  68. const organization = OrganizationFixture({
  69. features: ['invite-members'],
  70. access: ['org:write'],
  71. });
  72. render(getComponent(organization), {organization});
  73. expect(screen.getByRole('textbox', {name: 'Default Role'})).toBeDisabled();
  74. });
  75. it('enables default role selection if user does not has org:admin access', function () {
  76. const organization = OrganizationFixture({
  77. features: ['invite-members'],
  78. access: ['org:write', 'org:admin'],
  79. });
  80. render(getComponent(organization), {organization});
  81. expect(screen.getByRole('textbox', {name: 'Default Role'})).toBeEnabled();
  82. });
  83. it('disables member project creation if org does not have team-roles', function () {
  84. const organization = OrganizationFixture({
  85. features: ['invite-members'],
  86. access: ['org:write'],
  87. });
  88. render(getComponent(organization), {organization});
  89. expect(
  90. screen.getByRole('checkbox', {name: 'Let Members Create Projects'})
  91. ).toBeDisabled();
  92. });
  93. it('enables member project creation if org has team-roles', function () {
  94. const organization = OrganizationFixture({
  95. features: ['invite-members', 'team-roles'],
  96. access: ['org:write'],
  97. });
  98. render(getComponent(organization), {organization});
  99. expect(
  100. screen.getByRole('checkbox', {name: 'Let Members Create Projects'})
  101. ).toBeEnabled();
  102. });
  103. it('disables member project creation if user does not have org:write access', function () {
  104. const organization = OrganizationFixture({
  105. features: ['invite-members', 'team-roles'],
  106. access: [],
  107. });
  108. render(getComponent(organization), {organization});
  109. expect(
  110. screen.getByRole('checkbox', {name: 'Let Members Create Projects'})
  111. ).toBeDisabled();
  112. });
  113. });