[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:
Jakob Ackermann
2025-02-25 14:31:44 +00:00
committed by Copybot
parent 08ee37afc1
commit a26290018c
7 changed files with 54 additions and 24 deletions

View File

@@ -127,8 +127,12 @@ describe('admin panel', function () {
testProjectName = `project-${uuid()}`
deletedProjectName = `deleted-project-${uuid()}`
login(user1)
createProject(testProjectName).then(id => (testProjectId = id))
createProject(deletedProjectName).then(id => (projectToDeleteId = id))
createProject(testProjectName, { open: false }).then(
id => (testProjectId = id)
)
createProject(deletedProjectName, { open: false }).then(
id => (projectToDeleteId = id)
)
})
describe('manage site', () => {

View File

@@ -50,9 +50,10 @@ describe('Project creation and compilation', function () {
const targetProjectName = `${sourceProjectName}-target`
login('user@example.com')
createProject(sourceProjectName, { type: 'Example Project' }).as(
'sourceProjectId'
)
createProject(sourceProjectName, {
type: 'Example Project',
open: false,
}).as('sourceProjectId')
createProject(targetProjectName)
// 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 targetProjectName = `${sourceProjectName}-target`
login('user@example.com')
createProject(sourceProjectName, { type: 'Example Project' }).as(
'sourceProjectId'
)
createProject(sourceProjectName, {
type: 'Example Project',
open: false,
}).as('sourceProjectId')
createProject(targetProjectName).as('targetProjectId')
// link the image from `projectName` into this project

View File

@@ -184,9 +184,6 @@ describe('editor', () => {
login('user@example.com')
cy.visit(`/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', () => {

View File

@@ -122,7 +122,7 @@ describe('git-bridge', function () {
let projectName: string
beforeEach(() => {
projectName = uuid()
createProject(projectName).as('projectId')
createProject(projectName, { open: false }).as('projectId')
})
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', () => {
openProjectByName(projectName)
enableLinkSharing().then(({ linkSharingReadAndWrite }) => {
const email = 'collaborator-link-rw@example.com'
login(email)
@@ -168,6 +169,7 @@ describe('git-bridge', function () {
})
it('should expose r/o interface to link-sharing r/o collaborator', () => {
openProjectByName(projectName)
enableLinkSharing().then(({ linkSharingReadOnly }) => {
const email = 'collaborator-link-ro@example.com'
login(email)

View File

@@ -1,14 +1,17 @@
import { login } from './login'
import { openEmail } from './email'
import { v4 as uuid } from 'uuid'
export function createProject(
name: string,
{
type = 'Blank Project',
newProjectButtonMatcher = /new project/i,
open = true,
}: {
type?: 'Blank Project' | 'Example Project'
newProjectButtonMatcher?: RegExp
open?: boolean
} = {}
): Cypress.Chainable<string> {
cy.url().then(url => {
@@ -16,6 +19,22 @@ export function createProject(
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()
// FIXME: This should only look in the left menu
cy.findAllByText(type).first().click()
@@ -23,12 +42,18 @@ export function createProject(
cy.get('input').type(name)
cy.findByText('Create').click()
})
cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
waitForMainDocToLoad()
return cy
.url()
.should('match', /\/project\/[a-fA-F0-9]{24}/)
.then(url => url.split('/').pop())
if (open) {
cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
waitForMainDocToLoad()
return cy
.url()
.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) {
@@ -64,6 +89,7 @@ export function openProjectViaInviteNotification(projectName: string) {
})
cy.findByText('Open Project').click()
cy.url().should('match', /\/project\/[a-fA-F0-9]{24}/)
waitForMainDocToLoad()
}
function shareProjectByEmail(
@@ -74,8 +100,8 @@ function shareProjectByEmail(
openProjectByName(projectName)
cy.findByText('Share').click()
cy.findByRole('dialog').within(() => {
cy.get('input').type(`${email},`)
cy.get('input')
cy.findByLabelText('Add people', { selector: 'input' }).type(`${email},`)
cy.findByLabelText('Add people', { selector: 'input' })
.parents('form')
.within(() => cy.findByText('Can edit').parent().select(level))
cy.findByText('Invite').click({ force: true })
@@ -115,6 +141,7 @@ export function shareProjectByEmailAndAcceptInviteViaEmail(
cy.findByText(/user would like you to join/)
cy.contains(new RegExp(`You are accepting this invite as ${email}`))
cy.findByText('Join Project').click()
waitForMainDocToLoad()
}
export function enableLinkSharing() {

View File

@@ -32,7 +32,7 @@ describe('Project List', () => {
before(() => {
login(REGULAR_USER)
createProject(projectName, { type: 'Example Project' })
createProject(projectName, { type: 'Example Project', open: false })
})
it('Can download project sources', () => {
@@ -89,8 +89,7 @@ describe('Project List', () => {
cy.log('create a separate project to filter')
const nonTaggedProjectName = `project-${uuid()}`
login(REGULAR_USER)
createProject(nonTaggedProjectName)
cy.visit('/project')
createProject(nonTaggedProjectName, { open: false })
cy.log('select project')
cy.get(`[aria-label="Select ${projectName}"]`).click()

View File

@@ -158,7 +158,6 @@ describe('Project Sharing', function () {
})
it('should grant the collaborator read access', () => {
openProjectByName(projectName)
expectFullReadOnlyAccess()
expectProjectDashboardEntry()
})