test(cypress): Add e2e test for creating a new file from user template
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Родитель
8299a4cda9
Коммит
5f7c78e6d2
|
@ -31,7 +31,6 @@ describe('Create new office files', function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Shows create file entries', function() {
|
it('Shows create file entries', function() {
|
||||||
cy.visit('/apps/files')
|
|
||||||
cy.get('.files-controls .button.new')
|
cy.get('.files-controls .button.new')
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
.click()
|
.click()
|
||||||
|
@ -55,7 +54,6 @@ describe('Create new office files', function() {
|
||||||
]
|
]
|
||||||
newFileTypeLabels.forEach((filetype) => {
|
newFileTypeLabels.forEach((filetype) => {
|
||||||
it('Create empty ' + filetype + ' file', function() {
|
it('Create empty ' + filetype + ' file', function() {
|
||||||
cy.visit('/apps/files')
|
|
||||||
cy.get('.files-controls .button.new')
|
cy.get('.files-controls .button.new')
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
.click()
|
.click()
|
||||||
|
|
|
@ -33,9 +33,6 @@ describe('File sharing of office documents', function() {
|
||||||
cy.uploadFile(shareOwner, 'document.odt', 'application/vnd.oasis.opendocument.text', '/document.odt')
|
cy.uploadFile(shareOwner, 'document.odt', 'application/vnd.oasis.opendocument.text', '/document.odt')
|
||||||
cy.uploadFile(shareOwner, 'spreadsheet.ods', 'application/vnd.oasis.opendocument.spreadsheet', '/spreadsheet.ods')
|
cy.uploadFile(shareOwner, 'spreadsheet.ods', 'application/vnd.oasis.opendocument.spreadsheet', '/spreadsheet.ods')
|
||||||
})
|
})
|
||||||
beforeEach(function() {
|
|
||||||
cy.login(shareOwner)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Open a shared file', function() {
|
it('Open a shared file', function() {
|
||||||
const filename = 'document.odt'
|
const filename = 'document.odt'
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/**
|
||||||
|
* SPDX-FileLicenseText: 2023 Julius Härtl <jus@bitgrid.net>
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
describe('Create new office files from templates', function() {
|
||||||
|
|
||||||
|
let randUser
|
||||||
|
before(function() {
|
||||||
|
cy.createRandomUser().then(user => {
|
||||||
|
randUser = user
|
||||||
|
cy.createFolder(randUser, 'Templates-user')
|
||||||
|
cy.uploadFile(randUser, 'templates/presentation.otp', 'application/vnd.oasis.opendocument.presentation', '/Templates-user/presentation.otp')
|
||||||
|
cy.setPersonalTemplateFolder(randUser, '/Templates-user')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Create a new file from a user template', function() {
|
||||||
|
cy.visit('/apps/files')
|
||||||
|
cy.get('.files-controls .button.new')
|
||||||
|
.should('be.visible')
|
||||||
|
.click()
|
||||||
|
|
||||||
|
cy.get('.newFileMenu', { timeout: 10000 })
|
||||||
|
.should('be.visible')
|
||||||
|
.contains('.menuitem', 'New presentation')
|
||||||
|
.as('menuitem')
|
||||||
|
.should('be.visible')
|
||||||
|
.click()
|
||||||
|
|
||||||
|
cy.get('@menuitem').find('.filenameform input[type=text]').type('FileFromTemplate')
|
||||||
|
cy.get('@menuitem').find('.filenameform .icon-confirm').click()
|
||||||
|
|
||||||
|
cy.get('.templates-picker__form')
|
||||||
|
.as('form')
|
||||||
|
.should('be.visible')
|
||||||
|
.contains('.template-picker__label', 'presentation')
|
||||||
|
.should('be.visible')
|
||||||
|
.click()
|
||||||
|
|
||||||
|
cy.get('@form').find('.templates-picker__buttons input[type=submit]').click()
|
||||||
|
|
||||||
|
cy.waitForViewer()
|
||||||
|
cy.waitForCollabora()
|
||||||
|
})
|
||||||
|
})
|
Двоичный файл не отображается.
|
@ -31,6 +31,24 @@ Cypress.Commands.add('logout', (route = '/') => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Cypress.Commands.add('createFolder', (user, target) => {
|
||||||
|
cy.login(user)
|
||||||
|
const rootPath = `${Cypress.env('baseUrl')}/remote.php/dav/files/${encodeURIComponent(user.userId)}`
|
||||||
|
const dirPath = target.split('/').map(encodeURIComponent).join('/')
|
||||||
|
|
||||||
|
return cy.request('/csrftoken')
|
||||||
|
.then(({ body }) => body.token)
|
||||||
|
.then(requesttoken => {
|
||||||
|
return cy.request({
|
||||||
|
url: `${rootPath}/${dirPath}`,
|
||||||
|
method: 'MKCOL',
|
||||||
|
headers: {
|
||||||
|
requesttoken,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cy.uploadedFile - uploads a file from the fixtures folder
|
* cy.uploadedFile - uploads a file from the fixtures folder
|
||||||
*
|
*
|
||||||
|
@ -40,7 +58,7 @@ Cypress.Commands.add('logout', (route = '/') => {
|
||||||
* @param {string} [target] the target of the file relative to the user root
|
* @param {string} [target] the target of the file relative to the user root
|
||||||
*/
|
*/
|
||||||
Cypress.Commands.add('uploadFile', (user, fixture, mimeType, target = `/${fixture}`) => {
|
Cypress.Commands.add('uploadFile', (user, fixture, mimeType, target = `/${fixture}`) => {
|
||||||
cy.clearCookies()
|
cy.login(user)
|
||||||
const fileName = basename(target)
|
const fileName = basename(target)
|
||||||
|
|
||||||
// get fixture
|
// get fixture
|
||||||
|
@ -53,19 +71,17 @@ Cypress.Commands.add('uploadFile', (user, fixture, mimeType, target = `/${fixtur
|
||||||
const filePath = target.split('/').map(encodeURIComponent).join('/')
|
const filePath = target.split('/').map(encodeURIComponent).join('/')
|
||||||
try {
|
try {
|
||||||
const file = new File([blob], fileName, { type: mimeType })
|
const file = new File([blob], fileName, { type: mimeType })
|
||||||
await axios({
|
return cy.request('/csrftoken')
|
||||||
url: `${rootPath}${filePath}`,
|
.then(({ body }) => body.token)
|
||||||
method: 'PUT',
|
.then(requesttoken => {
|
||||||
data: file,
|
return axios.put(`${rootPath}/${filePath}`, file, {
|
||||||
headers: {
|
headers: {
|
||||||
|
requesttoken,
|
||||||
'Content-Type': mimeType,
|
'Content-Type': mimeType,
|
||||||
},
|
},
|
||||||
auth: {
|
|
||||||
username: user.userId,
|
|
||||||
password: user.password,
|
|
||||||
},
|
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
cy.log(`Uploaded ${fixture} as ${fileName}`, response)
|
cy.log(`Uploaded ${fileName}`, response.status)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
cy.log(error)
|
cy.log(error)
|
||||||
|
@ -127,6 +143,25 @@ Cypress.Commands.add('nextcloudEnableApp', (appId) => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Cypress.Commands.add('setPersonalTemplateFolder', (user, templateFolder) => {
|
||||||
|
cy.login(user)
|
||||||
|
templateFolder = templateFolder.split('/').map(encodeURIComponent).join('/')
|
||||||
|
|
||||||
|
return cy.request('/csrftoken')
|
||||||
|
.then(({ body }) => body.token)
|
||||||
|
.then(requesttoken => {
|
||||||
|
return cy.request({
|
||||||
|
url: `${Cypress.env('baseUrl')}/index.php/apps/richdocuments/ajax/personal.php`,
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
requesttoken,
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
templateFolder,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
Cypress.Commands.add('nextcloudTestingAppConfigSet', (appId, configKey, configValue) => {
|
Cypress.Commands.add('nextcloudTestingAppConfigSet', (appId, configKey, configValue) => {
|
||||||
cy.login(new User('admin', 'admin'))
|
cy.login(new User('admin', 'admin'))
|
||||||
cy.request({
|
cy.request({
|
||||||
|
|
Загрузка…
Ссылка в новой задаче