index.spec.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {textWithMarkupMatcher} from 'sentry-test/utils';
  4. import ConfigStore from 'sentry/stores/configStore';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import {Config, User} from 'sentry/types';
  7. import OrganizationAuditLog from 'sentry/views/settings/organizationAuditLog';
  8. describe('OrganizationAuditLog', function () {
  9. const user: User = {
  10. ...TestStubs.User(),
  11. options: {
  12. clock24Hours: true,
  13. timezone: 'America/Los_Angeles',
  14. },
  15. };
  16. const config: Config = {...ConfigStore.getState(), user};
  17. beforeEach(() => {
  18. ConfigStore.loadInitialData(config);
  19. });
  20. it('renders', async function () {
  21. MockApiClient.addMockResponse({
  22. url: `/organizations/org-slug/audit-logs/`,
  23. method: 'GET',
  24. body: {
  25. rows: [
  26. {
  27. id: '4500000',
  28. actor: TestStubs.User(),
  29. event: 'project.remove',
  30. ipAddress: '127.0.0.1',
  31. note: 'removed project test',
  32. targetObject: 5466660,
  33. targetUser: null,
  34. data: {},
  35. dateCreated: '2021-09-28T00:29:33.940848Z',
  36. },
  37. {
  38. id: '430000',
  39. actor: TestStubs.User(),
  40. event: 'org.create',
  41. ipAddress: '127.0.0.1',
  42. note: 'created the organization',
  43. targetObject: 54215,
  44. targetUser: null,
  45. data: {},
  46. dateCreated: '2016-11-21T04:02:45.929313Z',
  47. },
  48. ],
  49. options: TestStubs.AuditLogsApiEventNames(),
  50. },
  51. });
  52. const {routerContext, router} = initializeOrg({
  53. ...initializeOrg(),
  54. projects: [],
  55. router: {
  56. params: {orgId: 'org-slug'},
  57. },
  58. });
  59. render(<OrganizationAuditLog location={router.location} />, {
  60. context: routerContext,
  61. });
  62. expect(await screen.findByText('project.remove')).toBeInTheDocument();
  63. expect(screen.getByText('org.create')).toBeInTheDocument();
  64. expect(screen.getAllByText('127.0.0.1')).toHaveLength(2);
  65. expect(screen.getByText('17:29 PDT')).toBeInTheDocument();
  66. });
  67. it('Displays pretty dynamic sampling logs', async function () {
  68. const {routerContext, router, project, projects, organization} = initializeOrg({
  69. ...initializeOrg(),
  70. router: {
  71. params: {orgId: 'org-slug'},
  72. },
  73. });
  74. ProjectsStore.loadInitialData(projects);
  75. MockApiClient.addMockResponse({
  76. url: `/organizations/org-slug/audit-logs/`,
  77. method: 'GET',
  78. body: {
  79. rows: [
  80. {
  81. actor: TestStubs.User(),
  82. event: 'sampling_priority.enabled',
  83. ipAddress: '127.0.0.1',
  84. id: '14',
  85. note: 'enabled dynamic sampling priority "boostLatestRelease"',
  86. targetObject: 4504363022811136,
  87. targetUser: null,
  88. data: {
  89. id: project.id,
  90. name: 'boostLatestRelease',
  91. public: false,
  92. slug: project.slug,
  93. status: 0,
  94. },
  95. },
  96. {
  97. actor: TestStubs.User(),
  98. event: 'sampling_priority.disabled',
  99. ipAddress: '127.0.0.1',
  100. id: '15',
  101. note: 'disabled dynamic sampling priority "boostLatestRelease"',
  102. targetObject: 4504363022811136,
  103. targetUser: null,
  104. data: {
  105. id: project.id,
  106. name: 'boostLatestRelease',
  107. public: false,
  108. slug: project.slug,
  109. status: 0,
  110. },
  111. },
  112. ],
  113. options: TestStubs.AuditLogsApiEventNames(),
  114. },
  115. });
  116. render(<OrganizationAuditLog location={router.location} />, {
  117. context: routerContext,
  118. });
  119. // Enabled dynamic sampling priority
  120. expect(await screen.findByText('sampling_priority.enabled')).toBeInTheDocument();
  121. expect(
  122. screen.getByText(
  123. textWithMarkupMatcher(
  124. `Enabled retention priority "Prioritize new releases" in project ${project.slug}`
  125. )
  126. )
  127. ).toBeInTheDocument();
  128. // Disabled dynamic sampling priority
  129. expect(screen.getByText('sampling_priority.disabled')).toBeInTheDocument();
  130. expect(
  131. screen.getByText(
  132. textWithMarkupMatcher(
  133. `Disabled retention priority "Prioritize new releases" in project ${project.slug}`
  134. )
  135. )
  136. ).toBeInTheDocument();
  137. // Extra checks for the links to the project's settings
  138. for (const link of screen.getAllByRole('link', {name: project.slug})) {
  139. expect(link).toHaveAttribute(
  140. 'href',
  141. `/settings/${organization.slug}/projects/${project.slug}/performance/`
  142. );
  143. }
  144. });
  145. });