projectTeamAccess.spec.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  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. render(
  8. <ProjectTeamAccess
  9. organization={organization}
  10. project={TestStubs.Project({teams: [TestStubs.Team()]})}
  11. />,
  12. {context: routerContext}
  13. );
  14. expect(screen.getByText('Team Access')).toBeInTheDocument();
  15. expect(screen.getByText('#team-slug')).toBeInTheDocument();
  16. });
  17. it('links to a team settings', function () {
  18. render(
  19. <ProjectTeamAccess
  20. organization={organization}
  21. project={TestStubs.Project({teams: [TestStubs.Team()]})}
  22. />,
  23. {context: routerContext}
  24. );
  25. expect(screen.getByRole('link', {name: '#team-slug'})).toHaveAttribute(
  26. 'href',
  27. '/settings/org-slug/teams/team-slug/'
  28. );
  29. });
  30. it('display the right empty state with access', function () {
  31. render(
  32. <ProjectTeamAccess organization={organization} project={TestStubs.Project()} />,
  33. {context: routerContext}
  34. );
  35. expect(screen.getByRole('button', {name: 'Assign Team'})).toHaveAttribute(
  36. 'href',
  37. '/settings/org-slug/projects/project-slug/teams/'
  38. );
  39. });
  40. it('display the right empty state without access', function () {
  41. render(
  42. <ProjectTeamAccess
  43. organization={{...organization, access: []}}
  44. project={TestStubs.Project({teams: []})}
  45. />,
  46. {context: routerContext}
  47. );
  48. expect(screen.getByRole('button', {name: 'Assign Team'})).toBeDisabled();
  49. });
  50. it('collapses more than 5 teams', function () {
  51. render(
  52. <ProjectTeamAccess
  53. organization={organization}
  54. project={TestStubs.Project({
  55. teams: [
  56. TestStubs.Team({slug: 'team1'}),
  57. TestStubs.Team({slug: 'team2'}),
  58. TestStubs.Team({slug: 'team3'}),
  59. TestStubs.Team({slug: 'team4'}),
  60. TestStubs.Team({slug: 'team5'}),
  61. TestStubs.Team({slug: 'team6'}),
  62. TestStubs.Team({slug: 'team7'}),
  63. ],
  64. })}
  65. />,
  66. {context: routerContext}
  67. );
  68. expect(screen.getAllByTestId('badge-display-name')).toHaveLength(5);
  69. userEvent.click(screen.getByRole('button', {name: 'Show 2 collapsed teams'}));
  70. expect(screen.getAllByTestId('badge-display-name')).toHaveLength(7);
  71. userEvent.click(screen.getByRole('button', {name: 'Collapse'}));
  72. expect(screen.getAllByTestId('badge-display-name')).toHaveLength(5);
  73. });
  74. it('sorts teams alphabetically', function () {
  75. render(
  76. <ProjectTeamAccess
  77. organization={organization}
  78. project={TestStubs.Project({
  79. teams: [
  80. TestStubs.Team({slug: 'c'}),
  81. TestStubs.Team({slug: 'z'}),
  82. TestStubs.Team({slug: 'a'}),
  83. ],
  84. })}
  85. />,
  86. {context: routerContext}
  87. );
  88. const badges = screen.getAllByTestId('badge-display-name');
  89. expect(badges[0]).toHaveTextContent('#a');
  90. expect(badges[1]).toHaveTextContent('#c');
  91. expect(badges[2]).toHaveTextContent('#z');
  92. });
  93. });