Skip to content

Commit

Permalink
Test harness documentation improvement (#935)
Browse files Browse the repository at this point in the history
* Correct naming of search and filter bars

Changed the name from filter to search-filter and search to search-bar

* Checking image file renderring

* Image location

* Adding Muting docs

* Features section for muting docs 1st version

* Features section for muting docs 2nd version

* Improvement of test-harness-documentation

* Correcting test harness branch (#937)

* Update App Hosting guide to work with 3.x, call out it won't work with 4.x (#801)

* Update to work with 3.x, call out it won't work with 4.x

* Update content/en/apps/guides/hosting/app-developer.md

Co-authored-by: Joshua Kuestersteffen <[email protected]>

Co-authored-by: Joshua Kuestersteffen <[email protected]>

* Correct field refrence in API Improve #807 (#808)

* Tiny update from filter redesign work. (#784)

* convert all compose files to use 3.x for now until 4.0 is out (#809)

* Add Preparing to upgrade to CHT 4.0 guide  (#806)

* Add Preparing to upgrade to CHT 4.0 guide

* Update content/en/apps/guides/updates/preparing-for-4.0.md

Co-authored-by: Joshua Kuestersteffen <[email protected]>

* Update content/en/apps/guides/updates/preparing-for-4.0.md

Co-authored-by: Joshua Kuestersteffen <[email protected]>

* Update content/en/apps/guides/updates/preparing-for-4.0.md

Co-authored-by: Joshua Kuestersteffen <[email protected]>

* Add extensive Enketo notes per feedback

* update sql queries per feedback

* add note about empty versions

* Update content/en/apps/guides/updates/preparing-for-4.0.md

Co-authored-by: Joshua Kuestersteffen <[email protected]>

* Update content/en/apps/guides/updates/preparing-for-4.0.md

Co-authored-by: Joshua Kuestersteffen <[email protected]>

* Update content/en/apps/guides/updates/preparing-for-4.0.md

Co-authored-by: Joshua Kuestersteffen <[email protected]>

Co-authored-by: Joshua Kuestersteffen <[email protected]>

* add sample privacy policy HTML (#810)

* Release notes for v3.17.0 (#767)

* Change recommended Enketo form test branch to enketo_upgrade_3.x (#811)

* Updates to use mediators, not moderators

#813

* Fixes broken link

Related to #816

* Links directly to PDF file

The fixed link was to the GH page for the PDF. Updated to link directly to the PDF file.

* Split 3.x hosting docs off, create 4.x hosting section (#812)

* Split 3.x hosting docs off, create 4.x hosting section

* Everything but local setup done - and of course no 4.x docs yet ;)

* finalize local-setup

* remove dupe line per feedback

* Update content/en/apps/tutorials/local-setup.md

Co-authored-by: Gareth Bowen <[email protected]>

Co-authored-by: Gareth Bowen <[email protected]>

* Supervisor reference app (#792)

* Documentationf for application tests

* Moving the pages to the `tutorials` section, as mentioned in #32, confirmed with the author

* Adding page for application tests

* Application tests

* Remove old files

* Update application-tests.md

* Add related content, text changes

* Apply suggestions from code review

Co-authored-by: Niraj <[email protected]>

* Follow guidelines

* Added supervisor reference app in examples

* Update supervisor-reference-app.md (#799)

* Update content/en/apps/examples/supervisor-reference-app.md

Co-authored-by: Marc Abbyad <[email protected]>

* Update content/en/apps/examples/supervisor-reference-app.md

Co-authored-by: Ashley <[email protected]>

* Update content/en/apps/tutorials/application-tests.md

Co-authored-by: Ashley <[email protected]>

* Update content/en/apps/tutorials/application-tests.md

Co-authored-by: Ashley <[email protected]>

* Update content/en/apps/tutorials/application-tests.md

Co-authored-by: Ashley <[email protected]>

* Update content/en/apps/tutorials/application-tests.md

Co-authored-by: Ashley <[email protected]>

* Add files via upload

added images for supervisor reference app

* Updated supervisor reference app documentation.

GitHub link is still pending

* Update content/en/apps/tutorials/application-tests.md

* Update content/en/apps/tutorials/application-tests.md

* Update content/en/apps/examples/supervisor-reference-app.md

* Update content/en/apps/tutorials/application-tests.md

* Update content/en/apps/tutorials/application-tests.md

* Update content/en/apps/tutorials/application-tests.md

* Update content/en/apps/tutorials/application-tests.md

* Update content/en/apps/tutorials/application-tests.md

* Update content/en/apps/tutorials/application-tests.md

* Update content/en/apps/tutorials/application-tests.md

* Update content/en/apps/tutorials/application-tests.md

* Update content/en/apps/tutorials/application-tests.md

* bold table item per feedbac

* fix closing highlight tag

* remove unused image, clean up table image code

* remove unused image, clean up table image code

* make all images transparent

* fix arrows

* update table headers

Co-authored-by: Paul Kitutu <[email protected]>
Co-authored-by: Binod Adhikary <[email protected]>
Co-authored-by: Binod Adhikary <[email protected]>
Co-authored-by: Antony <[email protected]>
Co-authored-by: Marc Abbyad <[email protected]>
Co-authored-by: Ashley <[email protected]>
Co-authored-by: mrjones-plip <[email protected]>

* Differentiate titles (#818)

* Update headers (#822)

For #821

* add known issues dynamic link to >=3.10 (#824)

* Update documentation removing manual testing

We no longer require manual release testing so this section has been updated.
Also updated the "triage" section which hasn't been used for some time.

* Add release notes for 4.0.0

medic/cht-core#7804

* Document MacOS M1 errors (#832)

Co-authored-by: Andra Blaj <[email protected]>

* Document python2 config for MacOS (#838)

* Fix typo (#833)

* Fix hosting setup guides links

* Remove references to Travis

medic/cht-core#7001

* Add App Dev hosting for 4.x  (#834)

* Add App Dev hosting for 4.x per #829

* typo and add link

* list benefits

* Update content/en/apps/guides/hosting/4.x/app-developer.md

Co-authored-by: Gareth Bowen <[email protected]>

* Update content/en/apps/guides/hosting/4.x/app-developer.md

Co-authored-by: Gareth Bowen <[email protected]>

* Update content/en/apps/guides/hosting/4.x/app-developer.md

Co-authored-by: Gareth Bowen <[email protected]>

* Update content/en/apps/guides/hosting/4.x/app-developer.md

Co-authored-by: Gareth Bowen <[email protected]>

* Update content/en/apps/guides/hosting/4.x/app-developer.md

Co-authored-by: Gareth Bowen <[email protected]>

* fix code indentations

* update screenshot of helper

* Update content/en/apps/guides/hosting/4.x/app-developer.md

Co-authored-by: Gareth Bowen <[email protected]>

Co-authored-by: Gareth Bowen <[email protected]>

* Automate the delete branch step

* call out no support for Apple M1/M2 support (#844)

* Update supervisor-reference-app.md (#850)

* Update core developer setup for CHT 4.x (#848)

* Document python2 config for MacOS
* Update doc with developer setup for 4.x

* add iccm immunization icon (#836)

* add iccm immunization icon

* add png

* Make upgrade instructions harder to miss

* Add PIH to example apps (#771)

* Add content

* Update content/en/apps/examples/pih.md

Co-authored-by: Marc Abbyad <[email protected]>

* Add links

* updated with pih documentation file and images

* updated hierarchy image

* PIH CHT documentation updates (#826)

* Update pih.md

* Update pih.md

* Update pih.md

Co-authored-by: Niraj <[email protected]>

* Add files via upload

* Add files via upload

* Update pih.md

changed form names to bold fonts

* Update pih.md

converted image to markdown table with text.

* Delete Human_Immunodeficiency_Virus.png

removing unused images

* Delete IMCI_workflow.png

removing unused images

* Delete TB_workflow.png

removing unused images

* Delete TB_workflow_screened.png

removing unused images

* Delete delivery_workflow.png

* Delete family_planning_workflow.png

* Delete malnutrition_workflow.png

* Delete post_natal_workflow.png

* Delete pregnancy_workflow.png

* Delete ncd.png

* Delete ncd_1.png

* Delete users_hierarchy.png

Co-authored-by: Marc Abbyad <[email protected]>
Co-authored-by: Niraj <[email protected]>
Co-authored-by: Antony <[email protected]>

* 820 improve hierarchy diagram on supervisor reference application (#852)

* Updated hierarchy image

* updated hierarchy image

* Fix path on staging for compose files (#857)

* Document `bind-id-only` (#847)

* Includes bind-id-only

#842

* Cleanup

* Adds `bind-id-only`

Also move warning closer to context.

* Document bulk user upload column names and add ready-to-go spreadsheets (#858)

* Remove sensitive words

medic/cht-core#6574

* Add notes about 24 hour feedback for PR reviews. (#863)

Add notes about 24 hour feedback for PR reviews.

Co-authored-by: Gareth Bowen <[email protected]>

* Refactor XForm widgets (#862)

The widgets were previously in a bulleted list, which made the flow difficult to read, and impossible to link to individual widgets in documentation. This version moves each widget to its own subsection so that they can be referenced properly. This structure also allows for further details to be included, such as screenshots and other details for their use. 

For #861

* Fix reference to unsupported value

#867

* Fix typo in rapidpro endpoint

medic/cht-core#7472

* Fix broken link in demo form (#869)

#868

* Update architecture docs for 4.0.0

* Fix order of instructions 

medic/cht-core#7928

* Fixes header (#876)

Also restructures some of the text for logical flow.

For #875

* add dir hierarchy and tidy up compose up call  (#874)

* add dir hierarchy and tidy up compose up call per #873

* change compose file names per feedback

* add note about default contact in 3.17 (#769)

* add note about default contact in 3.16

* oop! 3.17, not 3.16

* Documentation on where to place images when making changes to the doc-site (#881)

* Adding documentation on where to place images when making changes to the docsite

* make image smaller and add arrows

Co-authored-by: mrjones-plip <[email protected]>

* Updates content to be more current

* Updates language and headers
* Includes national scale
* Adds more kickoff resources

* Revert build name (#871)

For #870

* Add horti links, use beta1 example of install

* Document the /api/v2/users API

medic/cht-core#7592

* Add wash PNG icons (#880)

* Add wash PNG icons

* Add wash SVG icons

* 4.0.1 release notes (#885)

* Remove relative paths from .env file (#891)

* update docker helper to be current (#882)

* update docker helper to be current

* Update content/en/apps/guides/hosting/4.x/app-developer.md

Co-authored-by: Joshua Kuestersteffen <[email protected]>

* tell that destroy is no joke, yo, per feedback

* call out that down doesn't delete any data

* call out which platforms we support

* call out m1/m2 support

* Update content/en/apps/guides/hosting/4.x/app-developer.md

Co-authored-by: Joshua Kuestersteffen <[email protected]>

* Update content/en/apps/guides/hosting/4.x/app-developer.md

Co-authored-by: Joshua Kuestersteffen <[email protected]>

* Update content/en/apps/guides/hosting/4.x/app-developer.md

Co-authored-by: Joshua Kuestersteffen <[email protected]>

* Update content/en/apps/guides/hosting/4.x/app-developer.md

Co-authored-by: Joshua Kuestersteffen <[email protected]>

Co-authored-by: Joshua Kuestersteffen <[email protected]>

* Bulk delete redesign (#815)

Ticket: medic/cht-core#7778

* 3.16.1 release notes (#886)

* 3.17.1 release notes (#887)

* Fix typo on interoperability page (#898)

* Updates build once section (#889)

Clarified with more up to date language

* Add documentation for create_users_for_contacts transition (#805)

Co-authored-by: Ashley <[email protected]>

* Update 4.0 prep guide to point to Enekto feature release (#890)

* fix deprecated use of down -> stop (#893)

* update helper screenshot to be current (#894)

* update to latest youtube video (#896)

* Change Targets date property default to "now"

The original issue is Target's date property should default to "now"#516.
This PR update the documentation after the PR got approved.
Now that the Target's date property default to 'now', we are updating the docs accordingly.

* Move from master to 4.0.1 as  stop gap (#904)

* Fix broken internal link to monitoring API docs (#905)

* Document RapidPro credentials (#903)

* Rearrange existing docs into handbook top level dir

#895

* Include link to already prepared documentation

* 4.1.0 release notes (#907)

* Remove unexecutable comment, use $0 instead of explicit shell (#912)

* Adding detail to hugo install and troubleshooting (#913)

* Adding detail to hugo install and troubleshooting

* Make it mo' OS agnostic

* fix spelling of "infrastracture" (#917)

* Update of CHT4 local setup documentation (#897)

* This is the first commit for WIP update of CHT4 local setup documentation

* Update content/en/apps/tutorials/local-setup.md

Remove hard-corded command and replace with troubleshooting guide

Co-authored-by: Ashley <[email protected]>

* Actioning on comments added by Andra and Ashley

Co-authored-by: Ashley <[email protected]>

* Add "code suggestion" recommendation to review docs (#920)

For now this seems to be the best place for this recommendation, but ideally we have a set of more detailed pages on code reviews. We currently link out to other recommendations (cool, since there's no need to duplicate all that), but it means not really having a good landing page for all this. For the time being I'm adding this here, but if we expand our code review guidance, this section should move to whatever comes in the future.

* Adds icon and favicons

For #900

* Broken link in How To Manage Translations documentation. (#923)

* Add files via upload

* Update content/en/core/overview/translations.md

Co-authored-by: Marc Abbyad <[email protected]>

Co-authored-by: Marc Abbyad <[email protected]>

* view old action bar permission (#914)

This adds details about the feature flag to enable the old action bar. This permission will hide the More Options menu and FAB.

medic/cht-core#7872

* Adding documentation on task owner vs requester (#902)

* Adding documentation on task owner vs requester

* Ommiting guid explanation

* Adding glossary for guid

* Adding GUID to gloassary list

* Make favicon suitable for dark and light modes (#927)

Uses the negative logo with a gradient similar to the original CHT logo so that it stands out on different colored tabs.

For #924 and #900

* Update 4.0 Upgrade Guide to note `+` operator does not work with strings (#926)

* Update cht4 local setup docs - adding line to ensure .sh file is available under scripts folder (#928)

* This is the first commit for WIP update of CHT4 local setup documentation

* Update content/en/apps/tutorials/local-setup.md

Remove hard-corded command and replace with troubleshooting guide

Co-authored-by: Ashley <[email protected]>

* Actioning on comments added by Andra and Ashley

* Adding line on ensuring .sh file is available

* Update content/en/apps/tutorials/local-setup.md

Co-authored-by: Ashley <[email protected]>

Co-authored-by: Ashley <[email protected]>

* Update 4.0 Upgrade Guide with new cht-conf-test-harness version (#931)

* Add note to upgrade guide about bulleted list bug (#933)

* Add FR install instructions for 4.x (#934)

* Setting up branch to merge with test-harness-branch

Co-authored-by: Ashley <[email protected]>
Co-authored-by: Joshua Kuestersteffen <[email protected]>
Co-authored-by: Yauvaraj Rimal <[email protected]>
Co-authored-by: Jennifer Q <[email protected]>
Co-authored-by: Marc Abbyad <[email protected]>
Co-authored-by: Gareth Bowen <[email protected]>
Co-authored-by: Niraj <[email protected]>
Co-authored-by: Paul Kitutu <[email protected]>
Co-authored-by: Binod Adhikary <[email protected]>
Co-authored-by: Binod Adhikary <[email protected]>
Co-authored-by: Antony <[email protected]>
Co-authored-by: mrjones-plip <[email protected]>
Co-authored-by: Andra Blaj <[email protected]>
Co-authored-by: Andra Blaj <[email protected]>
Co-authored-by: ulrichanani-muso <[email protected]>
Co-authored-by: Nicole Orlowski <[email protected]>
Co-authored-by: Elijah Karari <[email protected]>
Co-authored-by: Mokhtar <[email protected]>
Co-authored-by: Craig Landry <[email protected]>
Co-authored-by: Diana Barsan <[email protected]>
Co-authored-by: elvisdorkenoo <[email protected]>
Co-authored-by: Michael Kohn <[email protected]>

* Removing all additional files pushed from main

* Update content/en/apps/tutorials/application-tests.md

Co-authored-by: Binod Adhikary <[email protected]>

* Update content/en/apps/tutorials/application-tests.md

Co-authored-by: Binod Adhikary <[email protected]>

* Update content/en/apps/tutorials/application-tests.md

Co-authored-by: Binod Adhikary <[email protected]>

* Incorporating review suggestions

* Update content/en/apps/tutorials/application-tests.md

Co-authored-by: Binod Adhikary <[email protected]>

* Update content/en/apps/tutorials/application-tests.md

Co-authored-by: Binod Adhikary <[email protected]>

---------

Co-authored-by: Elijah Gichinga <[email protected]>
Co-authored-by: Ashley <[email protected]>
Co-authored-by: Joshua Kuestersteffen <[email protected]>
Co-authored-by: Yauvaraj Rimal <[email protected]>
Co-authored-by: Jennifer Q <[email protected]>
Co-authored-by: Marc Abbyad <[email protected]>
Co-authored-by: Gareth Bowen <[email protected]>
Co-authored-by: Niraj <[email protected]>
Co-authored-by: Paul Kitutu <[email protected]>
Co-authored-by: Binod Adhikary <[email protected]>
Co-authored-by: Binod Adhikary <[email protected]>
Co-authored-by: Antony <[email protected]>
Co-authored-by: mrjones-plip <[email protected]>
Co-authored-by: Andra Blaj <[email protected]>
Co-authored-by: Andra Blaj <[email protected]>
Co-authored-by: ulrichanani-muso <[email protected]>
Co-authored-by: Nicole Orlowski <[email protected]>
Co-authored-by: Mokhtar <[email protected]>
Co-authored-by: Craig Landry <[email protected]>
Co-authored-by: Diana Barsan <[email protected]>
Co-authored-by: elvisdorkenoo <[email protected]>
Co-authored-by: Michael Kohn <[email protected]>
  • Loading branch information
1 parent fcbe9ad commit 773943b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions content/en/apps/tutorials/application-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,31 @@ This tutorial takes you through testing the various configurable components of C

## Prerequisites

* Complete these tutorials:
Complete the following tutorials:
- [Building App Forms]({{< ref "apps/tutorials/app-forms" >}})
- [Building A Simple Task]({{< ref "apps/tutorials/tasks-1" >}})
- [Building Target Widgets]({{< ref "apps/tutorials/targets" >}})
- [Building Contact Summary]({{< ref "apps/tutorials/contact-summary" >}})

## Importance of testing your application
---
Testing your CHT application is important as it ensures you are consistently maintaining your application and defining implementation requirements. Testing also helps the user make better architectural decisions, optimizes the forms, tasks and other components of the application. Although it may seem tedious, testing your application ensures that you quickly discover issues that are introduced with changes or newer commits.
## CHT Application Testing

---

CHT applications are greatly configurable. Depending on the number and the complexity of the app components, it can take huge time and effort to test them manually. Some components, such as tasks, behave differently over time and are particularly difficult to test. As the project evolves, the configuration is often updated with new components, and changes are made to the existing components. After each change, you need to test not only the new components but also the old ones to make sure that the app works correctly. To facilitate the testing process, app builders are encouraged to write automated tests for their app using [cht-conf-test-harness](http://docs.communityhealthtoolkit.org/cht-conf-test-harness/).
CHT applications are greatly configurable. Depending on the number and complexity of app components, it can take a lot of time and effort to test the components manually. Some components, such as tasks, behave differently over time and are particularly challenging to test. As the project evolves, the configuration is often updated with new components and changes are made to the existing components. After each change, you need to test not only the new components, but also the old ones to make sure that the app works as expected. To facilitate the testing process, app builders are encouraged to write automated tests for their app using [cht-conf-test-harness](http://docs.communityhealthtoolkit.org/cht-conf-test-harness/).

Because it may be complicated to test with a real application, `cht-conf-test-harness` (also simply referred as `harness`), provides a platform that simulates the CHT application instance.

Using `cht-conf-test-harness` (also simply referred as `harness`), you can write tests and run them with [Mocha](https://mochajs.org/) testing framework to test the behavior of different components in a CHT application. You can use the [chai library](https://www.chaijs.com/) or other assertion libraries.
Using `cht-conf-test-harness`, you can write tests and run them with [Mocha](https://mochajs.org/) testing framework to test the behavior of different components in a CHT application. You can also use [chai library](https://www.chaijs.com/) or other assertion libraries.

## Preparing
## Preparation

Writing tests for CHT apps requires a good understanding of the project workflows and requirements. It is encouraged that the tests be written as part of the app-building process. To test using the harness, there are a few things you need to set up first:
1. From the previous tutorials, you should have a [functioning CHT instance with `cht-conf` installed locally]({{< ref "apps/tutorials/local-setup" >}}) and a [project folder set up]({{< ref "apps/tutorials/local-setup#3-create-and-upload-a-blank-project" >}}).
2. If your `package.json` file does not already have them, add `cht-conf-test-harness`, `chai`, and `mocha` by running this in your command-line:
Writing tests for CHT apps requires a good understanding of the project workflows and requirements. To test using the harness, there are a few things you need to set up:
1. From the previous tutorials, you should have a [functioning CHT instance with `cht-conf` installed locally]({{< ref "apps/tutorials/local-setup" >}}) and a [project folder set up]({{< ref "apps/tutorials/local-setup#3-create-and-upload-a-blank-project" >}}).
`cht-conf` which is short for CHT app configurer, is a command-line interface tool used to manage and configure your CHT apps. It is used for backup, conversion, validation, uploading and other actions which can be found by running `cht --help`.
2. Ensure your `package.json` file has the required libraries. A `package.json` file is used to record important metadata about a project and defines functional attributes that npm uses to install dependencies and run scripts. This file should be at the root of your project folder.
If your `package.json` file does not already have them, add `cht-conf-test-harness`, `chai`, and `mocha` by running this in your command-line:
```shell
npm install --save cht-conf-test-harness chai mocha
```
Expand All @@ -50,18 +56,30 @@ Writing tests for CHT apps requires a good understanding of the project workflow
```
After adding these scripts, you are able to run the tests by running one of these commands from the command-line:

|Command|Description|
|---|---|
|`npm run test`|Compiles the app settings, converts the forms, then runs the tests (preferred solution).
|`npm run unittest`|Only runs the tests.|
|Command|Description|
|---|---|
|`npm run test` |Compiles the app settings, converts the forms,then runs the tests (preferred solution).|
|`npm run unittest`| Only runs the unit tests.|

4. Create a folder in the project root where you keep the tests. You can name the folder yourself. For convenience, here it is named as `test`.
5. Create a file `harness.defaults.json` at the root of your project. This is the default configuration file for the harness. Here you can specify the default user, preloaded contacts and reports, and add other settings. Here's an [example](https://github.com/medic/cht-conf-test-harness/blob/master/harness.defaults.json.example) file to get you started. You can read more about it [here](https://docs.communityhealthtoolkit.org/cht-conf-test-harness/global.html#HarnessInputs).

You can also run the test on a specific form by defining a test under the scripts section.

For example, to run the test on the `death.spec.js` file, define the test as `death-form-unit-test: "mocha test/forms/death.spec.js --timeout 20000"`. Then run:
```shell
npm run death-form-unit-test
```

npm also supports a shorter alias as `npm test`. There are recommended conventions on how to arrange tests by splitting into unit tests and integration tests so that each of them can be run independently. This can be best illustrated by [this project code](https://github.com/medic/cht-pih-malawi-app).

4. Create a folder in the project root where you keep the tests. You can name the folder yourself. In this case it is named 'test'.
{{< figure src="test-folder-placement.png" link="test-folder-placement.png" class="col-9 col-lg-12" >}}

5. Create a file `harness.defaults.json` at the root of your project. This is the default configuration file for the harness. Here you can specify the default user, preloaded contacts and reports, and add other settings. Here's an [example](https://github.com/medic/cht-conf-test-harness/blob/master/harness.defaults.json.example) file to get you started. You can read more about it [here](https://docs.communityhealthtoolkit.org/cht-conf-test-harness/global.html#HarnessInputs).
{{< figure src="harness-json-file-placement.png" link="harness-json-file-placement.png" class="col-9 col-lg-12" >}}

## Writing a test for CHT App

Start by adding a file where a group of related tests are written. For example, in the default config, all tests for the pregnancy form are in the [pregnancy.spec.js](https://github.com/medic/cht-core/blob/master/config/default/test/forms/pregnancy.spec.js) file.
Start by adding a file where a group of related tests are written. For example, in the default config, all tests for the pregnancy form are in the [pregnancy.spec.js](https://github.com/medic/cht-core/blob/master/config/default/test/forms/pregnancy.spec.js) file. The common naming pattern for CHT applications test files is `filename.spec.js`. In JavaScript testing, `spec` is short for specifications which refers to technical details of a given application, that must be fulfilled.

Let's introduce some important sections from a typical test file:

Expand All @@ -72,8 +90,7 @@ const harness = new TestRunner();
```


You get an instance of `harness` and the same instance is used throughout the test file.

In the example above, we define values `TestRunner` and `harness`. You get an instance of `harness` and the same instance is used throughout the test file.
You can also pass parameters to the `TestRunner()` when instantiating:
```js
// For detailed console logs
Expand All @@ -94,7 +111,9 @@ describe('PNC form tests', () => {
after(async () => { return await harness.stop(); });
```
Any logic that you want to execute before and after each test can be placed in the `beforeEach()` and `afterEach()` hooks. Clear the state of the harness and set the date to a fixed value before each test run:
Any logic that you want to execute before and after each test can be placed in the `beforeEach()` and `afterEach()` hooks. This section ensures that the harness is reset to default before or after each run.
In the example below, the logic is to clear the state of the harness and set the date to '2000-01-01' before each test run:
```js
beforeEach(
async () => {
Expand Down Expand Up @@ -133,7 +152,7 @@ Let's look at a more detailed example. <a name="assessment-form-test">Here</a> i
});
```
In [line 3](#assessment-form-test-3) above, the method [harness.fillForm()](https://docs.communityhealthtoolkit.org/cht-conf-test-harness/Harness.html#fillForm) fills the specified form with the given input (answers).
In [line 4](#assessment-form-test-3) above, the method [harness.fillForm()](https://docs.communityhealthtoolkit.org/cht-conf-test-harness/Harness.html#fillForm) fills the specified form with the given input (answers).
Depending on the form design, the number of inputs to be filled can be large. The inputs are often repeated within a single test or across multiple tests with little or no variation. It is a good idea to keep them in a separate file and refer them from the tests as required. You can also introduce some variations in the inputs using function parameters.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 773943b

Please sign in to comment.