overleaf/server-ce/test/project-list.spec.ts
Jakob Ackermann 245473c1ac [server-pro] tests: backport changes from SaaS E2E tests (#23921)
* [server-pro] tests: add helper for gitURL

* [server-pro] tests: avoid hard-coding URL scheme/origin

* [server-pro] tests: fix typo in query selector

* [server-pro] tests: fix spelling of GitHub

* [server-pro] tests: double down on matching email in body

* [server-pro] tests: speed up session resumption

* [server-pro] tests: use a single project in editor spec

* [server-pro] drop check on started recompile

The labels changed between versions and making it configurable is too
verbose.

GitOrigin-RevId: d1ace3b534f28c65b8e20c808bac12268f26fa4d
2025-02-27 09:06:03 +00:00

106 lines
3.6 KiB
TypeScript

import { ensureUserExists, login } from './helpers/login'
import { createProject } from './helpers/project'
import { isExcludedBySharding, startWith } from './helpers/config'
import { v4 as uuid } from 'uuid'
const WITHOUT_PROJECTS_USER = 'user-without-projects@example.com'
const REGULAR_USER = 'user@example.com'
describe('Project List', () => {
if (isExcludedBySharding('PRO_DEFAULT_2')) return
startWith({ pro: true })
const findProjectRow = (projectName: string) => {
cy.log('find project row')
return cy.findByText(projectName).parent().parent()
}
describe('user with no projects', () => {
ensureUserExists({ email: WITHOUT_PROJECTS_USER })
it("'Import from GitHub' is not displayed in the welcome page", () => {
login(WITHOUT_PROJECTS_USER)
cy.visit('/project')
cy.findByText('Create a new project').click()
cy.findByText(/Import from GitHub/i).should('not.exist')
})
})
describe('user with projects', () => {
const projectName = `test-project-${uuid()}`
ensureUserExists({ email: REGULAR_USER })
before(() => {
login(REGULAR_USER)
createProject(projectName, { type: 'Example Project', open: false })
})
beforeEach(function () {
login(REGULAR_USER)
cy.visit('/project')
})
it('Can download project sources', () => {
findProjectRow(projectName).within(() =>
cy.findByRole('button', { name: 'Download .zip file' }).click()
)
cy.task('readFileInZip', {
pathToZip: `cypress/downloads/${projectName}.zip`,
fileToRead: 'main.tex',
}).should('contain', 'Your introduction goes here')
})
it('Can download project PDF', () => {
findProjectRow(projectName).within(() =>
cy.findByRole('button', { name: 'Download PDF' }).click()
)
const pdfName = projectName.replaceAll('-', '_')
cy.task('readPdf', `cypress/downloads/${pdfName}.pdf`).should(
'contain',
'Your introduction goes here'
)
})
it('can assign and remove tags to projects', () => {
const tagName = uuid().slice(0, 7) // long tag names are truncated in the UI, which affects selectors
cy.log('select project')
cy.get(`[aria-label="Select ${projectName}"]`).click()
cy.log('add tag to project')
cy.get('button[aria-label="Tags"]').click()
cy.findByText('Create new tag').click()
cy.get('input[name="new-tag-form-name"]').type(`${tagName}{enter}`)
cy.get(`button[aria-label="Select tag ${tagName}"]`) // tag label in project row
cy.log('remove tag')
cy.get(`button[aria-label="Remove tag ${tagName}"]`)
.first()
.click({ force: true })
cy.get(`button[aria-label="Select tag ${tagName}"]`).should('not.exist')
})
it('can filter by tag', () => {
cy.log('create a separate project to filter')
const nonTaggedProjectName = `project-${uuid()}`
login(REGULAR_USER)
createProject(nonTaggedProjectName, { open: false })
cy.log('select project')
cy.get(`[aria-label="Select ${projectName}"]`).click()
cy.log('add tag to project')
const tagName = uuid().slice(0, 7) // long tag names are truncated in the UI, which affects selectors
cy.get('button[aria-label="Tags"]').click()
cy.findByText('Create new tag').click()
cy.get('input[name="new-tag-form-name"]').type(`${tagName}{enter}`)
cy.log(
'check the non-tagged project is filtered out after clicking the tag'
)
cy.findByText(nonTaggedProjectName).should('exist')
cy.get('button').contains(tagName).click({ force: true })
cy.findByText(nonTaggedProjectName).should('not.exist')
})
})
})