ownedBy.spec.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {Group} from 'fixtures/js-stubs/group';
  2. import {Organization} from 'fixtures/js-stubs/organization';
  3. import {Project} from 'fixtures/js-stubs/project';
  4. import {Team} from 'fixtures/js-stubs/team';
  5. import {User} from 'fixtures/js-stubs/user';
  6. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  7. import {openCreateOwnershipRule} from 'sentry/actionCreators/modal';
  8. import OwnedBy from 'sentry/components/group/ownedBy';
  9. import MemberListStore from 'sentry/stores/memberListStore';
  10. import {buildTeamId, buildUserId} from 'sentry/utils';
  11. jest.mock('sentry/actionCreators/modal');
  12. describe('Group > OwnedBy', () => {
  13. it('renders unowned', () => {
  14. const group = Group();
  15. render(<OwnedBy group={group} organization={Organization()} project={Project()} />);
  16. expect(screen.getByText('No-one')).toBeInTheDocument();
  17. });
  18. it('renders team owner', () => {
  19. const team = Team();
  20. const group = Group({
  21. owners: [
  22. {
  23. date_added: new Date(),
  24. owner: buildTeamId(team.id),
  25. type: 'codeowners',
  26. },
  27. ],
  28. });
  29. render(
  30. <OwnedBy
  31. group={group}
  32. organization={Organization()}
  33. project={Project({teams: [team]})}
  34. />
  35. );
  36. expect(screen.getByText(`#${team.slug}`)).toBeInTheDocument();
  37. });
  38. it('renders member owner', () => {
  39. const user = User();
  40. MemberListStore.loadInitialData([user]);
  41. const group = Group({
  42. owners: [
  43. {
  44. date_added: new Date(),
  45. owner: buildUserId(user.id),
  46. type: 'codeowners',
  47. },
  48. ],
  49. });
  50. render(<OwnedBy group={group} organization={Organization()} project={Project()} />);
  51. expect(screen.getByText(user.name)).toBeInTheDocument();
  52. });
  53. it('does not render suspect commit', () => {
  54. const user = User();
  55. MemberListStore.loadInitialData([user]);
  56. const group = Group({
  57. owners: [
  58. {
  59. date_added: new Date(),
  60. owner: buildUserId(user.id),
  61. type: 'suspectCommit',
  62. },
  63. ],
  64. });
  65. render(<OwnedBy group={group} organization={Organization()} project={Project()} />);
  66. expect(screen.getByText('No-one')).toBeInTheDocument();
  67. });
  68. it('allows project:write to edit owners', () => {
  69. render(<OwnedBy group={Group()} organization={Organization()} project={Project()} />);
  70. userEvent.click(screen.getByLabelText('Create Ownership Rule'));
  71. expect(openCreateOwnershipRule).toHaveBeenCalledWith(
  72. expect.objectContaining({issueId: '1'})
  73. );
  74. });
  75. });