projectTeamAccess.spec.tsx 3.1 KB

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