index.spec.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. projects: [],
  54. router: {
  55. params: {orgId: 'org-slug'},
  56. },
  57. });
  58. render(<OrganizationAuditLog location={router.location} />, {
  59. context: routerContext,
  60. });
  61. expect(await screen.findByText('project.remove')).toBeInTheDocument();
  62. expect(screen.getByText('org.create')).toBeInTheDocument();
  63. expect(screen.getAllByText('127.0.0.1')).toHaveLength(2);
  64. expect(screen.getByText('17:29 PDT')).toBeInTheDocument();
  65. });
  66. it('Displays pretty dynamic sampling logs', async function () {
  67. const {routerContext, router, project, projects, organization} = initializeOrg({
  68. router: {
  69. params: {orgId: 'org-slug'},
  70. },
  71. });
  72. ProjectsStore.loadInitialData(projects);
  73. MockApiClient.addMockResponse({
  74. url: `/organizations/org-slug/audit-logs/`,
  75. method: 'GET',
  76. body: {
  77. rows: [
  78. {
  79. actor: TestStubs.User(),
  80. event: 'sampling_priority.enabled',
  81. ipAddress: '127.0.0.1',
  82. id: '14',
  83. note: 'enabled dynamic sampling priority "boostLatestRelease"',
  84. targetObject: 4504363022811136,
  85. targetUser: null,
  86. data: {
  87. id: project.id,
  88. name: 'boostLatestRelease',
  89. public: false,
  90. slug: project.slug,
  91. status: 0,
  92. },
  93. },
  94. {
  95. actor: TestStubs.User(),
  96. event: 'sampling_priority.disabled',
  97. ipAddress: '127.0.0.1',
  98. id: '15',
  99. note: 'disabled dynamic sampling priority "boostLatestRelease"',
  100. targetObject: 4504363022811136,
  101. targetUser: null,
  102. data: {
  103. id: project.id,
  104. name: 'boostLatestRelease',
  105. public: false,
  106. slug: project.slug,
  107. status: 0,
  108. },
  109. },
  110. ],
  111. options: TestStubs.AuditLogsApiEventNames(),
  112. },
  113. });
  114. render(<OrganizationAuditLog location={router.location} />, {
  115. context: routerContext,
  116. });
  117. // Enabled dynamic sampling priority
  118. expect(await screen.findByText('sampling_priority.enabled')).toBeInTheDocument();
  119. expect(
  120. screen.getByText(
  121. textWithMarkupMatcher(
  122. `Enabled retention priority "Prioritize new releases" in project ${project.slug}`
  123. )
  124. )
  125. ).toBeInTheDocument();
  126. // Disabled dynamic sampling priority
  127. expect(screen.getByText('sampling_priority.disabled')).toBeInTheDocument();
  128. expect(
  129. screen.getByText(
  130. textWithMarkupMatcher(
  131. `Disabled retention priority "Prioritize new releases" in project ${project.slug}`
  132. )
  133. )
  134. ).toBeInTheDocument();
  135. // Extra checks for the links to the project's settings
  136. for (const link of screen.getAllByRole('link', {name: project.slug})) {
  137. expect(link).toHaveAttribute(
  138. 'href',
  139. `/settings/${organization.slug}/projects/${project.slug}/performance/`
  140. );
  141. }
  142. });
  143. });