codeOwnerFileTable.spec.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. MockApiClient.addMockResponse({
  26. method: 'GET',
  27. url: `/organizations/${organization.slug}/code-mappings/${codeowner.codeMappingId}/codeowners/`,
  28. body: newCodeowner,
  29. });
  30. MockApiClient.addMockResponse({
  31. method: 'PUT',
  32. url: `/projects/${organization.slug}/${project.slug}/codeowners/${codeowner.id}/`,
  33. body: newCodeowner,
  34. });
  35. MockApiClient.addMockResponse({
  36. method: 'DELETE',
  37. url: `/projects/${organization.slug}/${project.slug}/codeowners/${codeowner.id}/`,
  38. body: {},
  39. });
  40. const onDelete = jest.fn();
  41. const onUpdate = jest.fn();
  42. render(
  43. <CodeOwnerFileTable
  44. project={project}
  45. codeowners={[codeowner]}
  46. onDelete={onDelete}
  47. onUpdate={onUpdate}
  48. disabled={false}
  49. />,
  50. {
  51. organization,
  52. }
  53. );
  54. expect(screen.getByText('example/repo-name')).toBeInTheDocument();
  55. await userEvent.click(screen.getByRole('button', {name: 'Actions'}));
  56. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Sync'}));
  57. await waitFor(() => {
  58. expect(onUpdate).toHaveBeenCalledWith(newCodeowner);
  59. });
  60. await userEvent.click(screen.getByRole('button', {name: 'Actions'}));
  61. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Delete'}));
  62. await waitFor(() => {
  63. expect(onDelete).toHaveBeenCalledWith(codeowner);
  64. });
  65. });
  66. });