Skip to content

Commit 9fb0fd0

Browse files
juliusknorrelzody
authored andcommitted
test: Add test case for creating a new file and opening it with direct editing
Signed-off-by: Julius Knorr <jus@bitgrid.net>
1 parent 67385c1 commit 9fb0fd0

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

cypress/e2e/direct.spec.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
* SPDX-FileCopyrightText: 2023 Julius Härtl <jus@bitgrid.net>
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5+
const getTemplates = (user, type) => {
6+
return cy.request({
7+
method: 'GET',
8+
url: `${Cypress.env('baseUrl')}/ocs/v2.php/apps/richdocuments/api/v1/templates/${type}?format=json`,
9+
auth: { user: user.userId, pass: user.password },
10+
headers: {
11+
'OCS-ApiRequest': 'true',
12+
'Content-Type': 'application/x-www-form-urlencoded',
13+
},
14+
}).then(response => {
15+
cy.log(response)
16+
const templates = response.body?.ocs?.data
17+
cy.wrap(templates)
18+
})
19+
}
20+
521
const createDirectEditingLink = (user, fileId) => {
622
cy.login(user)
723
return cy.request({
@@ -24,6 +40,28 @@ const createDirectEditingLink = (user, fileId) => {
2440
})
2541
}
2642

43+
const createNewFileDirectEditingLink = (user, path, template) => {
44+
cy.login(user)
45+
return cy.request({
46+
method: 'POST',
47+
url: `${Cypress.env('baseUrl')}/ocs/v2.php/apps/richdocuments/api/v1/templates/new?format=json`,
48+
form: true,
49+
body: {
50+
path, template,
51+
},
52+
// auth: { user: user.userId, pass: user.password },
53+
headers: {
54+
'OCS-ApiRequest': 'true',
55+
'Content-Type': 'application/x-www-form-urlencoded',
56+
},
57+
}).then(response => {
58+
cy.log(response)
59+
const token = response.body?.ocs?.data?.url
60+
cy.log(`Created direct editing token for ${user.userId}`, token)
61+
cy.wrap(token)
62+
})
63+
}
64+
2765
const createDirectEditingLinkForShareToken = (shareToken, host = undefined, path = '', password = undefined) => {
2866
cy.logout()
2967
return cy.request({
@@ -75,6 +113,21 @@ describe('Direct editing (legacy)', function() {
75113
})
76114
})
77115

116+
it('Open an new file', function() {
117+
getTemplates(randUser, 'document')
118+
.then((templates) => {
119+
const emptyTemplate = templates.find((template) => template.name === 'Empty')
120+
cy.nextcloudTestingAppConfigSet('richdocuments', 'uiDefaults-UIMode', 'classic')
121+
createNewFileDirectEditingLink(randUser, 'mynewfile.odt', emptyTemplate.id)
122+
.then((token) => {
123+
cy.logout()
124+
cy.visit(token)
125+
cy.waitForCollabora(false)
126+
cy.screenshot('direct-new')
127+
})
128+
})
129+
})
130+
78131
it('Open an existing file on a share link', function() {
79132
cy.shareLink(randUser, '/document.odt').then((token) => {
80133
createDirectEditingLinkForShareToken(token)

0 commit comments

Comments
 (0)