Merge pull request #3563 from nextcloud/fix/cypress-flaky-sections-test

Fix/cypress flaky sections test
This commit is contained in:
Jonas 2022-12-12 12:38:16 +01:00 коммит произвёл GitHub
Родитель 9dd7dc6790 117d10db3c
Коммит 6b982bf1bd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 109 добавлений и 62 удалений

Просмотреть файл

@ -18,7 +18,6 @@ describe('table plugin', () => {
beforeEach(() => {
cy.login(user)
cy.visit('/apps/files')
cy.isolateTest({
sourceFile: fileName,

Просмотреть файл

@ -10,8 +10,6 @@ describe('test link marks', function() {
beforeEach(function() {
cy.login(user)
cy.visit('/apps/files')
cy.isolateTest({
sourceFile: fileName,
onBeforeLoad(win) {
@ -19,9 +17,7 @@ describe('test link marks', function() {
.as('winOpen')
},
})
cy.openFile(fileName, { force: true })
return cy.clearContent()
})
describe('link preview', function() {

Просмотреть файл

@ -1,4 +1,4 @@
import { initUserAndFiles, randUser } from '../utils/index.js'
import { randUser } from '../utils/index.js'
const user = randUser()
const fileName = 'empty.md'
@ -15,34 +15,25 @@ const clickOutline = () => {
.click()
}
let currentFolder
describe('Content Sections', () => {
before(function() {
initUserAndFiles(user, fileName)
cy.createUser(user)
})
beforeEach(function() {
cy.login(user, {
onBeforeLoad(win) {
cy.stub(win, 'open')
.as('winOpen')
},
cy.login(user)
cy.createTestFolder().then(folderName => {
currentFolder = folderName
cy.uploadFile(fileName, 'text/markdown', `${currentFolder}/${fileName}`)
})
cy.visit('/apps/files')
cy.isolateTest({
sourceFile: fileName,
onBeforeLoad(win) {
cy.stub(win, 'open')
.as('winOpen')
},
})
cy.openFile(fileName, { force: true })
return cy.clearContent()
})
describe('Heading anchors', () => {
it('Anchor exists', () => {
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
cy.getContent()
.type('# Heading\nText\n## Heading 2\nText\n## Heading 2')
.then(() => {
@ -58,7 +49,9 @@ describe('Content Sections', () => {
})
it('Anchor ID is updated', () => {
cy.clearContent()
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
cy.getContent()
.type('# Heading 1{enter}')
.then(() => {
cy.getContent()
@ -86,40 +79,24 @@ describe('Content Sections', () => {
})
})
it('Anchor scrolls into view', () => {
// Create link to top heading
cy.clearContent()
.type('{selectAll}{backspace}move top\n{selectAll}')
.then(() => {
cy.getSubmenuEntry('insert-link', 'insert-link-website')
.click()
.then(() => {
cy.getActionSubEntry('insert-link-input')
.find('input[type="text"]')
.type('#top{enter}')
})
})
// Insert content above link
it('scrolls anchor into view', () => {
cy.uploadFile('anchors.md', 'text/markdown', `${currentFolder}/anchors.md`)
cy.visitTestFolder()
cy.openFile('anchors.md')
cy.getContent()
.type('{moveToStart}\n{moveToStart}# top \n')
.type('lorem ipsum \n'.repeat(25))
.type('{moveToEnd}\n')
cy.getContent().find('h1#top')
.get('h2[id="bottom"]')
.should('not.be.inViewport')
// Click link and test view moved to anchor
cy.getContent()
.find('a:not(.heading-anchor)')
.find('a[href="#bottom"]:not(.heading-anchor)')
.click({ force: true })
.then(() => {
cy.getContent()
.get('h1[id="top"]')
.should('be.inViewport')
})
cy.getContent()
.get('h2[id="bottom"]')
.should('be.inViewport')
})
it('Can change heading level', () => {
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
// Issue #2868
cy.getContent()
.type('# Heading 1{enter}')
@ -149,6 +126,8 @@ describe('Content Sections', () => {
describe('Table of Contents', () => {
it('sidebar toc', () => {
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
cy.getContent()
.type('# T1 \n## T2 \n### T3 \n#### T4 \n##### T5 \n###### T6\n')
.then(refresh)
@ -177,8 +156,8 @@ describe('Content Sections', () => {
})
it('empty toc', () => {
refresh()
.then(() => cy.openFile(fileName, { force: true }))
cy.visitTestFolder()
cy.openFile(fileName, { force: true })
.then(clickOutline)
cy.getOutline()

Просмотреть файл

@ -0,0 +1,57 @@
# top
[move to bottom](#bottom)
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
lorem ipsum
[move to top](#top)
## Bottom

Просмотреть файл

@ -131,20 +131,36 @@ Cypress.Commands.add('shareFileToUser', (path, targetUser) => {
})
})
Cypress.Commands.add('isolateTest', ({ sourceFile = 'empty.md', targetFile = null, onBeforeLoad } = {}) => {
targetFile = targetFile || sourceFile
Cypress.Commands.add('testName', () => {
const retry = cy.state('test').currentRetry()
const folderName = retry
? `${Cypress.currentTest.title} (${retry})`
: Cypress.currentTest.title
return cy.wrap(folderName)
})
cy.createFolder(folderName)
cy.uploadFile(sourceFile, 'text/markdown', `${encodeURIComponent(folderName)}/${targetFile}`)
Cypress.Commands.add('createTestFolder', () => {
return cy.testName().then(folderName => {
cy.createFolder(folderName)
return cy.wrap(folderName)
})
})
window.__currentDirectory = folderName
return cy.visit(`apps/files?dir=/${encodeURIComponent(folderName)}`, { onBeforeLoad })
.then(() => ({ folderName, fileName: targetFile }))
Cypress.Commands.add('visitTestFolder', (visitOptions = {}) => {
return cy.testName().then(folderName => {
const url = `apps/files?dir=/${encodeURIComponent(folderName)}`
return cy.visit(url, visitOptions)
})
})
Cypress.Commands.add('isolateTest', ({ sourceFile = 'empty.md', targetFile = null, onBeforeLoad } = {}) => {
targetFile = targetFile || sourceFile
cy.createTestFolder().then(folderName => {
cy.uploadFile(sourceFile, 'text/markdown', `${encodeURIComponent(folderName)}/${targetFile}`)
window.__currentDirectory = folderName
return cy.visitTestFolder({ onBeforeLoad })
.then(() => ({ folderName, fileName: targetFile }))
})
})
Cypress.Commands.add('shareFile', (path, options = {}) => {