-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3954 from nextcloud/backport/3919/stable30
[stable30] Pass data to field depending on field type
- Loading branch information
Showing
17 changed files
with
386 additions
and
218 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* SPDX-FileCopyrightText: 2023 Julius Härtl <[email protected]> | ||
* 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 }) | ||
.should('be.visible') | ||
.contains('.menuitem', 'New presentation') | ||
.as('menuitem') | ||
cy.get('.files-list__header div[menu-title="New"] button') | ||
.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 }) | ||
.should('be.visible') | ||
.contains('.menuitem', 'New presentation') | ||
.as('menuitem') | ||
cy.get('.files-list__header div[menu-title="New"] button') | ||
.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,77 @@ 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 = [ | ||
{ type: 'rich-text', alias: 'Name', content: 'Nextcloud' }, | ||
{ type: 'rich-text', alias: 'Favorite app', content: 'richdocuments' }, | ||
{ type: 'checkbox', alias: 'Uses Nextcloud at home', checked: true }, | ||
] | ||
|
||
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) | ||
}) | ||
}) | ||
}) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.