admin.spec.ts 13 KB

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