projectTeamAccess.spec.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import ProjectTeamAccess from 'sentry/views/projectDetail/projectTeamAccess';
  4. describe('ProjectDetail > ProjectTeamAccess', function () {
  5. const {organization, routerContext} = initializeOrg();
  6. it('renders a list', function () {
  7. const wrapper = mountWithTheme(
  8. <ProjectTeamAccess
  9. organization={organization}
  10. project={TestStubs.Project({teams: [TestStubs.Team()]})}
  11. />,
  12. routerContext
  13. );
  14. expect(wrapper.find('SectionHeading').text()).toBe('Team Access');
  15. expect(wrapper.find('IdBadge').text()).toBe('#team-slug');
  16. expect(wrapper.find('IdBadge').length).toBe(1);
  17. });
  18. it('links to a team settings', function () {
  19. const wrapper = mountWithTheme(
  20. <ProjectTeamAccess
  21. organization={organization}
  22. project={TestStubs.Project({teams: [TestStubs.Team()]})}
  23. />,
  24. routerContext
  25. );
  26. expect(wrapper.find('StyledLink').prop('to')).toBe(
  27. '/settings/org-slug/teams/team-slug/'
  28. );
  29. });
  30. it('displays the right empty state', function () {
  31. const wrapper = mountWithTheme(
  32. <ProjectTeamAccess organization={organization} project={TestStubs.Project()} />,
  33. routerContext
  34. );
  35. const assignTeamButton = wrapper.find('Link[aria-label="Assign Team"]').at(0);
  36. expect(assignTeamButton.prop('to')).toBe(
  37. '/settings/org-slug/projects/project-slug/teams/'
  38. );
  39. expect(assignTeamButton.text()).toBe('Assign Team');
  40. const wrapperNoPermissions = mountWithTheme(
  41. <ProjectTeamAccess
  42. organization={{...organization, access: []}}
  43. project={TestStubs.Project({teams: []})}
  44. />,
  45. routerContext
  46. );
  47. expect(wrapperNoPermissions.find('Button').prop('disabled')).toBeTruthy();
  48. });
  49. it('collapses more than 5 teams', function () {
  50. const wrapper = mountWithTheme(
  51. <ProjectTeamAccess
  52. organization={organization}
  53. project={TestStubs.Project({
  54. teams: [
  55. TestStubs.Team({slug: 'team1'}),
  56. TestStubs.Team({slug: 'team2'}),
  57. TestStubs.Team({slug: 'team3'}),
  58. TestStubs.Team({slug: 'team4'}),
  59. TestStubs.Team({slug: 'team5'}),
  60. TestStubs.Team({slug: 'team6'}),
  61. TestStubs.Team({slug: 'team7'}),
  62. ],
  63. })}
  64. />,
  65. routerContext
  66. );
  67. expect(wrapper.find('IdBadge').length).toBe(5);
  68. wrapper.find('button[aria-label="Show 2 collapsed teams"]').simulate('click');
  69. expect(wrapper.find('IdBadge').length).toBe(7);
  70. wrapper.find('button[aria-label="Collapse"]').simulate('click');
  71. expect(wrapper.find('IdBadge').length).toBe(5);
  72. });
  73. it('sorts teams alphabetically', function () {
  74. const wrapper = mountWithTheme(
  75. <ProjectTeamAccess
  76. organization={organization}
  77. project={TestStubs.Project({
  78. teams: [
  79. TestStubs.Team({slug: 'c'}),
  80. TestStubs.Team({slug: 'z'}),
  81. TestStubs.Team({slug: 'a'}),
  82. ],
  83. })}
  84. />,
  85. routerContext
  86. );
  87. expect(wrapper.find('IdBadge').at(0).text()).toBe('#a');
  88. expect(wrapper.find('IdBadge').at(1).text()).toBe('#c');
  89. expect(wrapper.find('IdBadge').at(2).text()).toBe('#z');
  90. });
  91. });