admin.spec.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import { startWith } from './helpers/config'
  2. import { activateUser, ensureUserExists, login } from './helpers/login'
  3. import { v4 as uuid } from 'uuid'
  4. import { createProject } from './helpers/project'
  5. import { beforeWithReRunOnTestRetry } from './helpers/beforeWithReRunOnTestRetry'
  6. describe('admin panel', function () {
  7. describe('in server pro', () => {
  8. const admin = 'admin@example.com'
  9. const user1 = 'user@example.com'
  10. const user2 = 'user2@example.com'
  11. const testProjectName = `project-${uuid()}`
  12. let testProjectId = ''
  13. const deletedProjectName = `deleted-project-${uuid()}`
  14. let projectToDeleteId = ''
  15. const findProjectRow = (projectName: string) => {
  16. cy.log('find project row')
  17. return cy.findByText(projectName).parent().parent()
  18. }
  19. startWith({
  20. pro: true,
  21. })
  22. ensureUserExists({ email: admin, isAdmin: true })
  23. ensureUserExists({ email: user1 })
  24. ensureUserExists({ email: user2 })
  25. beforeWithReRunOnTestRetry(() => {
  26. login(user1)
  27. cy.visit('/project')
  28. createProject(testProjectName).then(id => (testProjectId = id))
  29. cy.visit('/project')
  30. createProject(deletedProjectName).then(id => (projectToDeleteId = id))
  31. })
  32. describe('manage site', () => {
  33. let resumeAdminSession: () => void
  34. beforeEach(() => {
  35. resumeAdminSession = login(admin)
  36. cy.visit('/project')
  37. cy.get('nav').findByText('Admin').click()
  38. cy.get('nav').findByText('Manage Site').click()
  39. })
  40. it('publish and clear admin messages', () => {
  41. const message = 'Admin Message ' + uuid()
  42. cy.log('create system message')
  43. cy.get('[role="tab"]').contains('System Messages').click()
  44. cy.get('input[name="content"]').type(message)
  45. cy.get('button').contains('Post Message').click()
  46. cy.findByText(message)
  47. const resumeUser1Session = login(user1)
  48. cy.visit('/project')
  49. cy.findByText(message)
  50. cy.log('clear system messages')
  51. resumeAdminSession()
  52. cy.visit('/project')
  53. cy.get('nav').findByText('Admin').click()
  54. cy.get('nav').findByText('Manage Site').click()
  55. cy.get('[role="tab"]').contains('System Messages').click()
  56. cy.get('button').contains('Clear all messages').click()
  57. cy.log('verify system messages are no longer displayed')
  58. resumeUser1Session()
  59. cy.visit('/project')
  60. cy.findByText(message).should('not.exist')
  61. })
  62. })
  63. describe('manage users', () => {
  64. beforeEach(() => {
  65. login(admin)
  66. cy.visit('/project')
  67. cy.get('nav').findByText('Admin').click()
  68. cy.get('nav').findByText('Manage Users').click()
  69. })
  70. it('create and login user', () => {
  71. const user = `${uuid()}@example.com`
  72. cy.get('a').contains('New User').click()
  73. cy.get('input[name="email"]').type(user + '{enter}')
  74. cy.get('td')
  75. .contains(/\/user\/activate/)
  76. .then($td => {
  77. const url = $td.text().trim()
  78. activateUser(url)
  79. })
  80. })
  81. it('user list RegExp search', () => {
  82. cy.get('input[name="isRegExpSearch"]').click()
  83. cy.get('input[name="email"]').type('user[0-9]{enter}')
  84. cy.findByText(user2)
  85. cy.findByText(user1).should('not.exist')
  86. })
  87. })
  88. describe('user page', () => {
  89. beforeEach(() => {
  90. login(admin)
  91. cy.visit('/project')
  92. cy.get('nav').findByText('Admin').click()
  93. cy.get('nav').findByText('Manage Users').click()
  94. cy.get('input[name="email"]').type(user1 + '{enter}')
  95. cy.findByText(user1).click()
  96. cy.url().should('match', /\/admin\/user\/[a-fA-F0-9]{24}/)
  97. })
  98. it('displays expected tabs', () => {
  99. const tabs = [
  100. 'User Info',
  101. 'Projects',
  102. 'Deleted Projects',
  103. 'Audit Log',
  104. 'Sessions',
  105. ]
  106. cy.get('[role="tab"]').each((el, index) => {
  107. cy.wrap(el).findByText(tabs[index]).click()
  108. })
  109. })
  110. describe('user info tab', () => {
  111. beforeEach(() => {
  112. cy.get('[role="tab"]').contains('User Info').click()
  113. })
  114. it('displays required sections', () => {
  115. // not exhaustive list, checks the tab content is rendered
  116. cy.findByText('Profile')
  117. cy.findByText('Editor Settings')
  118. })
  119. it('should not display SaaS-only sections', () => {
  120. cy.findByText('Referred User Count').should('not.exist')
  121. cy.findByText('Split Test Assignments').should('not.exist')
  122. cy.findByText('Experimental Features').should('not.exist')
  123. cy.findByText('Service Integration').should('not.exist')
  124. cy.findByText('SSO Integrations').should('not.exist')
  125. cy.findByText('Security').should('not.exist')
  126. })
  127. })
  128. it('transfer project ownership', () => {
  129. cy.log("access project admin through owners' project list")
  130. cy.get('[role="tab"]').contains('Projects').click()
  131. cy.get(`a[href="/admin/project/${testProjectId}"]`).click()
  132. cy.findByText('Transfer Ownership').click()
  133. cy.get('button[type="submit"]').should('be.disabled')
  134. cy.get('input[name="user_id"]').type(user2)
  135. cy.get('button[type="submit"]').should('not.be.disabled')
  136. cy.get('button[type="submit"]').click()
  137. cy.findByText('Transfer project to this user?')
  138. cy.get('button').contains('Confirm').click()
  139. cy.log('check the project is displayed in the new owner projects tab')
  140. cy.get('input[name="email"]').type(user2 + '{enter}')
  141. cy.findByText(user2).click()
  142. cy.get('[role="tab"]').contains('Projects').click()
  143. cy.get(`a[href="/admin/project/${testProjectId}"]`)
  144. })
  145. })
  146. it('restore deleted projects', () => {
  147. const resumeUserSession = login(user1)
  148. cy.visit('/project')
  149. cy.log('select project to delete')
  150. findProjectRow(deletedProjectName).within(() =>
  151. cy.get('input[type="checkbox"]').first().check()
  152. )
  153. cy.log('delete project')
  154. findProjectRow(deletedProjectName).within(() =>
  155. cy.get('button[aria-label="Trash"]').click()
  156. )
  157. cy.get('button').contains('Confirm').click()
  158. cy.findByText(deletedProjectName).should('not.exist')
  159. cy.log('navigate to thrashed projects and delete the project')
  160. cy.get('.project-list-sidebar-react').within(() => {
  161. cy.findByText('Trashed Projects').click()
  162. })
  163. findProjectRow(deletedProjectName).within(() =>
  164. cy.get('button[aria-label="Delete"]').click()
  165. )
  166. cy.get('button').contains('Confirm').click()
  167. cy.findByText(deletedProjectName).should('not.exist')
  168. cy.log('login as an admin and navigate to the deleted project')
  169. login(admin)
  170. cy.visit('/admin/user')
  171. cy.get('input[name="email"]').type(user1 + '{enter}')
  172. cy.get('a').contains(user1).click()
  173. cy.findByText('Deleted Projects').click()
  174. cy.get('a').contains(deletedProjectName).click()
  175. cy.log('undelete the project')
  176. cy.findByText('undelete').click()
  177. cy.findByText('undelete').should('not.exist')
  178. cy.url().should('contain', `/admin/project/${projectToDeleteId}`)
  179. cy.log('login as the user and verify the project is restored')
  180. resumeUserSession()
  181. cy.visit('/project')
  182. cy.get('.project-list-sidebar-react').within(() => {
  183. cy.findByText('Trashed Projects').click()
  184. })
  185. cy.findByText(`${deletedProjectName} (Restored)`)
  186. })
  187. })
  188. })