Methods
Loads and fills a contact form with the appropriate action
Parameters:
Name |
Type |
Attributes |
Description |
contactType |
string
|
|
Type of contact that should be created |
action |
string
|
|
one of 'create' or 'edit' |
answers |
Array.<string>
|
<repeatable>
|
Provide an array for the answers given on each page. See fillForm for more details. |
- Source:
Type Definitions
Properties:
Name |
Type |
Description |
fields |
Array.<Field>
|
|
cards |
Array.<Card>
|
|
context |
Context
|
|
- Source:
FillError
An object describing an error which has occurred while filling a form.
Type:
Properties:
Name |
Type |
Description |
type |
string
|
A classification of the error [ 'validation', 'general', 'page' ] |
msg |
string
|
Description of the error |
- Source:
FillResult
An object describing the result of filling a form.
Type:
Properties:
Name |
Type |
Description |
errors |
Array.<FillError>
|
A list of errors |
section |
string
|
The page number on which the errors occurred |
report |
Object
|
The report object which resulted from submitting the filled report. Undefined if an error blocks form submission. |
additionalDocs |
Array.<Object>
|
An array of database documents which are created in addition to the report. |
- Source:
cht-conf-test-harness provides interfaces for mocking all inputs so you can easily test the possible behaviors of your configuration.
The data of the HarnessInputs represents the environment/data in which your forms, tasks, targets, and contact-summaries are running within your CHT application.
You can provide default values for these inputs through a file called `harness.defaults.json` in your configuration project's folder ([example](https://github.com/medic/cht-conf-test-harness/blob/master/harness.defaults.json.example)).
Properties:
Name |
Type |
Description |
user |
string
|
Object
|
This represents the current user that is logged into the system. Use this for testing whenever your system behaves differently for different users.
In harness.fillForm(), this is the data bound to `inputs/user` (hydrated).
In harness.getTargets(), this is the global `user` object available in targets.js. (hydrated)
In harness.getTasks(), this is the global `user` object available in tasks.js. (hydrated)
In contact-summary code, this is the global `user` object in contact-summary.templated.js. (hydrated) |
userRoles |
Array.<string>
|
This represents the 'roles' assigned to the current user that is logged in. Roles control the user's permissions ([roles documentation](https://docs.communityhealthtoolkit.org/apps/concepts/users/#roles)) |
subject |
string
|
Object
|
This represents the contact that is being "acted on" or the "subject of the test".
The harness.fillForm() function simulates "completing an action" on the subject's profile page.
The harness.getTasks() function returns the tasks listed on the subject's profile page.
The harness.getContactSummary() function returns the contact summary information displayed for the subject.
`subject` can be an `object` or a `string`. Assigning `subject` a `string` should be preferred as it will result in behavior closest to the CHT. The `subject` should be set to the `_id` of the contact document present
in `HarnessInputs.docs`. The harness will pull in the appropriate contact and hydrate it automatically. Assigning `subject` an `object` will skip any integration with `docs` and skips hydration - the exact value set
will be used. This is powerful and useful for unit testing, but should be avoided during integration testing. |
content |
Object
|
This is the data that will be passed into an XForm via loadForm(). Tasks have the ability to set this data via the
modifyContent interface.
Recommendeded to leave this undefined in `harness.defaults.json`. |
contactSummary |
Object
|
Set this value to mock the data passed into app forms via `instance('contact-summary')/context`. This is mocking the
context information that is
returned by the contact-summary. If left empty, the `context` returned by getContactSummary will be used. |
docs |
Array.<Object>
|
This simulates the documents on the user's device when the test begins. |
- Source:
- See:
-
- userRoles For setting the user's role
Examples
harness.userRoles = ['chw']
harness.defaults.json using subject as a string (preferred)
{
"coreVersion": "3.10.3",
"subject": "patient_id",
"docs": [
{
"_id": "patient_id",
"name": "Sick Bob",
"type": "person",
"reported_date": 1550559625153,
"parent": {
"_id": "family_id",
"parent": {
"_id": "chw_area_id"
},
}
},
{
"_id": "family_id",
"type": "clinic",
"parent": {
"_id": "chw_area_id"
},
},
]
}
harness.defaults.json using mock object
{
"coreVersion": "3.10.3",
"subject": {
"_id": "patient_id",
"name": "Sick Bob",
"type": "person",
"reported_date": 1550559625153,
"parent": {
"_id": "family_id",
"type": "clinic",
"parent": {
"_id": "chw_area_id"
},
}
},
"docs": []
}
HarnessState
Properties:
Name |
Type |
Description |
console |
Array.<Object>
|
Each element represents an event within Chrome console. |
contacts |
Array.<Object>
|
All contacts known to nools. |
reports |
Array.<Object>
|
All reports known to nools. |
- Source:
Target
An emitted target. The structure of emitted targets may vary by the version of cht-conf and the version of the medic webapp. In general, target have this structure.
Properties:
Name |
Type |
Description |
value |
Object
|
The aggregated calculation based on the instances.
Properties
Name |
Type |
Description |
pass |
boolean
|
|
total |
number
|
|
percent |
number
|
|
|
- Source:
Task
Properties:
Name |
Type |
Description |
_id |
uuid
|
|
user |
string
|
The user settings id of the user who calculated and created the document. Used for controlling replication. (eg. org.couchdb.user:agatha) |
requester |
uuid
|
The guid of the contact whose data brought about the creation of the document. Used for controlling cancellation. |
owner |
uuid
|
string The guid of the contact whose profile this task will appear on in the contact’s tab. |
emission |
Object
|
Minified data emitted from the partner code.
Properties
Name |
Type |
Description |
forId |
uuid
|
If completing a task’s action opens a form. Completing the form creates a report. forId is the guid of the contact information that will be passed into the form. For most forms, the resulting report will be associated with this contact. |
title |
string
|
The "name" attribute of the task configuration |
contact.name |
string
|
The name that will appear beside the task on the tasks tab. The "contactLabel" attribute of the task configuration |
startDate |
date
|
The date at which time the task will be displayed to the user. Before this date, the task document will be in state "Draft". |
endDate |
date
|
The date at which time the task will no longer be displayed to the user. After this date, the task will move to state "Failed". |
|
stateHistory |
Array
|
Each time the state attribute changes, the time of the change is recorded in the state history. |
- Source: