codeOwnerFileTable.spec.tsx 2.1 KB

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