index.spec.tsx 4.8 KB

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