diff --git a/server-ce/test/admin.spec.ts b/server-ce/test/admin.spec.ts index be921d9c90..18b33c6932 100644 --- a/server-ce/test/admin.spec.ts +++ b/server-ce/test/admin.spec.ts @@ -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', () => { diff --git a/server-ce/test/create-and-compile-project.spec.ts b/server-ce/test/create-and-compile-project.spec.ts index 4298dd8774..afee2072b5 100644 --- a/server-ce/test/create-and-compile-project.spec.ts +++ b/server-ce/test/create-and-compile-project.spec.ts @@ -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 diff --git a/server-ce/test/editor.spec.ts b/server-ce/test/editor.spec.ts index 005a701c5c..02f4f65735 100644 --- a/server-ce/test/editor.spec.ts +++ b/server-ce/test/editor.spec.ts @@ -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', () => { diff --git a/server-ce/test/git-bridge.spec.ts b/server-ce/test/git-bridge.spec.ts index 87a293e771..ea7aea3e5b 100644 --- a/server-ce/test/git-bridge.spec.ts +++ b/server-ce/test/git-bridge.spec.ts @@ -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) diff --git a/server-ce/test/helpers/project.ts b/server-ce/test/helpers/project.ts index 76f996426f..09fdeca125 100644 --- a/server-ce/test/helpers/project.ts +++ b/server-ce/test/helpers/project.ts @@ -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 { 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() { diff --git a/server-ce/test/project-list.spec.ts b/server-ce/test/project-list.spec.ts index 1c98d20e2c..49e50bd350 100644 --- a/server-ce/test/project-list.spec.ts +++ b/server-ce/test/project-list.spec.ts @@ -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() diff --git a/server-ce/test/project-sharing.spec.ts b/server-ce/test/project-sharing.spec.ts index ebb3a7fe75..44887f2fd2 100644 --- a/server-ce/test/project-sharing.spec.ts +++ b/server-ce/test/project-sharing.spec.ts @@ -158,7 +158,6 @@ describe('Project Sharing', function () { }) it('should grant the collaborator read access', () => { - openProjectByName(projectName) expectFullReadOnlyAccess() expectProjectDashboardEntry() })