Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(cy): use a new session for direct editing
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed May 2, 2024
commit 62ecdf67b686e915f8ee3dc302c63a9ba3a4d5f4
30 changes: 12 additions & 18 deletions cypress/e2e/directediting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ const user = randUser()

describe('direct editing', function() {

const visitHooks = {
onBeforeLoad(win) {
win.DirectEditingMobileInterface = {
close() {},
}
},
}
before(function() {
initUserAndFiles(user, 'test.md', 'empty.md', 'empty.txt')
})
Expand All @@ -23,8 +16,8 @@ describe('direct editing', function() {
cy.login(user)
cy.createDirectEditingLink('empty.md')
.then((token) => {
cy.logout()
cy.visit(token, visitHooks)
cy.session('direct-editing', () => { })
cy.openDirectEditingToken(token)
})
cy.getContent().type('# This is a headline')
cy.getContent().type('{enter}')
Expand All @@ -37,11 +30,10 @@ describe('direct editing', function() {

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

it('Create a file, edit it', () => {
Expand All @@ -52,8 +44,8 @@ describe('direct editing', function() {
cy.login(user)
cy.createDirectEditingLinkForNewFile('newfile.md')
.then((token) => {
cy.logout()
cy.visit(token, visitHooks)
cy.session('direct-editing', () => { })
cy.openDirectEditingToken(token)
})

cy.getContent().type('# This is a headline')
Expand All @@ -68,6 +60,7 @@ describe('direct editing', function() {
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')
})
Expand All @@ -82,8 +75,8 @@ describe('direct editing', function() {
cy.login(user)
cy.createDirectEditingLink('empty.txt')
.then((token) => {
cy.logout()
cy.visit(token, visitHooks)
cy.session('direct-editing', () => { })
cy.openDirectEditingToken(token)
})

cy.getContent().type('# This is a headline')
Expand All @@ -98,6 +91,7 @@ describe('direct editing', function() {
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')
})
Expand Down
11 changes: 11 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ Cypress.Commands.overwrite('login', (login, user) => {
cy.wrap(user, silent).as('currentUser')
})

Cypress.Commands.add('openDirectEditingToken', (token) => {
const visitHooks = {
onBeforeLoad(win) {
win.DirectEditingMobileInterface = {
close() {},
}
},
}
cy.visit(token, visitHooks)
})

Cypress.Commands.add('uploadFile', (fileName, mimeType, target) => {
return cy.fixture(fileName, 'binary')
.then(Cypress.Blob.binaryStringToBlob)
Expand Down