Update selectors to improve CE test stability (#28096)

* Update selectors to improve test stability

* Update selectors to improve test stability

* Use plain string matchers

* Fix test

* [monorepo] use plain string matchers everywhere

* [web] remove Kb/ prefix from title of learn wiki links

---------

Co-authored-by: Jakob Ackermann <jakob.ackermann@overleaf.com>
GitOrigin-RevId: 12e13c39822795338a3bee20236454f9948e6221
This commit is contained in:
Rebeka Dekany
2025-09-02 08:04:56 +00:00
committed by Copybot
co-authored by Jakob Ackermann
parent bd4130c147
commit 97d8f73749
24 changed files with 736 additions and 476 deletions
+98 -46
View File
@@ -10,11 +10,14 @@ import { v4 as uuid } from 'uuid'
import { beforeWithReRunOnTestRetry } from './helpers/beforeWithReRunOnTestRetry'
import { prepareWaitForNextCompileSlot } from './helpers/compile'
const USER = 'user@example.com'
const COLLABORATOR = 'collaborator@example.com'
describe('editor', () => {
if (isExcludedBySharding('PRO_DEFAULT_1')) return
startWith({ pro: true })
ensureUserExists({ email: 'user@example.com' })
ensureUserExists({ email: 'collaborator@example.com' })
ensureUserExists({ email: USER })
ensureUserExists({ email: COLLABORATOR })
let projectName: string
let projectId: string
@@ -22,7 +25,7 @@ describe('editor', () => {
let waitForCompileRateLimitCoolOff: (fn: () => void) => void
beforeWithReRunOnTestRetry(function () {
projectName = `project-${uuid()}`
login('user@example.com')
login(USER)
createProject(projectName, { type: 'Example project', open: false }).then(
id => (projectId = id)
)
@@ -31,7 +34,7 @@ describe('editor', () => {
})
beforeEach(() => {
login('user@example.com')
login(USER)
waitForCompileRateLimitCoolOff(() => {
openProjectById(projectId)
})
@@ -40,9 +43,16 @@ describe('editor', () => {
describe('spelling', function () {
function changeSpellCheckLanguageTo(lng: string) {
cy.log(`change project language to '${lng}'`)
cy.get('button').contains('Menu').click()
cy.get('select[id=settings-menu-spellCheckLanguage]').select(lng)
cy.get('[id="left-menu"]').type('{esc}') // close left menu
cy.findByRole('navigation', {
name: 'Project actions',
})
.findByRole('button', { name: 'Menu' })
.click()
cy.findByRole('dialog').within(() => {
cy.findByLabelText('Spell check').select(lng)
})
cy.get('body').type('{esc}')
}
afterEach(function () {
@@ -70,20 +80,28 @@ describe('editor', () => {
cy.findByText(word).should('not.have.class', 'ol-cm-spelling-error')
cy.log('remove word from dictionary')
cy.get('button').contains('Menu').click()
cy.get('button#dictionary-settings').contains('Edit').click()
cy.get('[id="dictionary-modal"]').within(() => {
cy.findByRole('navigation', {
name: 'Project actions',
})
.findByRole('button', { name: 'Menu' })
.click()
cy.findByRole('dialog').within(() => {
cy.findByLabelText('Dictionary').click()
})
cy.findByTestId('dictionary-modal').within(() => {
cy.findByText(word)
.parent()
.within(() => cy.get('button').click())
.within(() =>
cy.findByRole('button', { name: 'Remove from dictionary' }).click()
)
// the modal has 2 close buttons, this ensures the one with the visible label is
// clicked, otherwise it would need `force: true`
cy.get('.btn').contains('Close').click()
cy.contains('button', /close/i).click()
})
cy.log('close left panel')
cy.get('[id="left-menu"]').type('{esc}')
cy.findByTestId('left-menu').type('{esc}')
cy.log('rewrite word to force spelling error')
cy.get('.cm-line').type('{selectAll}{del}' + word + '{enter}')
@@ -94,7 +112,11 @@ describe('editor', () => {
describe('editor', () => {
it('renders jpg', () => {
cy.findByTestId('file-tree').findByText('frog.jpg').click()
cy.findByRole('navigation', {
name: 'Project files and outline',
})
.findByRole('treeitem', { name: 'frog.jpg' })
.click()
cy.get('[alt="frog.jpg"]')
.should('be.visible')
.and('have.prop', 'naturalWidth')
@@ -108,7 +130,7 @@ describe('editor', () => {
force: true,
})
cy.get('button').contains('𝜉').click()
cy.findByRole('textbox', { name: /Source Editor editing/i }).should(
cy.findByRole('textbox', { name: 'Source Editor editing' }).should(
'contain.text',
'\\xi'
)
@@ -120,23 +142,27 @@ describe('editor', () => {
describe('add new file to project', () => {
beforeEach(() => {
cy.get('button').contains('New file').click({ force: true })
cy.findByRole('button', { name: 'New file' }).click()
})
testNewFileUpload()
it('should not display import from URL', () => {
cy.findByText('From external URL').should('not.exist')
cy.findByRole('button', { name: 'From external URL' }).should('not.exist')
})
})
describe('left menu', () => {
beforeEach(() => {
cy.get('button').contains('Menu').click()
cy.findByRole('navigation', {
name: 'Project actions',
})
.findByRole('button', { name: 'Menu' })
.click()
})
it('can download project sources', () => {
cy.get('a').contains('Source').click()
cy.findByRole('link', { name: 'Source' }).click()
const zipName = projectName.replaceAll('-', '_')
cy.task('readFileInZip', {
pathToZip: `cypress/downloads/${zipName}.zip`,
@@ -146,10 +172,12 @@ describe('editor', () => {
it('can download project PDF', () => {
cy.log('ensure project is compiled')
cy.get('.pdf-viewer').should('contain.text', 'Your Paper')
cy.get('.nav-downloads').within(() => {
cy.findByText('PDF').click()
cy.findByRole('region', { name: 'PDF preview and logs' }).should(
'contain.text',
'Your Paper'
)
cy.findByRole('dialog').within(() => {
cy.findByRole('link', { name: 'PDF' }).click()
const pdfName = projectName.replaceAll('-', '_')
cy.task('readPdf', `cypress/downloads/${pdfName}.pdf`).should(
'contain',
@@ -160,11 +188,13 @@ describe('editor', () => {
it('word count', () => {
cy.log('ensure project is compiled')
cy.get('.pdf-viewer').should('contain.text', 'Your Paper')
cy.findByRole('region', { name: 'PDF preview and logs' }).should(
'contain.text',
'Your Paper'
)
cy.findByRole('button', { name: 'Word Count' }).click()
cy.findByText('Word Count').click()
cy.get('#word-count-modal').within(() => {
cy.findByTestId('word-count-modal').within(() => {
cy.findByText('Total Words:')
cy.findByText('607')
cy.findByText('Headers:')
@@ -179,51 +209,73 @@ describe('editor', () => {
describe('layout selector', () => {
it('show editor only and switch between editor and pdf', () => {
cy.get('.pdf-viewer').should('be.visible')
cy.findByRole('region', { name: 'PDF preview and logs' }).should(
'be.visible'
)
cy.get('.cm-editor').should('be.visible')
cy.findByText('Layout').click()
cy.findByText('Editor only').click()
cy.findByRole('button', { name: 'Layout' }).click()
cy.findByRole('menu').within(() => {
cy.findByRole('menuitem', { name: /Editor only/ }).click()
})
cy.get('.pdf-viewer').should('not.be.visible')
cy.findByRole('region', { name: 'PDF preview and logs' }).should(
'not.be.visible'
)
cy.get('.cm-editor').should('be.visible')
cy.findByText('Switch to PDF').click()
cy.findByRole('button', { name: 'Switch to PDF' }).click()
cy.get('.pdf-viewer').should('be.visible')
cy.findByRole('region', { name: 'PDF preview and logs' }).should(
'be.visible'
)
cy.get('.cm-editor').should('not.be.visible')
cy.findByText('Switch to editor').click()
cy.findByRole('button', { name: 'Switch to editor' }).click()
cy.get('.pdf-viewer').should('not.be.visible')
cy.findByRole('region', { name: 'PDF preview and logs' }).should(
'not.be.visible'
)
cy.get('.cm-editor').should('be.visible')
})
it('show PDF only and go back to Editor & PDF', () => {
cy.get('.pdf-viewer').should('be.visible')
cy.findByRole('region', { name: 'PDF preview and logs' }).should(
'be.visible'
)
cy.get('.cm-editor').should('be.visible')
cy.findByText('Layout').click()
cy.findByText('PDF only').click()
cy.findByRole('button', { name: 'Layout' }).click()
cy.findByRole('menu').within(() => {
cy.findByRole('menuitem', { name: /PDF only/ }).click()
})
cy.get('.pdf-viewer').should('be.visible')
cy.findByRole('region', { name: 'PDF preview and logs' }).should(
'be.visible'
)
cy.get('.cm-editor').should('not.be.visible')
cy.findByText('Layout').click()
cy.findByText('Editor & PDF').click()
cy.findByRole('button', { name: 'Layout' }).click()
cy.findByRole('menu').within(() => {
cy.findByRole('menuitem', { name: 'Editor & PDF' }).click()
})
cy.get('.pdf-viewer').should('be.visible')
cy.findByRole('region', { name: 'PDF preview and logs' }).should(
'be.visible'
)
cy.get('.cm-editor').should('be.visible')
})
it('PDF in a separate tab (tests editor only)', () => {
cy.get('.pdf-viewer').should('be.visible')
cy.findByTestId('pdf-viewer').should('be.visible')
cy.get('.cm-editor').should('be.visible')
cy.findByText('Layout').click()
cy.findByText('PDF in separate tab').click()
cy.findByRole('button', { name: 'Layout' }).click()
cy.findByRole('menu').within(() => {
cy.findByRole('menuitem', { name: 'PDF in separate tab' }).click()
})
cy.get('.pdf-viewer').should('not.exist')
cy.findByTestId('pdf-viewer').should('not.exist')
cy.get('.cm-editor').should('be.visible')
})
})