XForm
is an object editor and a form generator
- it accepts object in v-model
- it accepts array of objects in
fields
property - it renders
<form>
with same amount of child elements as length offields
array - each
field
in fields describes a configuration for a child field.component
gets the name of the component (or tag) that should be rendered (for example it can beinput
, orselect
, ordiv
, etc.). Default:input
.field.field
get the name of the key of the v-model object to editfield.field
value is used asname
attribute of the child- all other properties are binded as html attributes (such as
type
,placeholder
, etc.) - when value of input is changed, it updates v-model
- examples in
App.vue
work as expected:XForm
with paramteresmyObjectN
andmyFieldsN
should render into htmlmyResultN
-
Approaches to testing -- What makes more sense?
1a. Map each acceptance criteria to a single test -- so that there are exactly 10 tests. Then I ask myself if a criterion like 1 is even strictly testable.
1b. Synthesize tests from multiple criteria -- e.g. Test 1 covers generic HTML generation (could cover criteria 1, 2, 3), test 2 covers attribute generation (could cover criteria 8), test 3 covers reactivity (could cover criteria 9), and so on. This seems like a more efficient approach on the surface, but synthesizing tests is overhead and trying to keep the criteria apart while covering them all seems like it could get messy fast.
-
Does it make sense to test directly for generated HTML? That seems precise but fragile -- tests start to break on the slightest change to the markup.
-
Is there a more elegant way to get all the children of a DOM element?
wrapper.findAll('form')[0].children
=== undefined -
Does it make sense to test the emits? Seems like in this case, the result is what matters and we test that by checking the HTML.
-
This implementation seems to meet the acceptance criteria. However, from a common sense perspective, I felt the need to refine it so that a field with
field.component = 'div'
renders{{modelValue[field.field]}}
as its text. I didn't do this because last time I got docked points for doing more than asked for. I thought that this merits a comment because not seeing this in the criteria gave me pause for a moment. -
type='datetime' doesn't seem to meaningfully change an . Should it be 'datetime-local'? Again, kept to the criteria.
-
The challenge specifies to use composition API but the component XForm starts out with the Option API, which suggests otherwise.