Skip to content

Commit

Permalink
test(cy): use createTestFolder() and `visitTestFolder()
Browse files Browse the repository at this point in the history
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Dec 17, 2023
1 parent 0c7a0e3 commit 1437501
Showing 1 changed file with 33 additions and 38 deletions.
71 changes: 33 additions & 38 deletions cypress/e2e/workspace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { randUser } from '../utils/index.js'
const user = randUser()

describe('Workspace', function() {
let currentFolder

before(function() {
cy.createUser(user, 'password')
Expand All @@ -36,17 +35,13 @@ describe('Workspace', function() {
// Make sure it's the default otherwise.
cy.modifyUser(user, 'language', 'en')
// isolate tests - each happens in its own folder
const retry = cy.state('test').currentRetry()
currentFolder = retry
? `${Cypress.currentTest.title} (${retry})`
: Cypress.currentTest.title
cy.createFolder(currentFolder)
cy.createTestFolder().as('testFolder')
})

it('Hides the workspace when switching to another folder', function() {
cy.uploadFile('test.md', 'text/markdown', `${currentFolder}/README.md`)
cy.createFolder(`${currentFolder}/subdirectory`)
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.uploadFile('test.md', 'text/markdown', `${this.testFolder}/README.md`)
cy.createFolder(`${this.testFolder}/subdirectory`)
cy.visitTestFolder()
cy.getFile('README.md')
cy.get('#rich-workspace .ProseMirror')
.should('contain', 'Hello world')
Expand All @@ -56,8 +51,8 @@ describe('Workspace', function() {
})

it('Hides the workspace when switching to another view', function() {
cy.uploadFile('test.md', 'text/markdown', `${currentFolder}/README.md`)
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.uploadFile('test.md', 'text/markdown', `${this.testFolder}/README.md`)
cy.visitTestFolder()
cy.getFile('README.md')
cy.get('#rich-workspace .ProseMirror')
.should('contain', 'Hello world')
Expand All @@ -68,15 +63,15 @@ describe('Workspace', function() {
})

it('adds a Readme.md', function() {
cy.createDescription(currentFolder)
cy.createDescription(this.testFolder)
openSidebar('Readme.md')
cy.get('#rich-workspace .text-editor .text-editor__wrapper')
.should('be.visible')
})

it('formats text', function() {
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.openWorkspace(currentFolder)
cy.visitTestFolder()
cy.openWorkspace(this.testFolder)
const buttons = [
['bold', 'strong'],
['italic', 'em'],
Expand All @@ -90,8 +85,8 @@ describe('Workspace', function() {
})

it('creates headings via submenu', function() {
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.openWorkspace(currentFolder).type('Heading')
cy.visitTestFolder()
cy.openWorkspace(this.testFolder).type('Heading')
cy.getContent().type('{selectall}')
;['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].forEach((heading) => {
const actionName = `headings-${heading}`
Expand All @@ -111,8 +106,8 @@ describe('Workspace', function() {
})

it('creates lists', function() {
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.openWorkspace(currentFolder).type('List me')
cy.visitTestFolder()
cy.openWorkspace(this.testFolder).type('List me')
cy.getContent().type('{selectall}')
;[
['unordered-list', 'ul'],
Expand All @@ -122,16 +117,16 @@ describe('Workspace', function() {
})

it('takes README.md into account', function() {
cy.uploadFile('test.md', 'text/markdown', `${Cypress.currentTest.title}/README.md`)
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.uploadFile('test.md', 'text/markdown', `${this.testFolder}/README.md`)
cy.visitTestFolder()
cy.getFile('README.md')
cy.get('#rich-workspace .ProseMirror')
.should('contain', 'Hello world')
})

it('emoji picker', () => {
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.openWorkspace(currentFolder)
cy.visitTestFolder()
cy.openWorkspace(this.testFolder)
.type('# Let\'s smile together{enter}## ')

cy.getMenuEntry('emoji-picker')
Expand All @@ -147,13 +142,13 @@ describe('Workspace', function() {
})

it('relative folder links', () => {
cy.createFolder(`${currentFolder}/sub-folder`)
cy.createFolder(`${currentFolder}/sub-folder/alpha`)
cy.createFolder(`${this.testFolder}/sub-folder`)
cy.createFolder(`${this.testFolder}/sub-folder/alpha`)

cy.uploadFile('test.md', 'text/markdown', `${currentFolder}/sub-folder/alpha/test.md`)
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.uploadFile('test.md', 'text/markdown', `${this.testFolder}/sub-folder/alpha/test.md`)
cy.visitTestFolder()

cy.openWorkspace(currentFolder)
cy.openWorkspace(this.testFolder)
.type('link me')
cy.getContent()
.type('{selectall}')
Expand All @@ -169,7 +164,7 @@ describe('Workspace', function() {
cy.getEditor()
.find('a')
.should('have.attr', 'href')
.and('contains', `dir=/${currentFolder}/sub-folder/alpha`)
.and('contains', `dir=/${this.testFolder}/sub-folder/alpha`)
.and('contains', '#relPath=sub-folder/alpha/test.md')

cy.getEditor()
Expand All @@ -190,8 +185,8 @@ describe('Workspace', function() {
const types = ['info', 'warn', 'error', 'success']

beforeEach(function() {
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.openWorkspace(currentFolder).type('Callout')
cy.visitTestFolder()
cy.openWorkspace(this.testFolder).type('Callout')
})
// eslint-disable-next-line cypress/no-async-tests
it('create callout', () => {
Expand Down Expand Up @@ -239,17 +234,17 @@ describe('Workspace', function() {
describe('localize', () => {
it('takes localized file name into account', function() {
cy.modifyUser(user, 'language', 'de_DE')
cy.uploadFile('test.md', 'text/markdown', `${Cypress.currentTest.title}/Anleitung.md`)
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.uploadFile('test.md', 'text/markdown', `${this.testFolder}/Anleitung.md`)
cy.visitTestFolder()
cy.getFile('Anleitung.md')
cy.get('#rich-workspace .ProseMirror')
.should('contain', 'Hello world')
})

it('ignores localized file name in other language', function() {
cy.modifyUser(user, 'language', 'fr')
cy.uploadFile('test.md', 'text/markdown', `${Cypress.currentTest.title}/Anleitung.md`)
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.uploadFile('test.md', 'text/markdown', `${this.testFolder}/Anleitung.md`)
cy.visitTestFolder()
cy.getFile('Anleitung.md')
})
})
Expand All @@ -265,21 +260,21 @@ describe('Workspace', function() {
}

beforeEach(() => {
cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`)
cy.visitTestFolder()
})

it('click', () => {
cy.openWorkspace(currentFolder).click()
cy.openWorkspace(this.testFolder).click()
checkContent()
})

it('enter', () => {
cy.openWorkspace(currentFolder).type('{enter}')
cy.openWorkspace(this.testFolder).type('{enter}')
checkContent()
})

it('spacebar', () => {
cy.openWorkspace(currentFolder)
cy.openWorkspace(this.testFolder)
.trigger('keyup', {
keyCode: 32,
which: 32,
Expand Down

0 comments on commit 1437501

Please sign in to comment.