Skip to content

Commit

Permalink
feat(tests): add testing for checkbox field type
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody committed Aug 20, 2024
1 parent 5c2d218 commit a875e0d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
7 changes: 4 additions & 3 deletions cypress/e2e/templates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('Create templates with fields', () => {

cy.login(randUser)
cy.visit('/apps/files')

// Create a templates folder
cy.get('.files-list__header div[menu-title="New"] button')
.should('be.visible')
Expand All @@ -126,8 +126,9 @@ describe('Create templates with fields', () => {

it('Create a document from a template with fields', () => {
const fields = [
{ alias: 'Name', content: 'Nextcloud' },
{ alias: 'Favorite app', content: 'richdocuments' }
{ 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')
Expand Down
Binary file modified cypress/fixtures/templates/document_template_with_fields.odt
Binary file not shown.
34 changes: 29 additions & 5 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,21 @@ Cypress.Commands.add('submitTemplateFields', (fields) => {
cy.get('.template-field-modal__buttons').as('templateFillerButtons')

for (const field of fields) {
cy.get('@templateFiller')
.find(`input[placeholder="${field.alias}"]`)
.type(field.content)
switch (field.type) {
case 'rich-text':
cy.get('@templateFiller')
.find(`input[placeholder="${field.alias}"]`)
.type(field.content)
break
case 'checkbox':
cy.get('@templateFiller')
.find('label').contains(field.alias)
.click()
break
default:
expect.fail('Using a field type not yet supported')
break
}
}

// Submit the template fields
Expand All @@ -287,11 +299,23 @@ Cypress.Commands.add('verifyTemplateFields', (fields, fileId) => {
method: 'GET',
url: Cypress.env('baseUrl') + apiEndpoint + fileId + '?format=json',
headers: {
requesttoken
requesttoken,
},
}).then(({ body }) => {
for (const index in body.ocs.data) {
expect(body.ocs.data[index].content).to.equal(fields[index].content)
const field = body.ocs.data[index]

switch (field.type) {
case 'rich-text':
expect(field.content).to.equal(fields[index].content)
break
case 'checkbox':
expect(field.checked).to.equal(fields[index].checked)
break
default:
expect.fail('Using a field type not yet supported')
break
}
}
})
})
Expand Down

0 comments on commit a875e0d

Please sign in to comment.