Skip to content

Commit

Permalink
First (top-down) TriggerableDagTest.java test port
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eyelidlessness committed May 16, 2024
1 parent 90eb940 commit 97ff688
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/scenario/test/calculate.test.ts
Original file line number Diff line number Diff line change
@@ -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));
});
});

0 comments on commit 97ff688

Please sign in to comment.