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

test(cy): rely on @nextcloud/axios for requests #5727

Merged
merged 3 commits into from
May 2, 2024
Merged
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
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 @@

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() {

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() {

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
Loading