admin.spec.ts 7.4 KB

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