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>
  • Loading branch information
max-nextcloud committed May 2, 2024
1 parent 62ecdf6 commit ab794e4
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() {

Check warning on line 5 in cypress/e2e/directediting.spec.js

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc comment
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 ab794e4

Please sign in to comment.