2024-07-10 10:00:41 -04:00
|
|
|
import { isExcludedBySharding, startWith } from './helpers/config'
|
2024-08-02 08:10:06 -04:00
|
|
|
import {
|
|
|
|
activateUser,
|
|
|
|
createMongoUser,
|
|
|
|
ensureUserExists,
|
|
|
|
login,
|
|
|
|
} from './helpers/login'
|
2024-06-13 04:36:32 -04:00
|
|
|
import { v4 as uuid } from 'uuid'
|
|
|
|
import { createProject } from './helpers/project'
|
2024-06-27 04:49:21 -04:00
|
|
|
import { beforeWithReRunOnTestRetry } from './helpers/beforeWithReRunOnTestRetry'
|
2024-08-02 08:10:06 -04:00
|
|
|
import { openEmail } from './helpers/email'
|
2024-06-13 04:36:32 -04:00
|
|
|
|
|
|
|
describe('admin panel', function () {
|
2024-08-02 08:10:06 -04:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2024-06-13 04:36:32 -04:00
|
|
|
describe('in server pro', () => {
|
|
|
|
const admin = 'admin@example.com'
|
|
|
|
const user1 = 'user@example.com'
|
|
|
|
const user2 = 'user2@example.com'
|
|
|
|
|
2024-07-11 06:22:30 -04:00
|
|
|
let testProjectName = ''
|
2024-06-13 04:36:32 -04:00
|
|
|
let testProjectId = ''
|
2024-07-11 06:22:30 -04:00
|
|
|
let deletedProjectName = ''
|
2024-06-13 04:36:32 -04:00
|
|
|
let projectToDeleteId = ''
|
|
|
|
|
2024-06-13 11:56:47 -04:00
|
|
|
const findProjectRow = (projectName: string) => {
|
|
|
|
cy.log('find project row')
|
|
|
|
return cy.findByText(projectName).parent().parent()
|
|
|
|
}
|
2024-06-13 04:36:32 -04:00
|
|
|
|
2024-07-10 10:00:41 -04:00
|
|
|
if (isExcludedBySharding('PRO_DEFAULT_2')) return
|
2024-06-13 04:36:32 -04:00
|
|
|
startWith({
|
|
|
|
pro: true,
|
|
|
|
})
|
|
|
|
ensureUserExists({ email: admin, isAdmin: true })
|
|
|
|
ensureUserExists({ email: user1 })
|
|
|
|
ensureUserExists({ email: user2 })
|
|
|
|
|
2024-06-27 04:49:21 -04:00
|
|
|
beforeWithReRunOnTestRetry(() => {
|
2024-07-11 06:22:30 -04:00
|
|
|
testProjectName = `project-${uuid()}`
|
|
|
|
deletedProjectName = `deleted-project-${uuid()}`
|
2024-06-13 04:36:32 -04:00
|
|
|
login(user1)
|
|
|
|
cy.visit('/project')
|
|
|
|
createProject(testProjectName).then(id => (testProjectId = id))
|
|
|
|
cy.visit('/project')
|
|
|
|
createProject(deletedProjectName).then(id => (projectToDeleteId = id))
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('manage site', () => {
|
|
|
|
beforeEach(() => {
|
2024-08-06 05:10:03 -04:00
|
|
|
login(admin)
|
2024-06-13 04:36:32 -04:00
|
|
|
cy.visit('/project')
|
|
|
|
cy.get('nav').findByText('Admin').click()
|
|
|
|
cy.get('nav').findByText('Manage Site').click()
|
|
|
|
})
|
|
|
|
|
2024-06-20 07:00:45 -04:00
|
|
|
it('publish and clear admin messages', () => {
|
2024-06-13 04:36:32 -04:00
|
|
|
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)
|
|
|
|
|
2024-08-06 05:10:03 -04:00
|
|
|
login(user1)
|
2024-06-13 04:36:32 -04:00
|
|
|
cy.visit('/project')
|
|
|
|
cy.findByText(message)
|
|
|
|
|
|
|
|
cy.log('clear system messages')
|
2024-08-06 05:10:03 -04:00
|
|
|
login(admin)
|
2024-06-13 04:36:32 -04:00
|
|
|
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')
|
2024-08-06 05:10:03 -04:00
|
|
|
login(user1)
|
2024-06-13 04:36:32 -04:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
|
2024-08-02 08:10:06 -04:00
|
|
|
describe('create users', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
cy.get('a').contains('New User').click()
|
|
|
|
})
|
|
|
|
registrationTests()
|
2024-06-13 04:36:32 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
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', () => {
|
2024-08-06 05:10:03 -04:00
|
|
|
login(user1)
|
2024-06-13 04:36:32 -04:00
|
|
|
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(() =>
|
2024-07-11 06:22:30 -04:00
|
|
|
cy.contains('Trash').click()
|
2024-06-13 04:36:32 -04:00
|
|
|
)
|
|
|
|
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(() =>
|
2024-07-11 06:22:30 -04:00
|
|
|
cy.contains('Delete').click()
|
2024-06-13 04:36:32 -04:00
|
|
|
)
|
|
|
|
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')
|
2024-08-06 05:10:03 -04:00
|
|
|
login(user1)
|
2024-06-13 04:36:32 -04:00
|
|
|
cy.visit('/project')
|
|
|
|
cy.get('.project-list-sidebar-react').within(() => {
|
|
|
|
cy.findByText('Trashed Projects').click()
|
|
|
|
})
|
|
|
|
cy.findByText(`${deletedProjectName} (Restored)`)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|