codeOwnerFileTable.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import {CodeOwnerFileTable} from './codeOwnerFileTable';
  4. describe('CodeOwnerFileTable', () => {
  5. const organization = Organization();
  6. const project = TestStubs.Project();
  7. const codeowner = TestStubs.CodeOwner();
  8. it('renders empty', () => {
  9. const {container} = render(
  10. <CodeOwnerFileTable
  11. project={project}
  12. codeowners={[]}
  13. onDelete={() => {}}
  14. onUpdate={() => {}}
  15. disabled={false}
  16. />
  17. );
  18. expect(container).toBeEmptyDOMElement();
  19. });
  20. it('renders table w/ sync & delete actions', async () => {
  21. const newCodeowner = {
  22. ...codeowner,
  23. raw: '# new codeowner rules',
  24. };
  25. const codeOwnerSyncData = {
  26. ...codeowner,
  27. raw: '# new codeowner rules',
  28. date_updated: new Date('2023-10-03'),
  29. };
  30. MockApiClient.addMockResponse({
  31. method: 'GET',
  32. url: `/organizations/${organization.slug}/code-mappings/${codeowner.codeMappingId}/codeowners/`,
  33. body: newCodeowner,
  34. });
  35. MockApiClient.addMockResponse({
  36. method: 'PUT',
  37. url: `/projects/${organization.slug}/${project.slug}/codeowners/${codeowner.id}/`,
  38. body: codeOwnerSyncData,
  39. });
  40. MockApiClient.addMockResponse({
  41. method: 'DELETE',
  42. url: `/projects/${organization.slug}/${project.slug}/codeowners/${codeowner.id}/`,
  43. body: {},
  44. });
  45. const onDelete = jest.fn();
  46. const onUpdate = jest.fn();
  47. render(
  48. <CodeOwnerFileTable
  49. project={project}
  50. codeowners={[codeowner]}
  51. onDelete={onDelete}
  52. onUpdate={onUpdate}
  53. disabled={false}
  54. />,
  55. {
  56. organization,
  57. }
  58. );
  59. expect(screen.getByText('example/repo-name')).toBeInTheDocument();
  60. await userEvent.click(screen.getByRole('button', {name: 'Actions'}));
  61. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Sync'}));
  62. await waitFor(() => {
  63. expect(onUpdate).toHaveBeenCalledWith(codeOwnerSyncData);
  64. });
  65. await userEvent.click(screen.getByRole('button', {name: 'Actions'}));
  66. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Delete'}));
  67. await waitFor(() => {
  68. expect(onDelete).toHaveBeenCalledWith(codeowner);
  69. });
  70. });
  71. });