auditLogView.spec.jsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {Client} from 'sentry/api';
  4. import OrganizationAuditLog from 'sentry/views/settings/organizationAuditLog';
  5. describe('OrganizationAuditLog', () => {
  6. const {routerContext, org} = initializeOrg({
  7. projects: [],
  8. router: {
  9. params: {orgId: 'org-slug'},
  10. },
  11. });
  12. const ENDPOINT = `/organizations/${org.slug}/audit-logs/`;
  13. const mockLocation = {query: {}};
  14. beforeEach(function () {
  15. Client.clearMockResponses();
  16. Client.addMockResponse({
  17. url: ENDPOINT,
  18. body: {rows: TestStubs.AuditLogs(), options: TestStubs.AuditLogsApiEventNames()},
  19. });
  20. });
  21. it('renders', async () => {
  22. render(
  23. <OrganizationAuditLog
  24. location={mockLocation}
  25. organization={org}
  26. params={{orgId: org.slug}}
  27. />,
  28. {
  29. context: routerContext,
  30. }
  31. );
  32. expect(await screen.findByRole('heading')).toHaveTextContent('Audit Log');
  33. expect(screen.getByRole('textbox')).toBeInTheDocument();
  34. expect(screen.getByText('Member')).toBeInTheDocument();
  35. expect(screen.getByText('Action')).toBeInTheDocument();
  36. expect(screen.getByText('IP')).toBeInTheDocument();
  37. expect(screen.getByText('Time')).toBeInTheDocument();
  38. expect(screen.queryByText('No audit entries available')).not.toBeInTheDocument();
  39. expect(screen.getByText('edited project ludic-science')).toBeInTheDocument();
  40. });
  41. it('renders empty', async () => {
  42. Client.clearMockResponses();
  43. Client.addMockResponse({
  44. url: ENDPOINT,
  45. body: {rows: [], options: TestStubs.AuditLogsApiEventNames()},
  46. });
  47. render(
  48. <OrganizationAuditLog
  49. location={mockLocation}
  50. organization={org}
  51. params={{orgId: org.slug}}
  52. />,
  53. {
  54. context: routerContext,
  55. }
  56. );
  57. expect(await screen.findByText('No audit entries available')).toBeInTheDocument();
  58. });
  59. it('displays whether an action was done by a superuser', async () => {
  60. render(
  61. <OrganizationAuditLog
  62. location={mockLocation}
  63. organization={org}
  64. params={{orgId: org.slug}}
  65. />,
  66. {
  67. context: routerContext,
  68. }
  69. );
  70. expect(await screen.findByText('Sentry Staff')).toBeInTheDocument();
  71. expect(screen.getAllByText('Foo Bar')).toHaveLength(2);
  72. });
  73. });