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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import OffboardManagedUserModal from '../../../../../../frontend/js/features/group-management/components/managed-users/offboard-managed-user-modal'
  2. import sinon from 'sinon'
  3. describe('OffboardManagedUserModal', 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. const otherUser = {
  20. _id: 'other-user',
  21. email: 'other.user@example.com',
  22. first_name: 'Other',
  23. last_name: 'User',
  24. invite: false,
  25. last_active_at: new Date(),
  26. enrollment: {
  27. managedBy: `${groupId}`,
  28. enrolledAt: new Date(),
  29. },
  30. isEntityAdmin: undefined,
  31. }
  32. const allMembers = [user, otherUser]
  33. beforeEach(function () {
  34. cy.mount(
  35. <OffboardManagedUserModal
  36. user={user}
  37. allMembers={allMembers}
  38. groupId={groupId}
  39. onClose={sinon.stub()}
  40. />
  41. )
  42. })
  43. it('should render the modal', function () {
  44. cy.get('#delete-user-form').should('exist')
  45. })
  46. it('should disable the button if a recipient is not selected', function () {
  47. // Button should be disabled initially
  48. cy.get('button[type="submit"]').should('be.disabled')
  49. // Not selecting a recipient...
  50. // Fill in the email input
  51. cy.get('#supplied-email-input').type(user.email)
  52. // Button still disabled
  53. cy.get('button[type="submit"]').should('be.disabled')
  54. })
  55. it('should disable the button if the email is not filled in', function () {
  56. // Button should be disabled initially
  57. cy.get('button[type="submit"]').should('be.disabled')
  58. // Select a recipient
  59. cy.get('#recipient-select-input').select('other.user@example.com')
  60. // Not filling in the email...
  61. // Button still disabled
  62. cy.get('button[type="submit"]').should('be.disabled')
  63. })
  64. it('should disable the button if the email does not match the user', function () {
  65. // Button should be disabled initially
  66. cy.get('button[type="submit"]').should('be.disabled')
  67. // Select a recipient
  68. cy.get('#recipient-select-input').select('other.user@example.com')
  69. // Fill in the email input, with the wrong email address
  70. cy.get('#supplied-email-input').type('totally.wrong@example.com')
  71. // Button still disabled
  72. cy.get('button[type="submit"]').should('be.disabled')
  73. })
  74. it('should fill out the form, and enable the delete button', function () {
  75. // Button should be disabled initially
  76. cy.get('button[type="submit"]').should('be.disabled')
  77. // Select a recipient
  78. cy.get('#recipient-select-input').select('other.user@example.com')
  79. // Button still disabled
  80. cy.get('button[type="submit"]').should('be.disabled')
  81. // Fill in the email input
  82. cy.get('#supplied-email-input').type(user.email)
  83. // Button should be enabled now
  84. cy.get('button[type="submit"]').should('not.be.disabled')
  85. })
  86. })
  87. })