Ma77Ball opened a new issue, #5464:
URL: https://github.com/apache/texera/issues/5464
### Task Summary
### Task Summary
`FormlyRepeatDndComponent`
(`frontend/src/app/common/formly/repeat-dnd/repeat-dnd.component.ts`) has no
`*.spec.ts`
file. It is a small Formly field type whose only public method is
`onDrop(event)`, which
reorders a drag-and-drop list. There is a single, well-defined behavior to
lock down with
tests.
`onDrop(event: CdkDragDrop)`:
- returns early (no-op) when `this.model` is falsy or `previousIndex ===
currentIndex`;
- otherwise calls `moveItemInArray` on `this.model` and on
`this.field.fieldGroup`, then
removes and re-inserts the control on `this.formControl` at the new index;
- finally calls `this.props.reorder()` if that callback is defined.
### What to do (step by step)
1. Create
`frontend/src/app/common/formly/repeat-dnd/repeat-dnd.component.spec.ts` with
the Apache license header.
2. The component extends Formly's `FieldArrayType`, so the test must
populate the fields
it reads: set `component.model`, `component.field` (with a `fieldGroup`
array and
`props`), and `component.formControl` (a `FormArray`) before calling
`onDrop`.
3. Build a fake `CdkDragDrop` as a plain object: `{ previousIndex: 0,
currentIndex: 2 }`
(cast `as any` in the test is fine).
4. Cover the cases below.
5. Run `yarn test -- repeat-dnd`, then `yarn lint`.
### Cover
- `should create`.
- No-op when `previousIndex === currentIndex`: model/array unchanged and
`reorder` not
called.
- No-op when `this.model` is undefined.
- Happy path: items in `model` are reordered; `props.reorder` (a `vi.fn()`)
is called once.
### Notes / mocks
- `moveItemInArray` is a pure CDK helper; you do not need to mock it. Just
assert the
resulting array order.
- Use a real `FormArray` from `@angular/forms` (`new FormArray([...])`) so
`at/removeAt/insert` behave correctly.
- `props.reorder` should be a `vi.fn()` so you can assert it was called.
### Task Type
- [ ] Refactor / Cleanup
- [ ] DevOps / Deployment / CI
- [x] Testing / QA
- [ ] Documentation
- [ ] Performance
- [ ] Other
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]