index.spec.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import AlertStore from 'sentry/stores/alertStore';
  5. import OrganizationStore from 'sentry/stores/organizationStore';
  6. import PageFiltersStore from 'sentry/stores/pageFiltersStore';
  7. import ProjectsStore from 'sentry/stores/projectsStore';
  8. import OrganizationLayout from 'sentry/views/organizationLayout';
  9. jest.mock(
  10. 'sentry/components/sidebar',
  11. () =>
  12. function () {
  13. return <div />;
  14. }
  15. );
  16. describe('OrganizationLayout', function () {
  17. const {router} = initializeOrg();
  18. beforeEach(function () {
  19. OrganizationStore.reset();
  20. ProjectsStore.reset();
  21. PageFiltersStore.reset();
  22. MockApiClient.clearMockResponses();
  23. MockApiClient.addMockResponse({
  24. url: '/organizations/org-slug/broadcasts/',
  25. body: [],
  26. });
  27. MockApiClient.addMockResponse({
  28. url: '/organizations/org-slug/environments/',
  29. body: [],
  30. });
  31. });
  32. describe('deletion states', () => {
  33. it('should render a restoration prompt', async function () {
  34. const organization = OrganizationFixture({
  35. status: {
  36. id: 'pending_deletion',
  37. name: 'pending deletion',
  38. },
  39. });
  40. OrganizationStore.onUpdate(organization);
  41. render(
  42. <OrganizationLayout>
  43. <div />
  44. </OrganizationLayout>,
  45. {router, organization}
  46. );
  47. expect(await screen.findByText('Deletion Scheduled')).toBeInTheDocument();
  48. expect(screen.getByLabelText('Restore Organization')).toBeInTheDocument();
  49. expect(
  50. screen.getByText(
  51. 'Would you like to cancel this process and restore the organization back to the original state?'
  52. )
  53. ).toBeInTheDocument();
  54. });
  55. it('should render a restoration prompt without action for members', async function () {
  56. const organization = OrganizationFixture({
  57. access: [],
  58. status: {
  59. id: 'pending_deletion',
  60. name: 'pending deletion',
  61. },
  62. });
  63. OrganizationStore.onUpdate(organization);
  64. render(
  65. <OrganizationLayout>
  66. <div />
  67. </OrganizationLayout>,
  68. {router, organization}
  69. );
  70. expect(await screen.findByText('Deletion Scheduled')).toBeInTheDocument();
  71. const mistakeText = screen.getByText(
  72. 'If this is a mistake, contact an organization owner and ask them to restore this organization.'
  73. );
  74. expect(mistakeText).toBeInTheDocument();
  75. expect(screen.queryByLabelText('Restore Organization')).not.toBeInTheDocument();
  76. });
  77. });
  78. it('should render a deletion in progress prompt', async function () {
  79. const organization = OrganizationFixture({
  80. status: {
  81. id: 'deletion_in_progress',
  82. name: 'deletion in progress',
  83. },
  84. });
  85. OrganizationStore.onUpdate(organization);
  86. render(
  87. <OrganizationLayout>
  88. <div />
  89. </OrganizationLayout>,
  90. {router, organization}
  91. );
  92. const inProgress = await screen.findByText(
  93. 'currently in the process of being deleted from Sentry.',
  94. {exact: false}
  95. );
  96. expect(inProgress).toBeInTheDocument();
  97. expect(screen.queryByLabelText('Restore Organization')).not.toBeInTheDocument();
  98. });
  99. it('displays system alerts', async function () {
  100. OrganizationStore.onUpdate(OrganizationFixture());
  101. AlertStore.addAlert({
  102. id: 'abc123',
  103. message: 'Celery workers have not checked in',
  104. type: 'error',
  105. url: '/internal/health/',
  106. });
  107. render(
  108. <OrganizationLayout>
  109. <div />
  110. </OrganizationLayout>
  111. );
  112. expect(
  113. await screen.findByText(/Celery workers have not checked in/)
  114. ).toBeInTheDocument();
  115. });
  116. });