| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- 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', function () {
- const user = `${uuid()}@example.com`
- cy.findByLabelText('Emails to register new users').type(user + '{enter}')
- cy.findByRole('cell', { name: /\/user\/activate/ }).then($td => {
- const url = $td.text().trim()
- activateUser(url)
- })
- })
- it('via GUI and email', function () {
- const user = `${uuid()}@example.com`
- cy.findByLabelText('Emails to register new users').type(user + '{enter}')
- let url: string
- cy.findByRole('cell', { name: /\/user\/activate/ }).then($td => {
- url = $td.text().trim()
- })
- cy.then(() => {
- openEmail(
- 'Activate your E2E test Account',
- (frame, { url }) => {
- frame.contains('a', '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', function () {
- 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', function () {
- const user = `${uuid()}@example.com`
- let url: string
- cy.then(async () => {
- ;({ url } = await createMongoUser({ email: user }))
- })
- cy.then(() => {
- openEmail(
- 'Activate your E2E test Account',
- (frame, { url }) => {
- frame.contains('a', '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', function () {
- 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', function () {
- beforeEach(function () {
- login(admin)
- cy.visit('/project')
- cy.findByRole('menuitem', { name: 'Admin' }).click()
- cy.findByRole('menuitem', { name: 'Manage Users' }).click()
- })
- registrationTests()
- })
- })
- describe('in server pro', function () {
- 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)
- createProject(testProjectName, { open: false }).then(
- id => (testProjectId = id)
- )
- createProject(deletedProjectName, { open: false }).then(
- id => (projectToDeleteId = id)
- )
- })
- describe('admin menu items', function () {
- beforeEach(function () {
- login(admin)
- cy.visit('/project')
- })
- it('displays expected admin menu items', function () {
- const menuitems = ['Manage Site', 'Manage Users', 'Project URL Lookup']
- menuitems.forEach(name => {
- cy.findByRole('menuitem', { name: 'Admin' }).click()
- cy.findByRole('menu')
- .findAllByRole('menuitem')
- .should('have.length', menuitems.length)
- cy.findByRole('menu').findByRole('menuitem', { name }).click()
- })
- })
- })
- describe('manage site', function () {
- beforeEach(function () {
- login(admin)
- cy.visit('/project')
- cy.findByRole('menuitem', { name: 'Admin' }).click()
- cy.findByRole('menuitem', { name: 'Manage Site' }).click()
- })
- it('publish and clear admin messages', function () {
- const message = 'Admin Message ' + uuid()
- cy.log('create system message')
- cy.findByRole('tab', { name: 'System Messages' }).click()
- cy.findByLabelText('Message').type(message)
- cy.findByRole('button', { name: 'Post Message' }).click()
- cy.findByText(message)
- login(user1)
- cy.visit('/project')
- cy.findByText(message)
- cy.log('clear system messages')
- login(admin)
- cy.visit('/project')
- cy.findByRole('menuitem', { name: 'Admin' }).click()
- cy.findByRole('menuitem', { name: 'Manage Site' }).click()
- cy.findByRole('tab', { name: 'System Messages' }).click()
- cy.findByRole('button', { name: 'Clear all messages' }).click()
- cy.log('verify system messages are no longer displayed')
- login(user1)
- cy.visit('/project')
- cy.findByText(message).should('not.exist')
- })
- })
- describe('manage users', function () {
- beforeEach(function () {
- login(admin)
- cy.visit('/project')
- cy.findByRole('menuitem', { name: 'Admin' }).click()
- cy.findByRole('menuitem', { name: 'Manage Users' }).click()
- })
- it('displays expected tabs', function () {
- const tabs = ['Users', 'License Usage']
- cy.findAllByRole('tab').should('have.length', tabs.length)
- tabs.forEach(tabName => {
- cy.findByRole('tab', { name: tabName }).click()
- })
- })
- it('license usage tab', function () {
- cy.findByRole('tab', { name: 'License Usage' }).click()
- cy.findByText(
- 'An active user is one who has opened a project in this Server Pro instance in the last 12 months.'
- )
- })
- describe('create users', function () {
- beforeEach(function () {
- cy.findByRole('link', { name: 'New User' }).click()
- })
- registrationTests()
- })
- it('user list RegExp search', function () {
- cy.findByLabelText('RegExp').click()
- cy.findByPlaceholderText('Search users by email or id…').type(
- 'user[0-9]{enter}'
- )
- cy.findByRole('link', { name: user2 })
- cy.findByRole('link', { name: user1 }).should('not.exist')
- })
- })
- describe('user page', function () {
- beforeEach(function () {
- login(admin)
- cy.visit('/project')
- cy.findByRole('menuitem', { name: 'Admin' }).click()
- cy.findByRole('menuitem', { name: 'Manage Users' }).click()
- cy.findByPlaceholderText('Search users by email or id…').type(
- user1 + '{enter}'
- )
- cy.findByRole('link', { name: user1 }).click()
- cy.url().should('match', /\/admin\/user\/[a-fA-F0-9]{24}/)
- })
- it('displays expected tabs', function () {
- const tabs = [
- 'User Info',
- 'Projects',
- 'Deleted Projects',
- 'Audit Log',
- 'Sessions',
- ]
- cy.findAllByRole('tab').should('have.length', tabs.length)
- tabs.forEach(tabName => {
- cy.findByRole('tab', { name: tabName }).click()
- })
- })
- describe('user info tab', function () {
- beforeEach(function () {
- cy.findByRole('tab', { name: 'User Info' }).click()
- })
- it('displays required sections', function () {
- // not exhaustive list, checks the tab content is rendered
- cy.findByRole('heading', { name: 'Profile' })
- cy.findByRole('heading', { name: 'Editor Settings' })
- })
- it('should not display SaaS-only sections', function () {
- cy.findByLabelText('Referred User Count').should('not.exist')
- cy.findByRole('heading', { name: /Split Test Assignments/ }).should(
- 'not.exist'
- )
- cy.findByRole('heading', { name: 'Experimental Features' }).should(
- 'not.exist'
- )
- cy.findByRole('heading', { name: 'Service Integration' }).should(
- 'not.exist'
- )
- cy.findByRole('heading', { name: 'SSO Integrations' }).should(
- 'not.exist'
- )
- cy.findByRole('heading', { name: 'Security' }).should('not.exist')
- })
- })
- it('transfer project ownership', function () {
- cy.log("access project admin through owners' project list")
- cy.findByRole('tablist').within(() => {
- cy.findByRole('tab', { name: 'Projects' }).click()
- })
- cy.findByRole('link', { name: testProjectName })
- .parent()
- .parent()
- .within(() => {
- cy.findByRole('link', { name: 'Project information' }).click()
- })
- cy.findByRole('button', { name: 'Transfer Ownership' }).click()
- cy.findByRole('dialog').within(() => {
- cy.findByRole('heading', { name: 'Transfer Ownership of Project' })
- cy.findByRole('button', { name: 'Find' }).should('be.disabled')
- cy.findByRole('button', { name: 'Confirm' }).should('be.disabled')
- cy.findByPlaceholderText('User ID or Email').type(user2)
- cy.findByRole('button', { name: 'Find' }).should('not.be.disabled')
- cy.findByRole('button', { name: 'Find' }).click()
- cy.findByText('Transfer project to this user?')
- cy.findByRole('cell', { name: 'ID' })
- cy.findByRole('cell', { name: 'Name' })
- cy.findByRole('cell', { name: 'Email' })
- cy.findByRole('cell', { name: user2 })
- cy.findByRole('button', { name: 'Confirm' }).should('not.be.disabled')
- cy.findByRole('button', { name: 'Confirm' }).click()
- })
- cy.log('check the project is displayed in the new owner projects tab')
- cy.findByPlaceholderText('Search users by email or id…').type(
- user2 + '{enter}'
- )
- cy.findByRole('link', { name: user2 }).click()
- cy.findByRole('tablist').within(() => {
- cy.findByRole('tab', { name: 'Projects' }).click()
- })
- cy.findByRole('link', { name: testProjectName })
- .parent()
- .parent()
- .within(() => {
- cy.findByRole('link', { name: 'Project information' }).click()
- })
- })
- })
- describe('project page', function () {
- beforeEach(function () {
- login(admin)
- cy.visit(`/admin/project/${testProjectId}`)
- })
- it('displays expected tabs', function () {
- const tabs = ['Project Info', 'Deleted Docs', 'Audit Log']
- cy.findAllByRole('tab').should('have.length', tabs.length)
- tabs.forEach(tabName => {
- cy.findByRole('tab', { name: tabName }).click()
- })
- })
- })
- it('restore deleted projects', function () {
- login(user1)
- cy.visit('/project')
- cy.log('select project to delete')
- findProjectRow(deletedProjectName).within(() =>
- cy
- .findByRole('checkbox', { name: `Select ${deletedProjectName}` })
- .first()
- .check()
- )
- cy.log('delete project')
- findProjectRow(deletedProjectName).within(() =>
- cy.findByRole('button', { name: 'Trash' }).click()
- )
- cy.findByRole('button', { name: 'Confirm' }).click()
- cy.findByRole('link', { name: deletedProjectName }).should('not.exist')
- cy.log('navigate to thrashed projects and delete the project')
- cy.findByRole('navigation', {
- name: 'Project categories and tags',
- })
- .findByRole('button', { name: 'Trashed projects' })
- .click()
- findProjectRow(deletedProjectName).within(() =>
- cy.findByRole('button', { name: 'Delete' }).click()
- )
- cy.findByRole('button', { name: 'Confirm' }).click()
- cy.findByRole('link', { name: deletedProjectName }).should('not.exist')
- cy.log('login as an admin and navigate to the deleted project')
- login(admin)
- cy.visit('/admin/user')
- cy.findByPlaceholderText('Search users by email or id…').type(
- user1 + '{enter}'
- )
- cy.findByRole('link', { name: user1 }).click()
- cy.findByRole('tab', { name: 'Deleted Projects' }).click()
- cy.findByRole('link', { name: deletedProjectName }).click()
- cy.log('undelete the project')
- cy.findByRole('button', { name: 'Undelete' }).click()
- cy.findByRole('button', { name: 'Undelete' }).should('not.exist')
- cy.url().should('contain', `/admin/project/${projectToDeleteId}`)
- cy.log('login as the user and verify the project is restored')
- login(user1)
- cy.visit('/project')
- cy.findByRole('navigation', {
- name: 'Project categories and tags',
- })
- .findByRole('button', { name: 'Trashed projects' })
- .click()
- cy.findByRole('link', { name: `${deletedProjectName} (Restored)` })
- })
- })
- })
|