Skip to content

Commit

Permalink
test(cy): use a new session for direct editing
Browse files Browse the repository at this point in the history
Signed-off-by: Max <max@nextcloud.com>
  • Loading branch information
max-nextcloud committed May 2, 2024
1 parent a44c46e commit 62ecdf6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
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

0 comments on commit 62ecdf6

Please sign in to comment.