index.spec.tsx 4.7 KB

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