group-managers.spec.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import GroupManagers from '@/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. win.metaAttributesCache.set('ol-hasWriteAccess', true)
  30. })
  31. cy.mount(<GroupManagers />)
  32. })
  33. it('renders the group management page', function () {
  34. cy.findByRole('heading', { name: /my awesome team/i, level: 1 })
  35. cy.findByTestId('managed-entities-table')
  36. .find('tbody')
  37. .within(() => {
  38. cy.get('tr:nth-child(1)').within(() => {
  39. cy.findByText('john.doe@test.com')
  40. cy.findByText('John Doe')
  41. cy.findByText('15th Jan 2023')
  42. cy.findByText('Invite not yet accepted')
  43. })
  44. cy.get('tr:nth-child(2)').within(() => {
  45. cy.findByText('bobby.lapointe@test.com')
  46. cy.findByText('Bobby Lapointe')
  47. cy.findByText('2nd Jan 2023')
  48. cy.findByText('Accepted invite')
  49. })
  50. })
  51. })
  52. it('sends an invite', function () {
  53. cy.intercept('POST', PATHS.addMember, {
  54. statusCode: 201,
  55. body: {
  56. user: {
  57. email: 'someone.else@test.com',
  58. invite: true,
  59. },
  60. },
  61. })
  62. cy.findByTestId('add-members-form').within(() => {
  63. cy.findByLabelText(/Add more manager emails/i).type(
  64. 'someone.else@test.com'
  65. )
  66. cy.findByRole('button', { name: /add/i }).click()
  67. })
  68. cy.findByTestId('managed-entities-table')
  69. .find('tbody')
  70. .within(() => {
  71. cy.get('tr:nth-child(3)').within(() => {
  72. cy.findByText('someone.else@test.com')
  73. cy.findByText('N/A')
  74. cy.findByText('Invite not yet accepted')
  75. })
  76. })
  77. })
  78. it('tries to send an invite and displays the error', function () {
  79. cy.intercept('POST', PATHS.addMember, {
  80. statusCode: 500,
  81. body: {
  82. error: {
  83. message: 'User already added',
  84. },
  85. },
  86. })
  87. cy.findByTestId('add-members-form').within(() => {
  88. cy.findByLabelText(/Add more manager emails/i).type(
  89. 'someone.else@test.com'
  90. )
  91. cy.findByRole('button', { name: /add/i }).click()
  92. })
  93. cy.findByRole('alert').should('contain.text', 'Error: User already added')
  94. })
  95. it('checks the select all checkbox', function () {
  96. cy.findByTestId('managed-entities-table')
  97. .find('tbody')
  98. .within(() => {
  99. cy.get('tr:nth-child(1)').within(() => {
  100. cy.findByLabelText(/select user/i).should('not.be.checked')
  101. })
  102. cy.get('tr:nth-child(2)').within(() => {
  103. cy.findByLabelText(/select user/i).should('not.be.checked')
  104. })
  105. })
  106. cy.findByTestId('managed-entities-table')
  107. .find('thead')
  108. .within(() => {
  109. cy.findByLabelText(/select all/i).check()
  110. })
  111. cy.findByTestId('managed-entities-table')
  112. .find('tbody')
  113. .within(() => {
  114. cy.get('tr:nth-child(1)').within(() => {
  115. cy.findByLabelText(/select user/i).should('be.checked')
  116. })
  117. cy.get('tr:nth-child(2)').within(() => {
  118. cy.findByLabelText(/select user/i).should('be.checked')
  119. })
  120. })
  121. })
  122. it('remove a member', function () {
  123. cy.intercept('DELETE', `${PATHS.removeMember}/abc123def456`, {
  124. statusCode: 200,
  125. })
  126. cy.findByTestId('managed-entities-table')
  127. .find('tbody')
  128. .within(() => {
  129. cy.get('tr:nth-child(1)').within(() => {
  130. cy.findByLabelText(/select user/i).check()
  131. })
  132. })
  133. cy.findByRole('button', { name: /remove manager/i }).click()
  134. cy.findByTestId('managed-entities-table')
  135. .find('tbody')
  136. .within(() => {
  137. cy.get('tr:nth-child(1)').within(() => {
  138. cy.findByText('bobby.lapointe@test.com')
  139. cy.findByText('Bobby Lapointe')
  140. cy.findByText('2nd Jan 2023')
  141. cy.findByText('Accepted invite')
  142. })
  143. })
  144. })
  145. it('tries to remove a manager and displays the error', function () {
  146. cy.intercept('DELETE', `${PATHS.removeMember}/abc123def456`, {
  147. statusCode: 500,
  148. })
  149. cy.findByTestId('managed-entities-table')
  150. .find('tbody')
  151. .within(() => {
  152. cy.get('tr:nth-child(1)').within(() => {
  153. cy.findByLabelText(/select user/i).check()
  154. })
  155. })
  156. cy.findByRole('button', { name: /remove manager/i }).click()
  157. cy.findByRole('alert').should('contain.text', 'Sorry, something went wrong')
  158. })
  159. })