index.spec.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import ConfigStore from 'sentry/stores/configStore';
  4. import {Config, User} from 'sentry/types';
  5. import {OrganizationContext} from 'sentry/views/organizationContext';
  6. import OrganizationAuditLog from 'sentry/views/settings/organizationAuditLog';
  7. describe('OrganizationAuditLog', function () {
  8. const user: User = {
  9. ...TestStubs.User(),
  10. options: {
  11. clock24Hours: true,
  12. timezone: 'America/Los_Angeles',
  13. },
  14. };
  15. const config: Config = {...ConfigStore.getState(), user};
  16. beforeEach(() => {
  17. ConfigStore.loadInitialData(config);
  18. });
  19. it('renders', async function () {
  20. MockApiClient.addMockResponse({
  21. url: `/organizations/org-slug/audit-logs/`,
  22. method: 'GET',
  23. body: {
  24. rows: [
  25. {
  26. id: '4500000',
  27. actor: TestStubs.User(),
  28. event: 'project.remove',
  29. ipAddress: '127.0.0.1',
  30. note: 'removed project test',
  31. targetObject: 5466660,
  32. targetUser: null,
  33. data: {},
  34. dateCreated: '2021-09-28T00:29:33.940848Z',
  35. },
  36. {
  37. id: '430000',
  38. actor: TestStubs.User(),
  39. event: 'org.create',
  40. ipAddress: '127.0.0.1',
  41. note: 'created the organization',
  42. targetObject: 54215,
  43. targetUser: null,
  44. data: {},
  45. dateCreated: '2016-11-21T04:02:45.929313Z',
  46. },
  47. ],
  48. options: TestStubs.AuditLogsApiEventNames(),
  49. },
  50. });
  51. const {routerContext, organization, router} = initializeOrg({
  52. ...initializeOrg(),
  53. projects: [],
  54. router: {
  55. params: {orgId: 'org-slug'},
  56. },
  57. });
  58. render(
  59. <OrganizationContext.Provider value={organization}>
  60. <OrganizationAuditLog location={router.location} />
  61. </OrganizationContext.Provider>,
  62. {
  63. context: routerContext,
  64. }
  65. );
  66. expect(await screen.findByText('project.remove')).toBeInTheDocument();
  67. expect(screen.getByText('org.create')).toBeInTheDocument();
  68. expect(screen.getAllByText('127.0.0.1')).toHaveLength(2);
  69. expect(screen.getByText('17:29 PDT')).toBeInTheDocument();
  70. });
  71. });