group-managers.spec.tsx 4.1 KB

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