-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FormDefTest.java - port first test focused on interaction of repeat/o…
…utput … and an alternate approach, with proposed extension to `Scenario` API as opposed to further use of APIs corresponding to JavaRosa internals
- Loading branch information
1 parent
28934c0
commit b3279b0
Showing
3 changed files
with
213 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { AnyNode } from '@odk-web-forms/xforms-engine'; | ||
import { UnclearApplicabilityError } from '../../error/UnclearApplicabilityError.ts'; | ||
import type { Scenario } from '../Scenario.ts'; | ||
import type { JRFormDef } from '../form/JRFormDef.ts'; | ||
import type { JRFormIndex } from '../form/JRFormIndex.ts'; | ||
|
||
type AnyNodeCurrentState = AnyNode['currentState']; | ||
|
||
/** | ||
* **PORTING NOTES** | ||
* | ||
* It appears that this is an API used in JavaRosa to access `<label>`/`<hint>` | ||
* values and/or structures. It seems likely that this will correspond, at least | ||
* conceptually, to our notion of a node's properties with `TextRange` values | ||
* (i.e. currently {@link AnyNodeCurrentState.label} and | ||
* {@link AnyNodeCurrentState.hint}). | ||
* | ||
* This is currently stubbed to fail on construction. To the extent it's | ||
* reasonable, ported tests which exercise it will be accompanied by an | ||
* alternate approach, potentially exercising proposed extensions to | ||
* {@link Scenario}. | ||
*/ | ||
export class JRFormEntryCaption { | ||
constructor(_form: JRFormDef, _index: JRFormIndex) { | ||
throw new UnclearApplicabilityError("JavaRosa's `FormEntryCaption` API"); | ||
} | ||
|
||
getQuestionText(): string { | ||
throw new UnclearApplicabilityError("JavaRosa's `FormEntryCaption` API"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { | ||
bind, | ||
body, | ||
head, | ||
html, | ||
input, | ||
label, | ||
mainInstance, | ||
model, | ||
repeat, | ||
t, | ||
title, | ||
} from '@odk-web-forms/common/test/fixtures/xform-dsl/index.ts'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { Scenario } from '../src/jr/Scenario.ts'; | ||
import { JRFormEntryCaption } from '../src/jr/caption/JRFormEntryCaption.ts'; | ||
|
||
/** | ||
* **PORTING NOTES** | ||
* | ||
* There may be a more general category of multi-feature-interaction to be | ||
* found. This is the most obvious at time of porting. | ||
*/ | ||
describe('Interaction between `<repeat>` and `<output>`', () => { | ||
describe('FormDefTest.java', () => { | ||
/** | ||
* **PORTING NOTES** | ||
* | ||
* Rephrase? Unclear what "fill" was meant to reference here. | ||
*/ | ||
describe('[output?] fill template string', () => { | ||
/** | ||
* **PORTING NOTES** | ||
* | ||
* {@link JRFormEntryCaption} is stubbed, to fail on invocation. An | ||
* alternate test follows, exercising the apparent intent of this ported | ||
* test with a proposed addition to the {@link Scenario} API. | ||
*/ | ||
describe('[direct port/alternate - output resolves relative references]', () => { | ||
it.fails('resolves relative references', async () => { | ||
const scenario = await Scenario.init( | ||
'<output> with relative ref', | ||
html( | ||
head( | ||
title('output with relative ref'), | ||
model( | ||
mainInstance( | ||
t( | ||
'data id="relative-output"', | ||
t('repeat jr:template=""', t('position'), t('position_in_label')) | ||
) | ||
), | ||
bind('/data/repeat/position').type('int').calculate('position(..)'), | ||
bind('/data/repeat/position_in_label').type('int') | ||
) | ||
), | ||
body( | ||
repeat( | ||
'/data/repeat', | ||
input( | ||
'/data/repeat/position_in_label', | ||
label('Position: <output value=" ../position "/>') | ||
) | ||
) | ||
) | ||
) | ||
); | ||
|
||
scenario.next('/data/repeat'); | ||
scenario.createNewRepeat({ | ||
assertCurrentReference: '/data/repeat', | ||
}); | ||
scenario.next('/data/repeat[1]/position_in_label'); | ||
|
||
// FormEntryCaption caption = new FormEntryCaption(scenario.getFormDef(), scenario.getCurrentIndex()); | ||
let caption = new JRFormEntryCaption(scenario.getFormDef(), scenario.getCurrentIndex()); | ||
|
||
expect(caption.getQuestionText()).toBe('Position: 1'); | ||
|
||
scenario.next('/data/repeat'); | ||
scenario.createNewRepeat({ | ||
assertCurrentReference: '/data/repeat', | ||
}); | ||
scenario.next('/data/repeat[2]/position_in_label'); | ||
|
||
// caption = new FormEntryCaption(scenario.getFormDef(), scenario.getCurrentIndex()); | ||
caption = new JRFormEntryCaption(scenario.getFormDef(), scenario.getCurrentIndex()); | ||
|
||
expect(caption.getQuestionText()).toBe('Position: 2'); | ||
}); | ||
|
||
it('produces the output of an expression with a relative reference (alternate)', async () => { | ||
const scenario = await Scenario.init( | ||
'<output> with relative ref', | ||
html( | ||
head( | ||
title('output with relative ref'), | ||
model( | ||
mainInstance( | ||
t( | ||
'data id="relative-output"', | ||
t('repeat jr:template=""', t('position'), t('position_in_label')) | ||
) | ||
), | ||
bind('/data/repeat/position').type('int').calculate('position(..)'), | ||
bind('/data/repeat/position_in_label').type('int') | ||
) | ||
), | ||
body( | ||
repeat( | ||
'/data/repeat', | ||
input( | ||
'/data/repeat/position_in_label', | ||
label('Position: <output value=" ../position "/>') | ||
) | ||
) | ||
) | ||
) | ||
); | ||
|
||
scenario.next('/data/repeat'); | ||
scenario.createNewRepeat({ | ||
assertCurrentReference: '/data/repeat', | ||
}); | ||
scenario.next('/data/repeat[1]/position_in_label'); | ||
|
||
expect( | ||
scenario.proposed_getQuestionLabelText({ | ||
assertCurrentReference: '/data/repeat[1]/position_in_label', | ||
}) | ||
).toBe('Position: 1'); | ||
|
||
scenario.next('/data/repeat'); | ||
scenario.createNewRepeat({ | ||
assertCurrentReference: '/data/repeat', | ||
}); | ||
scenario.next('/data/repeat[2]/position_in_label'); | ||
|
||
expect( | ||
scenario.proposed_getQuestionLabelText({ | ||
assertCurrentReference: '/data/repeat[2]/position_in_label', | ||
}) | ||
).toBe('Position: 2'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |