feat(tests): add testing for template filling workflow

Signed-off-by: Elizabeth Danzberger <lizzy7128@tutanota.de>
This commit is contained in:
Elizabeth Danzberger 2024-08-05 20:36:24 -04:00
parent 810be762fe
commit 16102a214b
No known key found for this signature in database
GPG key ID: 2C0EB04DAD5237F6
3 changed files with 130 additions and 35 deletions

View file

@ -2,6 +2,7 @@
* SPDX-FileCopyrightText: 2023 Julius Härtl <jus@bitgrid.net>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
describe('Create new office files from templates', function() {
let randUser
@ -16,28 +17,20 @@ describe('Create new office files from templates', function() {
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 })
cy.get('.files-list__header div[menu-title="New"] button')
.should('be.visible')
.contains('.menuitem', 'New presentation')
.as('menuitem')
.should('be.visible')
.click()
.as('newFileMenu')
cy.get('@menuitem').find('.filenameform input[type=text]').type('FileFromTemplate')
cy.get('@menuitem').find('.filenameform .icon-confirm').click()
cy.get('@newFileMenu').click()
cy.get('button[role="menuitem"]').contains('New presentation').click()
cy.get('.templates-picker__form')
.as('form')
.should('be.visible')
.contains('.template-picker__label', 'presentation')
.should('be.visible')
.click()
cy.get('input[data-cy-files-new-node-dialog-input=""]').type('FileFromTemplate')
cy.get('button[data-cy-files-new-node-dialog-submit=""]').click()
cy.get('@form').find('.templates-picker__buttons input[type=submit]').click()
cy.get('form.templates-picker__form').as('templatePicker')
cy.get('@templatePicker').contains('presentation').click()
cy.get('@templatePicker').find('input[type="submit"]').click()
cy.waitForViewer()
cy.waitForCollabora()
@ -47,34 +40,26 @@ describe('Create new office files from templates', function() {
cy.uploadSystemTemplate()
cy.login(randUser)
cy.visit('/apps/files')
cy.get('.files-controls .button.new')
.should('be.visible')
.click()
cy.get('.newFileMenu', { timeout: 10000 })
cy.get('.files-list__header div[menu-title="New"] button')
.should('be.visible')
.contains('.menuitem', 'New presentation')
.as('menuitem')
.should('be.visible')
.click()
.as('newFileMenu')
cy.get('@menuitem').find('.filenameform input[type=text]').type('FileFromTemplate')
cy.get('@menuitem').find('.filenameform .icon-confirm').click()
cy.get('@newFileMenu').click()
cy.get('button[role="menuitem"]').contains('New presentation').click()
cy.get('.templates-picker__form')
.as('form')
.should('be.visible')
.contains('.template-picker__label', 'systemtemplate')
.should('be.visible')
.click()
cy.get('input[data-cy-files-new-node-dialog-input=""]').type('FileFromSystemTemplate')
cy.get('button[data-cy-files-new-node-dialog-submit=""]').click()
cy.get('@form').find('.templates-picker__buttons input[type=submit]').click()
cy.get('form.templates-picker__form').as('templatePicker')
cy.get('@templatePicker').contains('systemtemplate').click()
cy.get('@templatePicker').find('input[type="submit"]').click()
cy.waitForViewer()
cy.waitForCollabora()
})
it.only('Create a file from a system template as guest', () => {
it('Create a file from a system template as guest', () => {
cy.uploadSystemTemplate()
cy.createFolder(randUser, '/my-share')
@ -113,3 +98,76 @@ describe('Create new office files from templates', function() {
})
})
})
describe('Create templates with fields', () => {
let randUser
before(() => {
cy.createRandomUser().then(user => {
randUser = user
cy.login(randUser)
cy.visit('/apps/files')
// Create a templates folder
cy.get('.files-list__header div[menu-title="New"] button')
.should('be.visible')
.as('newFileMenu')
cy.get('@newFileMenu').click()
cy.get('button[role="menuitem"]').contains('Create templates folder').click()
cy.get('button[data-cy-files-new-node-dialog-submit=""]').click()
// Upload the fixtures into the templates folder
cy.uploadFile(randUser, 'templates/document_template_with_fields.odt', 'application/vnd.oasis.opendocument.text', '/Templates/document.odt')
})
})
it('Create a document from a template with fields', () => {
const fields = [
{ alias: 'Name', content: 'Nextcloud' },
{ alias: 'Favorite app', content: 'richdocuments' }
]
cy.visit('/apps/files')
// Create a new document
cy.get('.files-list__header div[menu-title="New"] button')
.should('be.visible')
.as('newFileMenu')
cy.get('@newFileMenu').click()
cy.get('button[role="menuitem"]').contains('New document').click()
cy.get('input[data-cy-files-new-node-dialog-input=""]').type('FileFromTemplateWithFields')
cy.get('button[data-cy-files-new-node-dialog-submit=""]').click()
// Choose the document template
cy.get('form.templates-picker__form').as('templatePicker')
cy.get('@templatePicker').contains('document').click()
cy.get('@templatePicker').find('input[type="submit"]').click()
// Intercept the POST request to verify the correct fields are submitted
cy.intercept('POST', '**/templates/create', (req) => {
const templateFields = Object.values(req.body.templateFields)
expect(templateFields[0].content).to.equal(fields[0].content)
expect(templateFields[1].content).to.equal(fields[1].content)
req.continue()
}).as('reqFillFields')
cy.submitTemplateFields(fields)
// Wait for the response and collect the file ID of the created file
cy.wait('@reqFillFields').then(({ response }) => {
cy.wrap(response.body.ocs.data.fileid).as('createdFileId')
})
// Test if the fields currently match the values we passed to the template
cy.get('@createdFileId').then(createdFileId => {
cy.verifyTemplateFields(fields, createdFileId)
})
})
})

View file

@ -259,3 +259,40 @@ Cypress.Commands.add('uploadSystemTemplate', () => {
}, { force: true })
cy.get('#richdocuments-templates li').contains('systemtemplate.otp')
})
Cypress.Commands.add('submitTemplateFields', (fields) => {
// Enter test values into the template filler
cy.get('.template-field-modal__content').as('templateFiller')
cy.get('.template-field-modal__buttons').as('templateFillerButtons')
for (const field of fields) {
cy.get('@templateFiller')
.find(`input[placeholder="${field.alias}"]`)
.type(field.content)
}
// Submit the template fields
cy.get('@templateFillerButtons').find('button[aria-label="Submit button"]').click()
})
Cypress.Commands.add('verifyTemplateFields', (fields, fileId) => {
const apiEndpoint = '/ocs/v2.php/apps/richdocuments/api/v1/template/fields/extract/'
cy.request('/csrftoken')
.then(({ body }) => body.token)
.as('requestToken')
cy.get('@requestToken').then(requesttoken => {
cy.request({
method: 'GET',
url: Cypress.env('baseUrl') + apiEndpoint + fileId + '?format=json',
headers: {
requesttoken
},
}).then(({ body }) => {
for (const index in body.ocs.data) {
expect(body.ocs.data[index].content).to.equal(fields[index].content)
}
})
})
})