Skip to content

Commit

Permalink
Merge pull request #5843 from nextcloud/backport/5727/stable28
Browse files Browse the repository at this point in the history
[stable28] test(cy): rely on @nextcloud/axios for requests
  • Loading branch information
mejo- authored May 28, 2024
2 parents 214d9b4 + be5734b commit 73c8b23
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 395 deletions.
5 changes: 0 additions & 5 deletions cypress/e2e/api/SessionApi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ describe('The session Api', function() {

before(function() {
cy.createUser(user)
cy.prepareWindowForSessionApi()
})

beforeEach(function() {
cy.login(user)
cy.prepareSessionApi()
})

describe('open the session', function() {
Expand Down Expand Up @@ -223,7 +221,6 @@ describe('The session Api', function() {
})
.then(() => cy.clearCookies())
.then(() => {
cy.prepareSessionApi()
return cy.createTextSession(undefined, { filePath: '', shareToken })
.then(con => {
connection = con
Expand All @@ -247,7 +244,6 @@ describe('The session Api', function() {
.should('be.at.least', 1)
cy.save(connection, { version: 1, autosaveContent: '# Heading 1', manualSave: true })
cy.login(user)
cy.prepareSessionApi()
cy.downloadFile('saves.md')
.its('data')
.should('eql', '# Heading 1')
Expand Down Expand Up @@ -290,7 +286,6 @@ describe('The session Api', function() {
cy.log(token)
shareToken = token
cy.clearCookies()
cy.prepareSessionApi()
cy.createTextSession(undefined, { filePath: '', shareToken })
.then(con => {
connection = con
Expand Down
2 changes: 0 additions & 2 deletions cypress/e2e/api/SyncServiceProvider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ describe('Sync service provider', function() {

before(function() {
cy.createUser(user)
cy.prepareWindowForSessionApi()
})

beforeEach(function() {
cy.login(user)
cy.prepareSessionApi()
cy.uploadTestFile('test.md')
.then(id => {
fileId = id
Expand Down
2 changes: 0 additions & 2 deletions cypress/e2e/api/UsersApi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ describe('The user mention API', function() {

before(function() {
cy.createUser(user)
cy.prepareWindowForSessionApi()
})

beforeEach(function() {
cy.login(user)
cy.uploadTestFile('test.md').as('fileId')
.then(cy.createTextSession).as('connection')
cy.getRequestToken()
})

afterEach(function() {
Expand Down
159 changes: 37 additions & 122 deletions cypress/e2e/directediting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,148 +2,63 @@ import { initUserAndFiles, randUser } from '../utils/index.js'

const user = randUser()

const createDirectEditingLink = (user, file) => {
cy.login(user)
return cy.request({
method: 'POST',
url: `${Cypress.env('baseUrl')}/ocs/v2.php/apps/files/api/v1/directEditing/open?format=json`,
form: true,
body: {
path: file,
},
auth: { user: user.userId, pass: user.password },
headers: {
'OCS-ApiRequest': 'true',
'Content-Type': 'application/x-www-form-urlencoded',
},
}).then(response => {
cy.log(response)
const token = response.body?.ocs?.data?.url
cy.log(`Created direct editing token for ${user.userId}`, token)
return cy.wrap(token)
})
}

const createDirectEditingLinkForNewFile = (user, file) => {
cy.login(user)
return cy.request({
method: 'POST',
url: `${Cypress.env('baseUrl')}/ocs/v2.php/apps/files/api/v1/directEditing/create?format=json`,
form: true,
body: {
path: file,
editorId: 'text',
creatorId: 'textdocument',
},
auth: { user: user.userId, pass: user.password },
headers: {
'OCS-ApiRequest': 'true',
'Content-Type': 'application/x-www-form-urlencoded',
},
}).then(response => {
cy.log(response)
const token = response.body?.ocs?.data?.url
cy.log(`Created direct editing token for ${user.userId}`, token)
return cy.wrap(token)
})
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() {

const visitHooks = {
onBeforeLoad(win) {
win.DirectEditingMobileInterface = {
close() {},
}
},
}
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')

createDirectEditingLink(user, 'empty.md')
cy.login(user)
cy.createDirectEditingLink('empty.md')
.then((token) => {
cy.logout()
cy.visit(token, visitHooks)
})
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.getFileContent('empty.md').then((content) => {
expect(content).to.equal('# This is a headline\n\nSome text')
})
cy.session('direct-editing', () => { })
cy.openDirectEditingToken(token)
})
enterContentAndClose()
cy.login(user)
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')

createDirectEditingLinkForNewFile(user, 'newfile.md')
cy.login(user)
cy.createDirectEditingLinkForNewFile('newfile.md')
.then((token) => {
cy.logout()
cy.visit(token, visitHooks)
})

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.getFileContent('newfile.md').then((content) => {
expect(content).to.equal('# This is a headline\n\nSome text')
})
cy.session('direct-editing', () => { })
cy.openDirectEditingToken(token)
})
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')

createDirectEditingLink(user, 'empty.txt')
cy.login(user)
cy.createDirectEditingLink('empty.txt')
.then((token) => {
cy.logout()
cy.visit(token, visitHooks)
})

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.getFileContent('empty.txt').then((content) => {
expect(content).to.equal('# This is a headline\nSome text\n')
})
cy.session('direct-editing', () => { })
cy.openDirectEditingToken(token)
})
enterContentAndClose()
cy.login(user)
cy.getFileContent('empty.txt')
.should('equal', '# This is a headline\nSome text\n')
})
})
2 changes: 1 addition & 1 deletion cypress/e2e/propfind.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Text PROPFIND extension ', function() {
cy.uploadFile('test.md', 'text/markdown', '/Readme.md')
cy.propfindFolder('/')
.should('have.property', richWorkspace, '## Hello world\n')
cy.removeFile('/Readme.md')
cy.deleteFile('/Readme.md')
cy.propfindFolder('/')
.should('have.property', richWorkspace, '')
})
Expand Down
Loading

0 comments on commit 73c8b23

Please sign in to comment.