Skip to content

Commit

Permalink
πŸ’š fix cypress test (links)
Browse files Browse the repository at this point in the history
add isolateTest command

Signed-off-by: Vinicius Reis <vinicius.reis@nextcloud.com>
  • Loading branch information
Vinicius Reis committed Sep 30, 2022
1 parent 1d49a82 commit 33f4bf0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
25 changes: 18 additions & 7 deletions cypress/e2e/links.spec.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import { initUserAndFiles, randHash } from '../utils/index.js'

const randUser = randHash()
const fileName = 'test.md'
const fileName = 'empty.md'

describe('test link marks', function() {
before(function() {
initUserAndFiles(randUser, fileName)
initUserAndFiles(randUser)
})

beforeEach(function() {
cy.login(randUser, 'password', {
cy.login(randUser, 'password')

cy.isolateTest({
sourceFile: fileName,
onBeforeLoad(win) {
cy.stub(win, 'open')
.as('winOpen')
},
})

return cy.openFile(fileName)
return cy.openFile(fileName, { force: true })
})

describe('autolink', function() {
beforeEach(() => cy.clearContent())
it('with protocol', () => {
cy.getFile(fileName)
.then($el => {
const id = $el.data('id')

const link = `${Cypress.env('baseUrl')}/file-name?fileId=${id}`
const link = `${Cypress.env('baseUrl')}/file-name?fileId=${id} `
cy.getContent()
.type(link)

Expand All @@ -42,11 +44,20 @@ describe('test link marks', function() {

it('whithout protocol', () => {
cy.getContent()
.type('google.com')
.type('google.com{enter}')

cy.getContent()
.find('a[href*="google.com"]')
.should('not.exist')
})

it('whithout space', () => {
cy.getContent()
.type('https://nextcloud.com')

cy.getContent()
.find('a[href*="nextcloud.com"]')
.should('not.exist')
})
})
})
15 changes: 15 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ Cypress.Commands.add('shareFileToUser', (userId, password, path, targetUserId) =
})
})

Cypress.Commands.add('isolateTest', ({ sourceFile = 'text.md', targetFile = null, onBeforeLoad } = {}) => {
targetFile = targetFile || sourceFile

const retry = cy.state('test').currentRetry()
const folderName = retry
? `${Cypress.currentTest.title} (${retry})`
: Cypress.currentTest.title

cy.createFolder(folderName)
cy.uploadFile(sourceFile, 'text/markdown', `${encodeURIComponent(folderName)}/${targetFile}`)

return cy.visit(`apps/files?dir=/${encodeURIComponent(folderName)}`, { onBeforeLoad })
.then(() => ({ folderName, fileName: targetFile }))
})

Cypress.Commands.add('shareFile', (path, options = {}) => {
return cy.window().then(async window => {
try {
Expand Down

0 comments on commit 33f4bf0

Please sign in to comment.