From 97ff6886d2df98e5ca43b36fac4f809802ad8a3e Mon Sep 17 00:00:00 2001 From: eyelidlessness Date: Sun, 28 Apr 2024 08:45:40 -0700 Subject: [PATCH] First (top-down) `TriggerableDagTest.java` test port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’ll probably want to squash many of this branch’s commits. This one is only here so I can keep moving top down through JavaRosa’s test “bags”/“vats” (will never not be funny!), and so the next ported test can get a more meaningful commit note --- packages/scenario/test/calculate.test.ts | 52 ++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 packages/scenario/test/calculate.test.ts diff --git a/packages/scenario/test/calculate.test.ts b/packages/scenario/test/calculate.test.ts new file mode 100644 index 00000000..68239686 --- /dev/null +++ b/packages/scenario/test/calculate.test.ts @@ -0,0 +1,52 @@ +import { + bind, + body, + head, + html, + input, + mainInstance, + model, + t, + title, +} from '@odk-web-forms/common/test/fixtures/xform-dsl/index.ts'; +import { describe, expect, it } from 'vitest'; +import { intAnswer } from '../src/answer/ExpectedIntAnswer.ts'; +import { Scenario } from '../src/jr/Scenario.ts'; + +describe('TriggerableDagTest.java', () => { + /** + * **PORTING NOTES** + * + * Rephrase? While DAG ordering is certainly under test, and while it's an + * explicit spec concern, there's also more specific computation logic under + * test which is worth describing as the functionality under test. + */ + it('[recomputes `calculate` expressions when their dependencies are updated] order of the DAG is ensured', async () => { + const scenario = await Scenario.init( + 'Some form', + html( + head( + title('Some form'), + model( + mainInstance(t('data id="some-form"', t('a', '2'), t('b'), t('c'))), + bind('/data/a').type('int'), + bind('/data/b').type('int').calculate('/data/a * 3'), + bind('/data/c').type('int').calculate('(/data/a + /data/b) * 5') + ) + ), + body(input('/data/a')) + ) + ); + + expect(scenario.answerOf('/data/a')).toEqualAnswer(intAnswer(2)); + expect(scenario.answerOf('/data/b')).toEqualAnswer(intAnswer(6)); + expect(scenario.answerOf('/data/c')).toEqualAnswer(intAnswer(40)); + + scenario.answer('/data/a', 3); + + expect(scenario.answerOf('/data/a')).toEqualAnswer(intAnswer(3)); + expect(scenario.answerOf('/data/b')).toEqualAnswer(intAnswer(9)); + // Verify that c gets computed using the updated value of b. + expect(scenario.answerOf('/data/c')).toEqualAnswer(intAnswer(60)); + }); +});