mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
[server-pro] tests: avoid opening editor if not needed for test (#23875)
* [server-pro] tests: avoid opening editor if not needed for test * [server-pro] tests: use intercept to avoid opening editor page Co-authored-by: Alf Eaton <alf.eaton@overleaf.com> * [server-pro] tests: use times option in intercept Co-authored-by: Alf Eaton <alf.eaton@overleaf.com> --------- Co-authored-by: Alf Eaton <alf.eaton@overleaf.com> GitOrigin-RevId: 9530d1f5b06766fec70631da47d8b1049b59ead5
This commit is contained in:
committed by
Copybot
co-authored by
Alf Eaton
parent
08ee37afc1
commit
a26290018c
@@ -127,8 +127,12 @@ describe('admin panel', function () {
|
|||||||
testProjectName = `project-${uuid()}`
|
testProjectName = `project-${uuid()}`
|
||||||
deletedProjectName = `deleted-project-${uuid()}`
|
deletedProjectName = `deleted-project-${uuid()}`
|
||||||
login(user1)
|
login(user1)
|
||||||
createProject(testProjectName).then(id => (testProjectId = id))
|
createProject(testProjectName, { open: false }).then(
|
||||||
createProject(deletedProjectName).then(id => (projectToDeleteId = id))
|
id => (testProjectId = id)
|
||||||
|
)
|
||||||
|
createProject(deletedProjectName, { open: false }).then(
|
||||||
|
id => (projectToDeleteId = id)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('manage site', () => {
|
describe('manage site', () => {
|
||||||
|
|||||||
@@ -50,9 +50,10 @@ describe('Project creation and compilation', function () {
|
|||||||
const targetProjectName = `${sourceProjectName}-target`
|
const targetProjectName = `${sourceProjectName}-target`
|
||||||
login('user@example.com')
|
login('user@example.com')
|
||||||
|
|
||||||
createProject(sourceProjectName, { type: 'Example Project' }).as(
|
createProject(sourceProjectName, {
|
||||||
'sourceProjectId'
|
type: 'Example Project',
|
||||||
)
|
open: false,
|
||||||
|
}).as('sourceProjectId')
|
||||||
createProject(targetProjectName)
|
createProject(targetProjectName)
|
||||||
|
|
||||||
// link the image from `projectName` into this project
|
// link the image from `projectName` into this project
|
||||||
@@ -77,9 +78,10 @@ describe('Project creation and compilation', function () {
|
|||||||
const sourceProjectName = `test-project-${Date.now()}`
|
const sourceProjectName = `test-project-${Date.now()}`
|
||||||
const targetProjectName = `${sourceProjectName}-target`
|
const targetProjectName = `${sourceProjectName}-target`
|
||||||
login('user@example.com')
|
login('user@example.com')
|
||||||
createProject(sourceProjectName, { type: 'Example Project' }).as(
|
createProject(sourceProjectName, {
|
||||||
'sourceProjectId'
|
type: 'Example Project',
|
||||||
)
|
open: false,
|
||||||
|
}).as('sourceProjectId')
|
||||||
createProject(targetProjectName).as('targetProjectId')
|
createProject(targetProjectName).as('targetProjectId')
|
||||||
|
|
||||||
// link the image from `projectName` into this project
|
// link the image from `projectName` into this project
|
||||||
|
|||||||
@@ -184,9 +184,6 @@ describe('editor', () => {
|
|||||||
login('user@example.com')
|
login('user@example.com')
|
||||||
cy.visit(`/project`)
|
cy.visit(`/project`)
|
||||||
createProject(`project-${uuid()}`, { type: 'Example Project' })
|
createProject(`project-${uuid()}`, { type: 'Example Project' })
|
||||||
// wait until the main document is rendered
|
|
||||||
cy.findByText(/Loading/).should('not.exist')
|
|
||||||
cy.findByText(/Your Paper/)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('renders jpg', () => {
|
it('renders jpg', () => {
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ describe('git-bridge', function () {
|
|||||||
let projectName: string
|
let projectName: string
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
projectName = uuid()
|
projectName = uuid()
|
||||||
createProject(projectName).as('projectId')
|
createProject(projectName, { open: false }).as('projectId')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should expose r/w interface to owner', () => {
|
it('should expose r/w interface to owner', () => {
|
||||||
@@ -154,6 +154,7 @@ describe('git-bridge', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should expose r/w interface to link-sharing r/w collaborator', () => {
|
it('should expose r/w interface to link-sharing r/w collaborator', () => {
|
||||||
|
openProjectByName(projectName)
|
||||||
enableLinkSharing().then(({ linkSharingReadAndWrite }) => {
|
enableLinkSharing().then(({ linkSharingReadAndWrite }) => {
|
||||||
const email = 'collaborator-link-rw@example.com'
|
const email = 'collaborator-link-rw@example.com'
|
||||||
login(email)
|
login(email)
|
||||||
@@ -168,6 +169,7 @@ describe('git-bridge', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should expose r/o interface to link-sharing r/o collaborator', () => {
|
it('should expose r/o interface to link-sharing r/o collaborator', () => {
|
||||||
|
openProjectByName(projectName)
|
||||||
enableLinkSharing().then(({ linkSharingReadOnly }) => {
|
enableLinkSharing().then(({ linkSharingReadOnly }) => {
|
||||||
const email = 'collaborator-link-ro@example.com'
|
const email = 'collaborator-link-ro@example.com'
|
||||||
login(email)
|
login(email)
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
import { login } from './login'
|
import { login } from './login'
|
||||||
import { openEmail } from './email'
|
import { openEmail } from './email'
|
||||||
|
import { v4 as uuid } from 'uuid'
|
||||||
|
|
||||||
export function createProject(
|
export function createProject(
|
||||||
name: string,
|
name: string,
|
||||||
{
|
{
|
||||||
type = 'Blank Project',
|
type = 'Blank Project',
|
||||||
newProjectButtonMatcher = /new project/i,
|
newProjectButtonMatcher = /new project/i,
|
||||||
|
open = true,
|
||||||
}: {
|
}: {
|
||||||
type?: 'Blank Project' | 'Example Project'
|
type?: 'Blank Project' | 'Example Project'
|
||||||
newProjectButtonMatcher?: RegExp
|
newProjectButtonMatcher?: RegExp
|
||||||
|
open?: boolean
|
||||||
} = {}
|
} = {}
|
||||||
): Cypress.Chainable<string> {
|
): Cypress.Chainable<string> {
|
||||||
cy.url().then(url => {
|
cy.url().then(url => {
|
||||||
@@ -16,6 +19,22 @@ export function createProject(
|
|||||||
cy.visit('/project')
|
cy.visit('/project')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
const interceptId = uuid()
|
||||||
|
let projectId = ''
|
||||||
|
if (!open) {
|
||||||
|
cy.then(() => {
|
||||||
|
// Register intercept just before creating the project, otherwise we might
|
||||||
|
// intercept a request from a prior createProject invocation.
|
||||||
|
cy.intercept(
|
||||||
|
{ method: 'GET', url: /\/project\/[a-fA-F0-9]{24}$/, times: 1 },
|
||||||
|
req => {
|
||||||
|
projectId = req.url.split('/').pop()!
|
||||||
|
// Redirect back to the project dashboard, effectively reload the page.
|
||||||
|
req.redirect('/project')
|
||||||
|
}
|
||||||
|
).as(interceptId)
|
||||||
|
})
|
||||||
|
}
|
||||||
cy.findAllByRole('button').contains(newProjectButtonMatcher).click()
|
cy.findAllByRole('button').contains(newProjectButtonMatcher).click()
|
||||||
// FIXME: This should only look in the left menu
|
// FIXME: This should only look in the left menu
|
||||||
cy.findAllByText(type).first().click()
|
cy.findAllByText(type).first().click()
|
||||||
@@ -23,12 +42,18 @@ export function createProject(
|
|||||||
cy.get('input').type(name)
|
cy.get('input').type(name)
|
||||||
cy.findByText('Create').click()
|
cy.findByText('Create').click()
|
||||||
})
|
})
|
||||||
cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
|
if (open) {
|
||||||
waitForMainDocToLoad()
|
cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
|
||||||
return cy
|
waitForMainDocToLoad()
|
||||||
.url()
|
return cy
|
||||||
.should('match', /\/project\/[a-fA-F0-9]{24}/)
|
.url()
|
||||||
.then(url => url.split('/').pop())
|
.should('match', /\/project\/[a-fA-F0-9]{24}/)
|
||||||
|
.then(url => url.split('/').pop())
|
||||||
|
} else {
|
||||||
|
const alias = `@${interceptId}` // IDEs do not like computed values in cy.wait().
|
||||||
|
cy.wait(alias)
|
||||||
|
return cy.then(() => projectId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openProjectByName(projectName: string) {
|
export function openProjectByName(projectName: string) {
|
||||||
@@ -64,6 +89,7 @@ export function openProjectViaInviteNotification(projectName: string) {
|
|||||||
})
|
})
|
||||||
cy.findByText('Open Project').click()
|
cy.findByText('Open Project').click()
|
||||||
cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
|
cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
|
||||||
|
waitForMainDocToLoad()
|
||||||
}
|
}
|
||||||
|
|
||||||
function shareProjectByEmail(
|
function shareProjectByEmail(
|
||||||
@@ -74,8 +100,8 @@ function shareProjectByEmail(
|
|||||||
openProjectByName(projectName)
|
openProjectByName(projectName)
|
||||||
cy.findByText('Share').click()
|
cy.findByText('Share').click()
|
||||||
cy.findByRole('dialog').within(() => {
|
cy.findByRole('dialog').within(() => {
|
||||||
cy.get('input').type(`${email},`)
|
cy.findByLabelText('Add people', { selector: 'input' }).type(`${email},`)
|
||||||
cy.get('input')
|
cy.findByLabelText('Add people', { selector: 'input' })
|
||||||
.parents('form')
|
.parents('form')
|
||||||
.within(() => cy.findByText('Can edit').parent().select(level))
|
.within(() => cy.findByText('Can edit').parent().select(level))
|
||||||
cy.findByText('Invite').click({ force: true })
|
cy.findByText('Invite').click({ force: true })
|
||||||
@@ -115,6 +141,7 @@ export function shareProjectByEmailAndAcceptInviteViaEmail(
|
|||||||
cy.findByText(/user would like you to join/)
|
cy.findByText(/user would like you to join/)
|
||||||
cy.contains(new RegExp(`You are accepting this invite as ${email}`))
|
cy.contains(new RegExp(`You are accepting this invite as ${email}`))
|
||||||
cy.findByText('Join Project').click()
|
cy.findByText('Join Project').click()
|
||||||
|
waitForMainDocToLoad()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function enableLinkSharing() {
|
export function enableLinkSharing() {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ describe('Project List', () => {
|
|||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
login(REGULAR_USER)
|
login(REGULAR_USER)
|
||||||
createProject(projectName, { type: 'Example Project' })
|
createProject(projectName, { type: 'Example Project', open: false })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Can download project sources', () => {
|
it('Can download project sources', () => {
|
||||||
@@ -89,8 +89,7 @@ describe('Project List', () => {
|
|||||||
cy.log('create a separate project to filter')
|
cy.log('create a separate project to filter')
|
||||||
const nonTaggedProjectName = `project-${uuid()}`
|
const nonTaggedProjectName = `project-${uuid()}`
|
||||||
login(REGULAR_USER)
|
login(REGULAR_USER)
|
||||||
createProject(nonTaggedProjectName)
|
createProject(nonTaggedProjectName, { open: false })
|
||||||
cy.visit('/project')
|
|
||||||
|
|
||||||
cy.log('select project')
|
cy.log('select project')
|
||||||
cy.get(`[aria-label="Select ${projectName}"]`).click()
|
cy.get(`[aria-label="Select ${projectName}"]`).click()
|
||||||
|
|||||||
@@ -158,7 +158,6 @@ describe('Project Sharing', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should grant the collaborator read access', () => {
|
it('should grant the collaborator read access', () => {
|
||||||
openProjectByName(projectName)
|
|
||||||
expectFullReadOnlyAccess()
|
expectFullReadOnlyAccess()
|
||||||
expectProjectDashboardEntry()
|
expectProjectDashboardEntry()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user