admin.spec.ts 7.4 KB

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