Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to set values to fields regardless of its attributes #139

Closed
latin-panda opened this issue Sep 9, 2021 · 3 comments
Closed

Add a way to set values to fields regardless of its attributes #139

latin-panda opened this issue Sep 9, 2021 · 3 comments

Comments

@latin-panda
Copy link

Is your feature request related to a problem? Please describe.
It'd be helpful to have a way to set values to fields regardless of its attributes (hidden, required, readonly, ...)

For example a field is required but has appearance hidden, then when running test case, it can't set the value (current validation code) and an error occurs when filling the form: “Required fields missing”

--- form inputs file ----
module.exports = {
  my_form: [['a09b9570-116e-11ec-82a8-0242ac130003'], [], [-12.113344], ['RUNNING']],

--- test case ----

it('Should show correct task when form is submitted', async () => {
    const result = await harness.fillForm('my_form', ...formInputs.my_form);

Describe alternatives you've considered
It'd be nice to use field name + group(s) name to find a field regardless if it’s visible, required, optional, readonly, hidden, or location deepness (groups). So we can pass something like key:value

"/inputs/contact/parent/name": "Facility abc"
-------- then
$([name="field_key"]).value(field_value) 
  • It doesn't rely in array position, if same level groups change order, the test won't be affected. No need to add empty arrays representing pages.
  • Easier to spot errors while building the form inputs for tests, because field location is specified. So no unexpected fields getting wrong values.
  • Have to check or be careful about performance if doing this approach.
  • Have to be backward compatible to not break existing tests.

Additional context
We were designing a form where some fields are automatically populated after a button action, these fields have hidden appearance because the data wasn't friendly or not relevant to the user, additionally the fields are required to prevent the user of continuing to the next page without performing the action.

Samples:

type name label appearance required default ...
string case_uuid NO_LABEL hidden yes ...
string latitude NO_LABEL hidden yes ...

At the end to move forward, we've worked around the form design because test coverage is important however the UX decreased.

@kennsippell
Copy link
Member

kennsippell commented Sep 9, 2021

Thanks for te issue @latin-panda! Consider this workaround which has been used with forms containing cht widgets to set values or make fields not required. You'll have to execute this magic after you loadForm and before you fillForm.

await harness.loadForm('myform');
await harness.page.evaluate(() => $$('input[name$="/breath_timer"]').removeAttr('data-required')`
const result = await harness.fillForm(['a'], ['b']);
expect(result.errors).to.be.empty;

https://github.com/medic/config-muso/blob/master/test/widget-hacks.js

Currently, the behaviour of fillForm strictly emulates the behaviour of users. Completing operations like "set the arbitrary value for this hidden field" is a paradigm shift away from that - which is fine, but also feels a bit hacky as tests reach into the internals of the system-under-test and alter the system's behaviour. I suspect what might be preferred is to support cht-core enketo widgets as first-class citizens in the harness. #46 so tests aren't responsible for "spooky data setting to emulate behaviour of widgets". Or using e2e tests with the ful cht-core stack.

@kennsippell
Copy link
Member

Please reactivate if the above workaround is not satisfactory.

@kennsippell
Copy link
Member

Please reactivate if the above workaround is not satisfactory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants