admin.spec.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. import { isExcludedBySharding, startWith } from './helpers/config'
  2. import {
  3. activateUser,
  4. createMongoUser,
  5. ensureUserExists,
  6. login,
  7. } from './helpers/login'
  8. import { v4 as uuid } from 'uuid'
  9. import { createProject } from './helpers/project'
  10. import { beforeWithReRunOnTestRetry } from './helpers/beforeWithReRunOnTestRetry'
  11. import { openEmail } from './helpers/email'
  12. describe('admin panel', function () {
  13. function registrationTests() {
  14. it('via GUI and opening URL manually', function () {
  15. const user = `${uuid()}@example.com`
  16. cy.findByLabelText('Emails to register new users').type(user + '{enter}')
  17. cy.findByRole('cell', { name: /\/user\/activate/ }).then($td => {
  18. const url = $td.text().trim()
  19. activateUser(url)
  20. })
  21. })
  22. it('via GUI and email', function () {
  23. const user = `${uuid()}@example.com`
  24. cy.findByLabelText('Emails to register new users').type(user + '{enter}')
  25. let url: string
  26. cy.findByRole('cell', { name: /\/user\/activate/ }).then($td => {
  27. url = $td.text().trim()
  28. })
  29. cy.then(() => {
  30. openEmail(
  31. 'Activate your E2E test Account',
  32. (frame, { url }) => {
  33. frame.contains('a', 'Set password').then(el => {
  34. expect(el.attr('href')!).to.equal(url)
  35. })
  36. },
  37. { url }
  38. )
  39. // Run activateUser in the main origin instead of inside openEmail. See docs on openEmail.
  40. activateUser(url)
  41. })
  42. })
  43. it('via script and opening URL manually', function () {
  44. const user = `${uuid()}@example.com`
  45. let url: string
  46. cy.then(async () => {
  47. ;({ url } = await createMongoUser({ email: user }))
  48. })
  49. cy.then(() => {
  50. activateUser(url)
  51. })
  52. })
  53. it('via script and email', function () {
  54. const user = `${uuid()}@example.com`
  55. let url: string
  56. cy.then(async () => {
  57. ;({ url } = await createMongoUser({ email: user }))
  58. })
  59. cy.then(() => {
  60. openEmail(
  61. 'Activate your E2E test Account',
  62. (frame, { url }) => {
  63. frame.contains('a', 'Set password').then(el => {
  64. expect(el.attr('href')!).to.equal(url)
  65. })
  66. },
  67. { url }
  68. )
  69. // Run activateUser in the main origin instead of inside openEmail. See docs on openEmail.
  70. activateUser(url)
  71. })
  72. })
  73. }
  74. describe('in CE', function () {
  75. if (isExcludedBySharding('CE_DEFAULT')) return
  76. startWith({ pro: false, version: 'latest' })
  77. const admin = 'admin@example.com'
  78. const user = `user+${uuid()}@example.com`
  79. ensureUserExists({ email: admin, isAdmin: true })
  80. ensureUserExists({ email: user })
  81. describe('create users', function () {
  82. beforeEach(function () {
  83. login(admin)
  84. cy.visit('/project')
  85. cy.findByRole('menuitem', { name: 'Admin' }).click()
  86. cy.findByRole('menuitem', { name: 'Manage Users' }).click()
  87. })
  88. registrationTests()
  89. })
  90. })
  91. describe('in server pro', function () {
  92. const admin = 'admin@example.com'
  93. const user1 = 'user@example.com'
  94. const user2 = 'user2@example.com'
  95. let testProjectName = ''
  96. let testProjectId = ''
  97. let deletedProjectName = ''
  98. let projectToDeleteId = ''
  99. const findProjectRow = (projectName: string) => {
  100. cy.log('find project row')
  101. return cy.findByText(projectName).parent().parent()
  102. }
  103. if (isExcludedBySharding('PRO_DEFAULT_2')) return
  104. startWith({
  105. pro: true,
  106. })
  107. ensureUserExists({ email: admin, isAdmin: true })
  108. ensureUserExists({ email: user1 })
  109. ensureUserExists({ email: user2 })
  110. beforeWithReRunOnTestRetry(() => {
  111. testProjectName = `project-${uuid()}`
  112. deletedProjectName = `deleted-project-${uuid()}`
  113. login(user1)
  114. createProject(testProjectName, { open: false }).then(
  115. id => (testProjectId = id)
  116. )
  117. createProject(deletedProjectName, { open: false }).then(
  118. id => (projectToDeleteId = id)
  119. )
  120. })
  121. describe('admin menu items', function () {
  122. beforeEach(function () {
  123. login(admin)
  124. cy.visit('/project')
  125. })
  126. it('displays expected admin menu items', function () {
  127. const menuitems = ['Manage Site', 'Manage Users', 'Project URL Lookup']
  128. menuitems.forEach(name => {
  129. cy.findByRole('menuitem', { name: 'Admin' }).click()
  130. cy.findByRole('menu')
  131. .findAllByRole('menuitem')
  132. .should('have.length', menuitems.length)
  133. cy.findByRole('menu').findByRole('menuitem', { name }).click()
  134. })
  135. })
  136. })
  137. describe('manage site', function () {
  138. beforeEach(function () {
  139. login(admin)
  140. cy.visit('/project')
  141. cy.findByRole('menuitem', { name: 'Admin' }).click()
  142. cy.findByRole('menuitem', { name: 'Manage Site' }).click()
  143. })
  144. it('publish and clear admin messages', function () {
  145. const message = 'Admin Message ' + uuid()
  146. cy.log('create system message')
  147. cy.findByRole('tab', { name: 'System Messages' }).click()
  148. cy.findByLabelText('Message').type(message)
  149. cy.findByRole('button', { name: 'Post Message' }).click()
  150. cy.findByText(message)
  151. login(user1)
  152. cy.visit('/project')
  153. cy.findByText(message)
  154. cy.log('clear system messages')
  155. login(admin)
  156. cy.visit('/project')
  157. cy.findByRole('menuitem', { name: 'Admin' }).click()
  158. cy.findByRole('menuitem', { name: 'Manage Site' }).click()
  159. cy.findByRole('tab', { name: 'System Messages' }).click()
  160. cy.findByRole('button', { name: 'Clear all messages' }).click()
  161. cy.log('verify system messages are no longer displayed')
  162. login(user1)
  163. cy.visit('/project')
  164. cy.findByText(message).should('not.exist')
  165. })
  166. })
  167. describe('manage users', function () {
  168. beforeEach(function () {
  169. login(admin)
  170. cy.visit('/project')
  171. cy.findByRole('menuitem', { name: 'Admin' }).click()
  172. cy.findByRole('menuitem', { name: 'Manage Users' }).click()
  173. })
  174. it('displays expected tabs', function () {
  175. const tabs = ['Users', 'License Usage']
  176. cy.findAllByRole('tab').should('have.length', tabs.length)
  177. tabs.forEach(tabName => {
  178. cy.findByRole('tab', { name: tabName }).click()
  179. })
  180. })
  181. it('license usage tab', function () {
  182. cy.findByRole('tab', { name: 'License Usage' }).click()
  183. cy.findByText(
  184. 'An active user is one who has opened a project in this Server Pro instance in the last 12 months.'
  185. )
  186. })
  187. describe('create users', function () {
  188. beforeEach(function () {
  189. cy.findByRole('link', { name: 'New User' }).click()
  190. })
  191. registrationTests()
  192. })
  193. it('user list RegExp search', function () {
  194. cy.findByLabelText('RegExp').click()
  195. cy.findByPlaceholderText('Search users by email or id…').type(
  196. 'user[0-9]{enter}'
  197. )
  198. cy.findByRole('link', { name: user2 })
  199. cy.findByRole('link', { name: user1 }).should('not.exist')
  200. })
  201. })
  202. describe('user page', function () {
  203. beforeEach(function () {
  204. login(admin)
  205. cy.visit('/project')
  206. cy.findByRole('menuitem', { name: 'Admin' }).click()
  207. cy.findByRole('menuitem', { name: 'Manage Users' }).click()
  208. cy.findByPlaceholderText('Search users by email or id…').type(
  209. user1 + '{enter}'
  210. )
  211. cy.findByRole('link', { name: user1 }).click()
  212. cy.url().should('match', /\/admin\/user\/[a-fA-F0-9]{24}/)
  213. })
  214. it('displays expected tabs', function () {
  215. const tabs = [
  216. 'User Info',
  217. 'Projects',
  218. 'Deleted Projects',
  219. 'Audit Log',
  220. 'Sessions',
  221. ]
  222. cy.findAllByRole('tab').should('have.length', tabs.length)
  223. tabs.forEach(tabName => {
  224. cy.findByRole('tab', { name: tabName }).click()
  225. })
  226. })
  227. describe('user info tab', function () {
  228. beforeEach(function () {
  229. cy.findByRole('tab', { name: 'User Info' }).click()
  230. })
  231. it('displays required sections', function () {
  232. // not exhaustive list, checks the tab content is rendered
  233. cy.findByRole('heading', { name: 'Profile' })
  234. cy.findByRole('heading', { name: 'Editor Settings' })
  235. })
  236. it('should not display SaaS-only sections', function () {
  237. cy.findByLabelText('Referred User Count').should('not.exist')
  238. cy.findByRole('heading', { name: /Split Test Assignments/ }).should(
  239. 'not.exist'
  240. )
  241. cy.findByRole('heading', { name: 'Experimental Features' }).should(
  242. 'not.exist'
  243. )
  244. cy.findByRole('heading', { name: 'Service Integration' }).should(
  245. 'not.exist'
  246. )
  247. cy.findByRole('heading', { name: 'SSO Integrations' }).should(
  248. 'not.exist'
  249. )
  250. cy.findByRole('heading', { name: 'Security' }).should('not.exist')
  251. })
  252. })
  253. it('transfer project ownership', function () {
  254. cy.log("access project admin through owners' project list")
  255. cy.findByRole('tablist').within(() => {
  256. cy.findByRole('tab', { name: 'Projects' }).click()
  257. })
  258. cy.findByRole('link', { name: testProjectName })
  259. .parent()
  260. .parent()
  261. .within(() => {
  262. cy.findByRole('link', { name: 'Project information' }).click()
  263. })
  264. cy.findByRole('button', { name: 'Transfer Ownership' }).click()
  265. cy.findByRole('dialog').within(() => {
  266. cy.findByRole('heading', { name: 'Transfer Ownership of Project' })
  267. cy.findByRole('button', { name: 'Find' }).should('be.disabled')
  268. cy.findByRole('button', { name: 'Confirm' }).should('be.disabled')
  269. cy.findByPlaceholderText('User ID or Email').type(user2)
  270. cy.findByRole('button', { name: 'Find' }).should('not.be.disabled')
  271. cy.findByRole('button', { name: 'Find' }).click()
  272. cy.findByText('Transfer project to this user?')
  273. cy.findByRole('cell', { name: 'ID' })
  274. cy.findByRole('cell', { name: 'Name' })
  275. cy.findByRole('cell', { name: 'Email' })
  276. cy.findByRole('cell', { name: user2 })
  277. cy.findByRole('button', { name: 'Confirm' }).should('not.be.disabled')
  278. cy.findByRole('button', { name: 'Confirm' }).click()
  279. })
  280. cy.log('check the project is displayed in the new owner projects tab')
  281. cy.findByPlaceholderText('Search users by email or id…').type(
  282. user2 + '{enter}'
  283. )
  284. cy.findByRole('link', { name: user2 }).click()
  285. cy.findByRole('tablist').within(() => {
  286. cy.findByRole('tab', { name: 'Projects' }).click()
  287. })
  288. cy.findByRole('link', { name: testProjectName })
  289. .parent()
  290. .parent()
  291. .within(() => {
  292. cy.findByRole('link', { name: 'Project information' }).click()
  293. })
  294. })
  295. })
  296. describe('project page', function () {
  297. beforeEach(function () {
  298. login(admin)
  299. cy.visit(`/admin/project/${testProjectId}`)
  300. })
  301. it('displays expected tabs', function () {
  302. const tabs = ['Project Info', 'Deleted Docs', 'Audit Log']
  303. cy.findAllByRole('tab').should('have.length', tabs.length)
  304. tabs.forEach(tabName => {
  305. cy.findByRole('tab', { name: tabName }).click()
  306. })
  307. })
  308. })
  309. it('restore deleted projects', function () {
  310. login(user1)
  311. cy.visit('/project')
  312. cy.log('select project to delete')
  313. findProjectRow(deletedProjectName).within(() =>
  314. cy
  315. .findByRole('checkbox', { name: `Select ${deletedProjectName}` })
  316. .first()
  317. .check()
  318. )
  319. cy.log('delete project')
  320. findProjectRow(deletedProjectName).within(() =>
  321. cy.findByRole('button', { name: 'Trash' }).click()
  322. )
  323. cy.findByRole('button', { name: 'Confirm' }).click()
  324. cy.findByRole('link', { name: deletedProjectName }).should('not.exist')
  325. cy.log('navigate to thrashed projects and delete the project')
  326. cy.findByRole('navigation', {
  327. name: 'Project categories and tags',
  328. })
  329. .findByRole('button', { name: 'Trashed projects' })
  330. .click()
  331. findProjectRow(deletedProjectName).within(() =>
  332. cy.findByRole('button', { name: 'Delete' }).click()
  333. )
  334. cy.findByRole('button', { name: 'Confirm' }).click()
  335. cy.findByRole('link', { name: deletedProjectName }).should('not.exist')
  336. cy.log('login as an admin and navigate to the deleted project')
  337. login(admin)
  338. cy.visit('/admin/user')
  339. cy.findByPlaceholderText('Search users by email or id…').type(
  340. user1 + '{enter}'
  341. )
  342. cy.findByRole('link', { name: user1 }).click()
  343. cy.findByRole('tab', { name: 'Deleted Projects' }).click()
  344. cy.findByRole('link', { name: deletedProjectName }).click()
  345. cy.log('undelete the project')
  346. cy.findByRole('button', { name: 'Undelete' }).click()
  347. cy.findByRole('button', { name: 'Undelete' }).should('not.exist')
  348. cy.url().should('contain', `/admin/project/${projectToDeleteId}`)
  349. cy.log('login as the user and verify the project is restored')
  350. login(user1)
  351. cy.visit('/project')
  352. cy.findByRole('navigation', {
  353. name: 'Project categories and tags',
  354. })
  355. .findByRole('button', { name: 'Trashed projects' })
  356. .click()
  357. cy.findByRole('link', { name: `${deletedProjectName} (Restored)` })
  358. })
  359. })
  360. })