admin.spec.ts 7.6 KB

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