Skip to content

Commit

Permalink
test(cy): simplify direct editing spec
Browse files Browse the repository at this point in the history
Extract function `enterContentAndClose()`.

Signed-off-by: Max <max@nextcloud.com>

[skip ci]
  • Loading branch information
max-nextcloud authored and backportbot[bot] committed May 28, 2024
1 parent 81e956f commit 6bbe732
Showing 1 changed file with 26 additions and 62 deletions.
88 changes: 26 additions & 62 deletions cypress/e2e/directediting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,99 +2,63 @@ import { initUserAndFiles, randUser } from '../utils/index.js'

const user = randUser()

function enterContentAndClose() {
cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest')
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')
cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')
cy.getContent().type('{ctrl+s}')
cy.wait('@push')
cy.wait('@sync')
cy.get('button.icon-close').click()
cy.wait('@closeRequest')
}

describe('direct editing', function() {

before(function() {
initUserAndFiles(user, 'test.md', 'empty.md', 'empty.txt')
})

it('Open an existing file, edit it', () => {
cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest')
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')

cy.login(user)
cy.createDirectEditingLink('empty.md')
.then((token) => {
cy.session('direct-editing', () => { })
cy.openDirectEditingToken(token)
})
cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')
cy.getContent().type('{ctrl+s}')

cy.wait('@push')
cy.wait('@sync')

cy.get('button.icon-close').click()
cy.wait('@closeRequest')
enterContentAndClose()
cy.login(user)
cy.getFileContent('empty.md').then((content) => {
expect(content).to.equal('# This is a headline\n\nSome text')
})
cy.getFileContent('empty.md')
.should('equal', '# This is a headline\n\nSome text')
})

it('Create a file, edit it', () => {
cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest')
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')

cy.login(user)
cy.createDirectEditingLinkForNewFile('newfile.md')
.then((token) => {
cy.session('direct-editing', () => { })
cy.openDirectEditingToken(token)
})

cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')
cy.getContent().type('{ctrl+s}')

cy.wait('@push')
cy.wait('@sync')

cy.get('button.icon-close').click()
cy.wait('@closeRequest')
.then(() => {
cy.login(user)
cy.getFileContent('newfile.md').then((content) => {
expect(content).to.equal('# This is a headline\n\nSome text')
})
})
enterContentAndClose()
cy.login(user)
cy.getFileContent('newfile.md')
.should('equal', '# This is a headline\n\nSome text')
})

it('Open an existing plain text file, edit it', () => {
cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest')
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')

cy.login(user)
cy.createDirectEditingLink('empty.txt')
.then((token) => {
cy.session('direct-editing', () => { })
cy.openDirectEditingToken(token)
})

cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
cy.getContent().type('Some text')
cy.getContent().type('{enter}')
cy.getContent().type('{ctrl+s}')

cy.wait('@push')
cy.wait('@sync')

cy.get('button.icon-close').click()
cy.wait('@closeRequest')
.then(() => {
cy.login(user)
cy.getFileContent('empty.txt').then((content) => {
expect(content).to.equal('# This is a headline\nSome text\n')
})
})
enterContentAndClose()
cy.login(user)
cy.getFileContent('empty.txt')
.should('equal', '# This is a headline\nSome text\n')
})
})

0 comments on commit 6bbe732

Please sign in to comment.