Skip to content

Commit

Permalink
chore(tests): add test case for calculated questions in tables
Browse files Browse the repository at this point in the history
  • Loading branch information
luytena authored and winged committed Jan 24, 2025
1 parent ef36c55 commit b8deeaa
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions caluma/caluma_form/tests/test_complex_jexl.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,86 @@ def test_update_calc_dependency_inside_table(
" Field(demo-outer-question-1, demo-outer-question-1-outer-option-a)",
" Field(demo-outer-table-question-2, None)",
]


def test_update_calc_dependency_inside_table_with_outer_reference(
transactional_db, complex_jexl_form, complex_jexl_doc
):
doc, _, _ = complex_jexl_doc

assert get_doc_structure(doc) == [
"FieldSet(demo-formular-1)",
" Field(demo-outer-table-question-1, None)",
" FieldSet(demo-table-form-1)",
" Field(demo-table-question-1, 3)",
" Field(demo-table-question-2, 1)",
" FieldSet(demo-table-form-1)",
" Field(demo-table-question-1, 20)",
" Field(demo-table-question-2, None)", # TODO: Should be 100
" Field(demo-outer-question-1, demo-outer-question-1-outer-option-a)",
" Field(demo-outer-table-question-2, None)",
]

# TODO: This implementation corresponds to the current frontend logic, this
# might change so that table row documents are attached on creation
new_table_doc = api.save_document(form=Form.objects.get(pk="demo-table-form-2"))

assert get_doc_structure(new_table_doc) == [
" FieldSet(demo-table-form-2)",
" Field(demo-table-question-outer-ref-hidden, None)",
" Field(demo-table-question-outer-ref-calc, None)",
]

api.save_answer(
Question.objects.get(pk="demo-table-question-outer-ref-hidden"),
document=new_table_doc,
value=30,
)

assert get_doc_structure(new_table_doc) == [
" FieldSet(demo-table-form-2)",
" Field(demo-table-question-outer-ref-hidden, 30)",
" Field(demo-table-question-outer-ref-calc, 30)",
]

api.save_answer(
question="demo-outer-table-question-2", document=doc, value=[new_table_doc.pk]
)

assert get_doc_structure(doc) == [
"FieldSet(demo-formular-1)",
" Field(demo-outer-table-question-1, None)",
" FieldSet(demo-table-form-1)",
" Field(demo-table-question-1, 3)",
" Field(demo-table-question-2, 1)",
" FieldSet(demo-table-form-1)",
" Field(demo-table-question-1, 20)",
" Field(demo-table-question-2, 100)",
" Field(demo-outer-question-1, demo-outer-question-1-outer-option-a)",
" Field(demo-outer-table-question-2, None)",
" FieldSet(demo-table-form-2)",
" Field(demo-table-question-outer-ref-hidden, 30)",
" Field(demo-table-question-outer-ref-calc, 30)",
]

api.save_answer(
Question.objects.get(pk="demo-table-question-outer-ref-hidden"),
document=new_table_doc,
value=20,
)

assert get_doc_structure(doc) == [
"FieldSet(demo-formular-1)",
" Field(demo-outer-table-question-1, None)",
" FieldSet(demo-table-form-1)",
" Field(demo-table-question-1, 3)",
" Field(demo-table-question-2, 1)",
" FieldSet(demo-table-form-1)",
" Field(demo-table-question-1, 20)",
" Field(demo-table-question-2, 100)",
" Field(demo-outer-question-1, demo-outer-question-1-outer-option-a)",
" Field(demo-outer-table-question-2, None)",
" FieldSet(demo-table-form-2)",
" Field(demo-table-question-outer-ref-hidden, 20)",
" Field(demo-table-question-outer-ref-calc, 20)",
]

0 comments on commit b8deeaa

Please sign in to comment.