ownedBy.spec.tsx 2.6 KB

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