Skip to content

Commit 8abe11d

Browse files
authored
Merge pull request #4538 from nextcloud/backport/4448/stable30
[stable30] feat(test): add tests for template fields with empty labels
2 parents b75f21f + 21f78c2 commit 8abe11d

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

cypress/e2e/templates.spec.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,12 @@ describe('Create templates with fields', () => {
126126

127127
it('Create a document from a template with fields', () => {
128128
const fields = [
129-
{ type: 'rich-text', alias: 'Name', content: 'Nextcloud' },
130-
{ type: 'rich-text', alias: 'Favorite app', content: 'richdocuments' },
131-
{ type: 'checkbox', alias: 'Uses Nextcloud at home', checked: true },
129+
{ index: 'ContentControls.ByIndex.0', type: 'rich-text', alias: 'Name', content: 'Nextcloud' },
130+
{ index: 'ContentControls.ByIndex.1', type: 'rich-text', alias: 'Favorite app', content: 'richdocuments' },
131+
{ index: 'ContentControls.ByIndex.2', type: 'checkbox', alias: 'Uses Nextcloud at home', checked: true },
132+
133+
{ index: 'ContentControls.ByIndex.3', type: 'rich-text', alias: '', content: '' },
134+
{ index: 'ContentControls.ByIndex.4', type: 'checkbox', alias: '', checked: false },
132135
]
133136

134137
cy.visit('/apps/files')
2.78 KB
Binary file not shown.

cypress/support/commands.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,19 +316,35 @@ Cypress.Commands.add('submitTemplateFields', (fields) => {
316316

317317
for (const field of fields) {
318318
switch (field.type) {
319+
319320
case 'rich-text':
320-
cy.get('@templateFiller')
321-
.find(`input[placeholder="${field.alias}"]`)
322-
.type(field.content)
321+
if (!field.alias) {
322+
cy.get('@templateFiller')
323+
.find(`label[for="text-field${field.index}"]`)
324+
.should('not.exist')
325+
} else {
326+
cy.get('@templateFiller')
327+
.find(`input[placeholder="${field.alias}"]`)
328+
.type(field.content)
329+
}
330+
323331
break
332+
324333
case 'checkbox':
325-
cy.get('@templateFiller')
326-
.find('span.checkbox-radio-switch__text').contains(field.alias)
327-
.click()
334+
if (!field.alias) {
335+
cy.get('@templateFiller')
336+
.find(`input[id="checkbox-field${field.index}`)
337+
.should('not.exist')
338+
} else {
339+
cy.get('@templateFiller')
340+
.find('span.checkbox-radio-switch__text').contains(field.alias)
341+
.click()
342+
}
343+
328344
break
345+
329346
default:
330347
expect.fail('Using a field type not yet supported')
331-
break
332348
}
333349
}
334350

@@ -354,6 +370,12 @@ Cypress.Commands.add('verifyTemplateFields', (fields, fileId) => {
354370
for (const index in body.ocs.data) {
355371
const field = body.ocs.data[index]
356372

373+
// If a field has no name or alias, we don't need
374+
// to check it because it is not shown in the template filler
375+
if (!field.alias) {
376+
continue;
377+
}
378+
357379
switch (field.type) {
358380
case 'rich-text':
359381
expect(field.content).to.equal(fields[index].content)

0 commit comments

Comments
 (0)