group-managers.spec.tsx 4.9 KB

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