remove-managed-user-modal.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import RemoveManagedUserModal from '@/features/group-management/components/members-table/remove-managed-user-modal'
  2. import sinon from 'sinon'
  3. describe('RemoveManagedUserModal', function () {
  4. describe('happy path', function () {
  5. const groupId = 'some-group'
  6. const user = {
  7. _id: 'some-user',
  8. email: 'some.user@example.com',
  9. first_name: 'Some',
  10. last_name: 'User',
  11. invite: true,
  12. last_active_at: new Date(),
  13. enrollment: {
  14. managedBy: `${groupId}`,
  15. enrolledAt: new Date(),
  16. },
  17. isEntityAdmin: undefined,
  18. }
  19. beforeEach(function () {
  20. cy.mount(
  21. <RemoveManagedUserModal
  22. user={user}
  23. groupId={groupId}
  24. onClose={sinon.stub()}
  25. />
  26. )
  27. })
  28. it('should render the modal', function () {
  29. cy.findByTestId('release-user-form')
  30. })
  31. it('should render content', function () {
  32. cy.findByText(
  33. `You’re about to remove ${user.first_name} ${user.last_name} (${user.email}). Doing this will mean:`
  34. )
  35. cy.findAllByRole('listitem')
  36. .eq(0)
  37. .contains(/they will be removed from the group/i)
  38. cy.findAllByRole('listitem')
  39. .eq(1)
  40. .contains(/they will no longer be a managed user/i)
  41. cy.findAllByRole('listitem')
  42. .eq(2)
  43. .contains(
  44. /they will retain their existing account on the .* free plan/i
  45. )
  46. cy.findAllByRole('listitem')
  47. .eq(3)
  48. .contains(
  49. /they will retain ownership of projects currently owned by them and any collaborators on those projects will become read-only/i
  50. )
  51. cy.findAllByRole('listitem')
  52. .eq(4)
  53. .contains(
  54. /they will continue to have access to any projects shared with them/i
  55. )
  56. cy.findAllByRole('listitem')
  57. .eq(5)
  58. .contains(
  59. /they won’t be able to log in with SSO \(if you have this enabled\)\. they will need to set an .* password/i
  60. )
  61. cy.contains(
  62. /in cases where a user has left your organization and you need to transfer their projects, the delete user option should be used/i
  63. )
  64. })
  65. it('should disable the remove button if the email does not match the user', function () {
  66. // Button should be disabled initially
  67. cy.findByRole('button', { name: /remove user/i }).should('be.disabled')
  68. // Fill in the email input, with the wrong email address
  69. cy.findByLabelText(
  70. /to confirm you want to remove .* please type the email address associated with their account/i
  71. ).type('totally.wrong@example.com')
  72. // Button still disabled
  73. cy.findByRole('button', { name: /remove user/i }).should('be.disabled')
  74. })
  75. it('should fill out the form, and enable the remove button', function () {
  76. // Button should be disabled initially
  77. cy.findByRole('button', { name: /remove user/i }).should('be.disabled')
  78. // Fill in the email input
  79. cy.findByLabelText(
  80. /to confirm you want to remove .* please type the email address associated with their account/i
  81. ).type(user.email)
  82. // Button should be enabled now
  83. cy.findByRole('button', { name: /remove user/i }).should('be.enabled')
  84. })
  85. })
  86. })