index.spec.tsx 4.8 KB

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