Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes need for report xml attachments (#7596)
Instead of relying on xml attachments, uses report fields to populate form model on report edits. Some changes have been required: (1) db-doc fields will be saved in the main report fields. To maintain old report content display, these fields will become "hidden". (2) Because of (1), it's not safe to default to using fields when editing a report that has a content attachment, so if the content attachment exists, it will be used to populate the form, but it will be deleted upon saving. (3) bindJsonToXml is refactored so it treats arrays (repeats) correctly. Limitations: - Editing a report that created extra docs duplicates all extra docs #7594 - this behavior existed before - Reports created as extra docs in forms are not editable #7605 - the additional context part - Reports created as extra docs might not always be faithful to the model of the form itself. Migrates a bunch of e2e tests from protractor to wdio. #5549
- Loading branch information
1 parent
922abab
commit 58ea748
Showing
30 changed files
with
1,723 additions
and
656 deletions.
There are no files selected for viewing
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
110 changes: 110 additions & 0 deletions
110
tests/e2e/default/enketo/edit-report-with-attachment.wdio-spec.js
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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
const genericForm = require('../../../page-objects/forms/generic-form.wdio.page'); | ||
const reportsPage = require('../../../page-objects/reports/reports.wdio.page'); | ||
const uuid = require('uuid').v4; | ||
const common = require('../../../page-objects/common/common.wdio.page'); | ||
const loginPage = require('../../../page-objects/login/login.wdio.page'); | ||
const utils = require('../../../utils'); | ||
const userData = require('../../../page-objects/forms/data/user.po.data'); | ||
const fs = require('fs'); | ||
const commonElements = require('../../../page-objects/common/common.wdio.page'); | ||
const oneTextForm = fs.readFileSync(`${__dirname}/forms/one-text-form.xml`, 'utf8'); | ||
|
||
const instanceID = uuid(); | ||
const reportModelXml = ` | ||
<one_text_form xmlns:jr="http://openrosa.org/javarosa" id="required_note"> | ||
<intro>initial text</intro> | ||
<meta> | ||
<instanceID>uuid:${instanceID}</instanceID> | ||
<deprecatedID/> | ||
</meta> | ||
</one_text_form>`; | ||
|
||
const { userContactDoc, docs } = userData; | ||
const formDoc = { | ||
_id: 'form:one_text_form', | ||
internalId: 'one_text_form', | ||
title: 'One text form', | ||
type: 'form', | ||
_attachments: { | ||
xml: { | ||
content_type: 'application/octet-stream', | ||
data: Buffer.from(oneTextForm).toString('base64'), | ||
} | ||
} | ||
}; | ||
const reportDoc ={ | ||
_id: uuid(), | ||
form: formDoc.internalId, | ||
type: 'data_record', | ||
reported_date: Date.now(), | ||
content_type: 'xml', | ||
contact: userContactDoc, | ||
hidden_fields: ['meta'], | ||
fields: { | ||
// to prove that when xml attachment exists, it is used to populate edit form instead of fields | ||
intro: 'not same text as in xml attachment', | ||
meta: { | ||
instanceID: `uuid:${instanceID}`, | ||
deprecatedID: '' | ||
} | ||
}, | ||
_attachments: { | ||
content: { | ||
content_type: 'application/octet-stream', | ||
data: Buffer.from(reportModelXml).toString('base64'), | ||
} | ||
} | ||
}; | ||
|
||
|
||
describe('Edit report with attachmnet', () => { | ||
before(async () => { | ||
await utils.seedTestData(userContactDoc, [...docs, formDoc]); | ||
await loginPage.cookieLogin(); | ||
await common.hideSnackbar(); | ||
}); | ||
|
||
it('should remove attachment when saving', async () => { | ||
reportDoc._id = uuid(); | ||
await utils.saveDoc(reportDoc); | ||
|
||
await commonElements.goToReports(); | ||
|
||
await reportsPage.editReport(reportDoc._id); | ||
// await browser.debug(); | ||
await reportsPage.submitForm(); | ||
|
||
const editedReport = await utils.getDoc(reportDoc._id); | ||
expect(editedReport._attachments).to.be.undefined; | ||
expect(editedReport.fields).excludingEvery('meta').to.deep.equal({ intro: 'initial text' }); | ||
|
||
await reportsPage.editReport(reportDoc._id); | ||
await reportsPage.submitForm(); | ||
|
||
const twiceEditedReport = await utils.getDoc(reportDoc._id); | ||
expect(editedReport._attachments).to.be.undefined; | ||
expect(twiceEditedReport.fields).excludingEvery('meta').to.deep.equal({ intro: 'initial text' }); | ||
}); | ||
|
||
it('should save edits', async () => { | ||
reportDoc._id = uuid(); | ||
await utils.saveDoc(reportDoc); | ||
|
||
await commonElements.goToReports(); | ||
await reportsPage.editReport(reportDoc._id); | ||
await (await genericForm.fieldByName(formDoc.internalId, 'intro')).setValue('updated text'); | ||
await reportsPage.submitForm(); | ||
|
||
const editedReport = await utils.getDoc(reportDoc._id); | ||
expect(editedReport._attachments).to.be.undefined; | ||
expect(editedReport.fields).excludingEvery('meta').to.deep.equal({ intro: 'updated text' }); | ||
|
||
await reportsPage.editReport(reportDoc._id); | ||
await (await genericForm.fieldByName(formDoc.internalId, 'intro')).setValue('twice updated text'); | ||
await reportsPage.submitForm(); | ||
|
||
const twiceEditedReport = await utils.getDoc(reportDoc._id); | ||
expect(twiceEditedReport._attachments).to.be.undefined; | ||
expect(twiceEditedReport.fields).excludingEvery('meta').to.deep.equal({ intro: 'twice updated text' }); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0"?> | ||
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms"> | ||
<h:head> | ||
<h:title>One text form</h:title> | ||
<model> | ||
<instance> | ||
<one_text_form id="one_text_form" prefix="J1!one_text_form!" delimiter="#" version="2021-12-01 00:00:00"> | ||
<intro/> | ||
<meta tag="hidden"> | ||
<instanceID/> | ||
</meta> | ||
</one_text_form> | ||
</instance> | ||
<bind nodeset="/one_text_form/intro" type="string" required="true()"/> | ||
<bind nodeset="/one_text_form/meta/instanceID" type="string" readonly="true()" calculate="concat('uuid:', uuid())"/> | ||
</model> | ||
</h:head> | ||
<h:body class="pages"> | ||
<input ref="/one_text_form/intro"> | ||
<label>Enter text</label> | ||
</input> | ||
</h:body> | ||
</h:html> |
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.