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:
Julius Härtl 2023-01-10 09:29:08 +01:00
Родитель 8299a4cda9
Коммит 5f7c78e6d2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4C614C6ED2CDE6DF
5 изменённых файлов: 109 добавлений и 20 удалений

Просмотреть файл

@ -31,7 +31,6 @@ describe('Create new office files', function() {
})
it('Shows create file entries', function() {
cy.visit('/apps/files')
cy.get('.files-controls .button.new')
.should('be.visible')
.click()
@ -55,7 +54,6 @@ describe('Create new office files', function() {
]
newFileTypeLabels.forEach((filetype) => {
it('Create empty ' + filetype + ' file', function() {
cy.visit('/apps/files')
cy.get('.files-controls .button.new')
.should('be.visible')
.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, 'spreadsheet.ods', 'application/vnd.oasis.opendocument.spreadsheet', '/spreadsheet.ods')
})
beforeEach(function() {
cy.login(shareOwner)
})
it('Open a shared file', function() {
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()
})
})

Двоичные данные
cypress/fixtures/templates/presentation.otp Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -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
*
@ -40,7 +58,7 @@ Cypress.Commands.add('logout', (route = '/') => {
* @param {string} [target] the target of the file relative to the user root
*/
Cypress.Commands.add('uploadFile', (user, fixture, mimeType, target = `/${fixture}`) => {
cy.clearCookies()
cy.login(user)
const fileName = basename(target)
// get fixture
@ -53,19 +71,17 @@ Cypress.Commands.add('uploadFile', (user, fixture, mimeType, target = `/${fixtur
const filePath = target.split('/').map(encodeURIComponent).join('/')
try {
const file = new File([blob], fileName, { type: mimeType })
await axios({
url: `${rootPath}${filePath}`,
method: 'PUT',
data: file,
return cy.request('/csrftoken')
.then(({ body }) => body.token)
.then(requesttoken => {
return axios.put(`${rootPath}/${filePath}`, file, {
headers: {
requesttoken,
'Content-Type': mimeType,
},
auth: {
username: user.userId,
password: user.password,
},
}).then(response => {
cy.log(`Uploaded ${fixture} as ${fileName}`, response)
cy.log(`Uploaded ${fileName}`, response.status)
})
})
} catch (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) => {
cy.login(new User('admin', 'admin'))
cy.request({