-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This feature is applied when using the appearance:descendant-of-current-contact The scope remains for forms that are opened in the contact tab; it takes the contact ID from the URL. It uses the CouchDB view contact_by_parent in combination with the contact type.
- Loading branch information
1 parent
7ebd7bf
commit 4547885
Showing
13 changed files
with
383 additions
and
63 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
const fs = require('fs'); | ||
|
||
const utils = require('@utils'); | ||
const userFactory = require('@factories/cht/users/users'); | ||
const placeFactory = require('@factories/cht/contacts/place'); | ||
const personFactory = require('@factories/cht/contacts/person'); | ||
const commonPage = require('@page-objects/default/common/common.wdio.page'); | ||
const loginPage = require('@page-objects/default/login/login.wdio.page'); | ||
const genericForm = require('@page-objects/default/enketo/generic-form.wdio.page'); | ||
const reportsPage = require('@page-objects/default/reports/reports.wdio.page'); | ||
|
||
describe('DB Object Widget', () => { | ||
const formId = 'db-object-widget'; | ||
const form = fs.readFileSync(`${__dirname}/forms/${formId}.xml`, 'utf8'); | ||
const formDocument = { | ||
_id: `form:${formId}`, | ||
internalId: formId, | ||
title: `Form ${formId}`, | ||
type: 'form', | ||
context: { person: true, place: true }, | ||
_attachments: { | ||
xml: { | ||
content_type: 'application/octet-stream', | ||
data: Buffer.from(form).toString('base64') | ||
} | ||
} | ||
}; | ||
|
||
const places = placeFactory.generateHierarchy(); | ||
const districtHospital = places.get('district_hospital'); | ||
const area1 = places.get('health_center'); | ||
const area2 = placeFactory.place().build({ | ||
_id: 'area2', | ||
name: 'area 2', | ||
type: 'health_center', | ||
parent: { _id: districtHospital._id } | ||
}); | ||
|
||
const offlineUser = userFactory.build({ place: districtHospital._id, roles: [ 'chw' ] }); | ||
const personArea1 = personFactory.build({ parent: { _id: area1._id, parent: area1.parent } }); | ||
const personArea2 = personFactory.build({ name: 'Patricio', parent: { _id: area2._id, parent: area2.parent } }); | ||
|
||
before(async () => { | ||
await utils.saveDocs([ ...places.values(), area2, personArea1, personArea2, formDocument ]); | ||
await utils.createUsers([ offlineUser ]); | ||
await loginPage.login(offlineUser); | ||
}); | ||
|
||
it('should display only the contacts from the parent contact', async () => { | ||
await commonPage.goToPeople(area1._id); | ||
await commonPage.openFastActionReport(formId); | ||
|
||
const sameParent = await genericForm.getDBObjectWidgetValues('/db_object_form/people/person_test_same_parent'); | ||
await sameParent[0].click(); | ||
expect(sameParent.length).to.equal(1); | ||
expect(sameParent[0].name).to.equal(personArea1.name); | ||
|
||
const allContacts = await genericForm.getDBObjectWidgetValues('/db_object_form/people/person_test_all'); | ||
await allContacts[2].click(); | ||
expect(allContacts.length).to.equal(3); | ||
expect(allContacts[0].name).to.equal(personArea1.name); | ||
expect(allContacts[1].name).to.equal(offlineUser.contact.name); | ||
expect(allContacts[2].name).to.equal(personArea2.name); | ||
|
||
await genericForm.submitForm(); | ||
await commonPage.waitForPageLoaded(); | ||
await commonPage.goToReports(); | ||
|
||
const firstReport = await reportsPage.getListReportInfo(await reportsPage.firstReport()); | ||
expect(firstReport.heading).to.equal(offlineUser.contact.name); | ||
expect(firstReport.form).to.equal('Form db-object-widget'); | ||
|
||
await reportsPage.openReport(firstReport.dataId); | ||
expect(await reportsPage.getReportDetailFieldValueByLabel( | ||
'report.db-object-widget.people.person_test_same_parent' | ||
)).to.equal(personArea1._id); | ||
expect(await reportsPage.getReportDetailFieldValueByLabel( | ||
'report.db-object-widget.people.person_test_all' | ||
)).to.equal(personArea2._id); | ||
}); | ||
|
||
}); |
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,32 @@ | ||
<?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>DB Object Form</h:title> | ||
<model> | ||
<instance> | ||
<db_object_form id="db_object_form" prefix="J1!db_object_form!" delimiter="#" version="2021-12-01 00:00:00"> | ||
<people> | ||
<person_test_same_parent/> | ||
<person_test_all/> | ||
</people> | ||
<meta tag="hidden"> | ||
<instanceID/> | ||
</meta> | ||
</db_object_form> | ||
</instance> | ||
<bind nodeset="/db_object_form/people/person_test_same_parent" type="string"/> | ||
<bind nodeset="/db_object_form/people/person_test_all" type="string"/> | ||
<bind nodeset="/db_object_form/meta/instanceID" type="string" readonly="true()" calculate="concat('uuid:', uuid())"/> | ||
</model> | ||
</h:head> | ||
<h:body class="pages"> | ||
<group appearance="field-list" ref="/db_object_form/people"> | ||
<input ref="/db_object_form/people/person_test_same_parent" appearance="select-contact type-person descendant-of-current-contact"> | ||
<label>Select a person from same parent</label> | ||
</input> | ||
<input ref="/db_object_form/people/person_test_all" appearance="select-contact type-person"> | ||
<label>Select a person from all</label> | ||
</input> | ||
</group> | ||
</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
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.