group-managers.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import GroupManagers from '../../../../../frontend/js/features/group-management/components/group-managers'
  2. const JOHN_DOE = {
  3. _id: 'abc123def456',
  4. first_name: 'John',
  5. last_name: 'Doe',
  6. email: 'john.doe@test.com',
  7. last_active_at: new Date('2023-01-15'),
  8. invite: true,
  9. }
  10. const BOBBY_LAPOINTE = {
  11. _id: 'bcd234efa567',
  12. first_name: 'Bobby',
  13. last_name: 'Lapointe',
  14. email: 'bobby.lapointe@test.com',
  15. last_active_at: new Date('2023-01-02'),
  16. invite: false,
  17. }
  18. const GROUP_ID = '888fff888fff'
  19. const PATHS = {
  20. addMember: `/manage/groups/${GROUP_ID}/managers`,
  21. removeMember: `/manage/groups/${GROUP_ID}/managers`,
  22. }
  23. describe('group managers', function () {
  24. beforeEach(function () {
  25. cy.window().then(win => {
  26. win.metaAttributesCache.set('ol-users', [JOHN_DOE, BOBBY_LAPOINTE])
  27. win.metaAttributesCache.set('ol-groupId', GROUP_ID)
  28. win.metaAttributesCache.set('ol-groupName', 'My Awesome Team')
  29. })
  30. cy.mount(<GroupManagers />)
  31. })
  32. it('renders the group management page', function () {
  33. cy.get('h1').contains('My Awesome Team')
  34. cy.get('ul').within(() => {
  35. cy.get('li:nth-child(2)').within(() => {
  36. cy.contains('john.doe@test.com')
  37. cy.contains('John Doe')
  38. cy.contains('15th Jan 2023')
  39. cy.get(`[aria-label="Invite not yet accepted"]`)
  40. })
  41. cy.get('li:nth-child(3)').within(() => {
  42. cy.contains('bobby.lapointe@test.com')
  43. cy.contains('Bobby Lapointe')
  44. cy.contains('2nd Jan 2023')
  45. cy.get(`[aria-label="Accepted invite"]`)
  46. })
  47. })
  48. })
  49. it('sends an invite', function () {
  50. cy.intercept('POST', PATHS.addMember, {
  51. statusCode: 201,
  52. body: {
  53. user: {
  54. email: 'someone.else@test.com',
  55. invite: true,
  56. },
  57. },
  58. })
  59. cy.get('.form-control').type('someone.else@test.com')
  60. cy.get('button').click()
  61. cy.get('ul').within(() => {
  62. cy.get('li:nth-child(4)').within(() => {
  63. cy.contains('someone.else@test.com')
  64. cy.contains('N/A')
  65. cy.get(`[aria-label="Invite not yet accepted"]`)
  66. })
  67. })
  68. })
  69. it('tries to send an invite and displays the error', function () {
  70. cy.intercept('POST', PATHS.addMember, {
  71. statusCode: 500,
  72. body: {
  73. error: {
  74. message: 'User already added',
  75. },
  76. },
  77. })
  78. cy.get('.form-control').type('someone.else@test.com')
  79. cy.get('button').click()
  80. cy.get('.alert').contains('Error: User already added')
  81. })
  82. it('checks the select all checkbox', function () {
  83. cy.get('ul').within(() => {
  84. cy.get('li:nth-child(2)').within(() => {
  85. cy.get('.select-item').should('not.be.checked')
  86. })
  87. cy.get('li:nth-child(3)').within(() => {
  88. cy.get('.select-item').should('not.be.checked')
  89. })
  90. })
  91. cy.get('.select-all').click()
  92. cy.get('ul').within(() => {
  93. cy.get('li:nth-child(2)').within(() => {
  94. cy.get('.select-item').should('be.checked')
  95. })
  96. cy.get('li:nth-child(3)').within(() => {
  97. cy.get('.select-item').should('be.checked')
  98. })
  99. })
  100. })
  101. it('remove a member', function () {
  102. cy.intercept('DELETE', `${PATHS.removeMember}/abc123def456`, {
  103. statusCode: 200,
  104. })
  105. cy.get('ul').within(() => {
  106. cy.get('li:nth-child(2)').within(() => {
  107. cy.get('.select-item').check()
  108. })
  109. })
  110. cy.get('button').contains('Remove manager').click()
  111. cy.get('ul').within(() => {
  112. cy.get('li:nth-child(2)').within(() => {
  113. cy.contains('bobby.lapointe@test.com')
  114. cy.contains('Bobby Lapointe')
  115. cy.contains('2nd Jan 2023')
  116. cy.get(`[aria-label="Accepted invite"]`)
  117. })
  118. })
  119. })
  120. it('tries to remove a manager and displays the error', function () {
  121. cy.intercept('DELETE', `${PATHS.removeMember}/abc123def456`, {
  122. statusCode: 500,
  123. })
  124. cy.get('ul').within(() => {
  125. cy.get('li:nth-child(2)').within(() => {
  126. cy.get('.select-item').check()
  127. })
  128. })
  129. cy.get('button').contains('Remove manager').click()
  130. cy.get('.alert').contains('Sorry, something went wrong')
  131. })
  132. })