Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] test(cy): rely on @nextcloud/axios for requests #5840

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 0 additions & 4 deletions cypress/e2e/api/SessionApi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe('The session Api', function() {

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

describe('open the session', function() {
Expand Down Expand Up @@ -227,7 +226,6 @@ describe('The session Api', function() {
})
.then(() => cy.clearCookies())
.then(() => {
cy.prepareSessionApi()
return cy.createTextSession(undefined, { filePath: '', shareToken })
.then(con => {
connection = con
Expand All @@ -251,7 +249,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 @@ -294,7 +291,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
1 change: 0 additions & 1 deletion cypress/e2e/api/SyncServiceProvider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('Sync service provider', function() {

beforeEach(function() {
cy.login(user)
cy.prepareSessionApi()
cy.uploadTestFile('test.md')
.then(id => {
fileId = id
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