| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- import { isExcludedBySharding, startWith } from './helpers/config'
- import {
- activateUser,
- createMongoUser,
- ensureUserExists,
- login,
- } from './helpers/login'
- import { v4 as uuid } from 'uuid'
- import { createProject } from './helpers/project'
- import { beforeWithReRunOnTestRetry } from './helpers/beforeWithReRunOnTestRetry'
- import { openEmail } from './helpers/email'
- describe('admin panel', function () {
- function registrationTests() {
- it('via GUI and opening URL manually', () => {
- const user = `${uuid()}@example.com`
- cy.get('input[name="email"]').type(user + '{enter}')
- cy.get('td')
- .contains(/\/user\/activate/)
- .then($td => {
- const url = $td.text().trim()
- activateUser(url)
- })
- })
- it('via GUI and email', () => {
- const user = `${uuid()}@example.com`
- cy.get('input[name="email"]').type(user + '{enter}')
- let url: string
- cy.get('td')
- .contains(/\/user\/activate/)
- .then($td => {
- url = $td.text().trim()
- })
- cy.then(() => {
- openEmail(
- 'Activate your Overleaf Community Edition Account',
- (frame, { url }) => {
- frame.contains('Set password').then(el => {
- expect(el.attr('href')!).to.equal(url)
- })
- },
- { url }
- )
- // Run activateUser in the main origin instead of inside openEmail. See docs on openEmail.
- activateUser(url)
- })
- })
- it('via script and opening URL manually', () => {
- const user = `${uuid()}@example.com`
- let url: string
- cy.then(async () => {
- ;({ url } = await createMongoUser({ email: user }))
- })
- cy.then(() => {
- activateUser(url)
- })
- })
- it('via script and email', () => {
- const user = `${uuid()}@example.com`
- let url: string
- cy.then(async () => {
- ;({ url } = await createMongoUser({ email: user }))
- })
- cy.then(() => {
- openEmail(
- 'Activate your Overleaf Community Edition Account',
- (frame, { url }) => {
- frame.contains('Set password').then(el => {
- expect(el.attr('href')!).to.equal(url)
- })
- },
- { url }
- )
- // Run activateUser in the main origin instead of inside openEmail. See docs on openEmail.
- activateUser(url)
- })
- })
- }
- describe('in CE', () => {
- if (isExcludedBySharding('CE_DEFAULT')) return
- startWith({ pro: false, version: 'latest' })
- const admin = 'admin@example.com'
- const user = `user+${uuid()}@example.com`
- ensureUserExists({ email: admin, isAdmin: true })
- ensureUserExists({ email: user })
- describe('create users', () => {
- beforeEach(() => {
- login(admin)
- cy.visit('/project')
- cy.get('nav').findByText('Admin').click()
- cy.get('nav').findByText('Manage Users').click()
- })
- registrationTests()
- })
- })
- describe('in server pro', () => {
- const admin = 'admin@example.com'
- const user1 = 'user@example.com'
- const user2 = 'user2@example.com'
- let testProjectName = ''
- let testProjectId = ''
- let deletedProjectName = ''
- let projectToDeleteId = ''
- const findProjectRow = (projectName: string) => {
- cy.log('find project row')
- return cy.findByText(projectName).parent().parent()
- }
- if (isExcludedBySharding('PRO_DEFAULT_2')) return
- startWith({
- pro: true,
- })
- ensureUserExists({ email: admin, isAdmin: true })
- ensureUserExists({ email: user1 })
- ensureUserExists({ email: user2 })
- beforeWithReRunOnTestRetry(() => {
- testProjectName = `project-${uuid()}`
- deletedProjectName = `deleted-project-${uuid()}`
- login(user1)
- cy.visit('/project')
- createProject(testProjectName).then(id => (testProjectId = id))
- cy.visit('/project')
- createProject(deletedProjectName).then(id => (projectToDeleteId = id))
- })
- describe('manage site', () => {
- let resumeAdminSession: () => void
- beforeEach(() => {
- resumeAdminSession = login(admin)
- cy.visit('/project')
- cy.get('nav').findByText('Admin').click()
- cy.get('nav').findByText('Manage Site').click()
- })
- it('publish and clear admin messages', () => {
- const message = 'Admin Message ' + uuid()
- cy.log('create system message')
- cy.get('[role="tab"]').contains('System Messages').click()
- cy.get('input[name="content"]').type(message)
- cy.get('button').contains('Post Message').click()
- cy.findByText(message)
- const resumeUser1Session = login(user1)
- cy.visit('/project')
- cy.findByText(message)
- cy.log('clear system messages')
- resumeAdminSession()
- cy.visit('/project')
- cy.get('nav').findByText('Admin').click()
- cy.get('nav').findByText('Manage Site').click()
- cy.get('[role="tab"]').contains('System Messages').click()
- cy.get('button').contains('Clear all messages').click()
- cy.log('verify system messages are no longer displayed')
- resumeUser1Session()
- cy.visit('/project')
- cy.findByText(message).should('not.exist')
- })
- })
- describe('manage users', () => {
- beforeEach(() => {
- login(admin)
- cy.visit('/project')
- cy.get('nav').findByText('Admin').click()
- cy.get('nav').findByText('Manage Users').click()
- })
- describe('create users', () => {
- beforeEach(() => {
- cy.get('a').contains('New User').click()
- })
- registrationTests()
- })
- it('user list RegExp search', () => {
- cy.get('input[name="isRegExpSearch"]').click()
- cy.get('input[name="email"]').type('user[0-9]{enter}')
- cy.findByText(user2)
- cy.findByText(user1).should('not.exist')
- })
- })
- describe('user page', () => {
- beforeEach(() => {
- login(admin)
- cy.visit('/project')
- cy.get('nav').findByText('Admin').click()
- cy.get('nav').findByText('Manage Users').click()
- cy.get('input[name="email"]').type(user1 + '{enter}')
- cy.findByText(user1).click()
- cy.url().should('match', /\/admin\/user\/[a-fA-F0-9]{24}/)
- })
- it('displays expected tabs', () => {
- const tabs = [
- 'User Info',
- 'Projects',
- 'Deleted Projects',
- 'Audit Log',
- 'Sessions',
- ]
- cy.get('[role="tab"]').each((el, index) => {
- cy.wrap(el).findByText(tabs[index]).click()
- })
- })
- describe('user info tab', () => {
- beforeEach(() => {
- cy.get('[role="tab"]').contains('User Info').click()
- })
- it('displays required sections', () => {
- // not exhaustive list, checks the tab content is rendered
- cy.findByText('Profile')
- cy.findByText('Editor Settings')
- })
- it('should not display SaaS-only sections', () => {
- cy.findByText('Referred User Count').should('not.exist')
- cy.findByText('Split Test Assignments').should('not.exist')
- cy.findByText('Experimental Features').should('not.exist')
- cy.findByText('Service Integration').should('not.exist')
- cy.findByText('SSO Integrations').should('not.exist')
- cy.findByText('Security').should('not.exist')
- })
- })
- it('transfer project ownership', () => {
- cy.log("access project admin through owners' project list")
- cy.get('[role="tab"]').contains('Projects').click()
- cy.get(`a[href="/admin/project/${testProjectId}"]`).click()
- cy.findByText('Transfer Ownership').click()
- cy.get('button[type="submit"]').should('be.disabled')
- cy.get('input[name="user_id"]').type(user2)
- cy.get('button[type="submit"]').should('not.be.disabled')
- cy.get('button[type="submit"]').click()
- cy.findByText('Transfer project to this user?')
- cy.get('button').contains('Confirm').click()
- cy.log('check the project is displayed in the new owner projects tab')
- cy.get('input[name="email"]').type(user2 + '{enter}')
- cy.findByText(user2).click()
- cy.get('[role="tab"]').contains('Projects').click()
- cy.get(`a[href="/admin/project/${testProjectId}"]`)
- })
- })
- it('restore deleted projects', () => {
- const resumeUserSession = login(user1)
- cy.visit('/project')
- cy.log('select project to delete')
- findProjectRow(deletedProjectName).within(() =>
- cy.get('input[type="checkbox"]').first().check()
- )
- cy.log('delete project')
- findProjectRow(deletedProjectName).within(() =>
- cy.contains('Trash').click()
- )
- cy.get('button').contains('Confirm').click()
- cy.findByText(deletedProjectName).should('not.exist')
- cy.log('navigate to thrashed projects and delete the project')
- cy.get('.project-list-sidebar-react').within(() => {
- cy.findByText('Trashed Projects').click()
- })
- findProjectRow(deletedProjectName).within(() =>
- cy.contains('Delete').click()
- )
- cy.get('button').contains('Confirm').click()
- cy.findByText(deletedProjectName).should('not.exist')
- cy.log('login as an admin and navigate to the deleted project')
- login(admin)
- cy.visit('/admin/user')
- cy.get('input[name="email"]').type(user1 + '{enter}')
- cy.get('a').contains(user1).click()
- cy.findByText('Deleted Projects').click()
- cy.get('a').contains(deletedProjectName).click()
- cy.log('undelete the project')
- cy.findByText('undelete').click()
- cy.findByText('undelete').should('not.exist')
- cy.url().should('contain', `/admin/project/${projectToDeleteId}`)
- cy.log('login as the user and verify the project is restored')
- resumeUserSession()
- cy.visit('/project')
- cy.get('.project-list-sidebar-react').within(() => {
- cy.findByText('Trashed Projects').click()
- })
- cy.findByText(`${deletedProjectName} (Restored)`)
- })
- })
- })
|