aglinxinyuan opened a new pull request, #7355:
URL: https://github.com/apache/texera/pull/7355

   ### What changes were proposed in this PR?
   
   Every toolbar action in the description editor — bold, link, and the rest — 
routes through `insert`, and it was the one method in the component with no 
coverage (the spec had 15 tests, none touching it).
   
   It splices the action's prefix and suffix around the current textarea 
selection, so wrong offsets silently corrupt the text the toolbar is meant to 
format:
   
   ```
   "hello world!"  select [6,11]  +  {prefix:"**", suffix:"**"}   ->  "hello 
**world**!"
   "hello "        caret  [6,6]   +  {default:"bold text"}        ->  "hello 
**bold text**"
   "see docs"      select [4,8]   +  {prefix:"[", suffix:"](url)"} ->  "see 
[docs](url)"
   ```
   
   Four tests, driving the **real textarea from the template** with 
`selectionStart`/`selectionEnd` set the way a user's selection would be, rather 
than stubbing the ViewChild:
   
   - a selection is wrapped and the text either side survives
   - a collapsed caret inserts the action's placeholder instead
   - the action's own **suffix** is used, not a second copy of the prefix — a 
link action is asymmetric, so a symmetric wrap passes a bold test but breaks 
links
   - the preview re-renders from the **spliced** text, not the old text
   
   **Verified by mutation**, all reverted (component diff empty):
   
   | Mutation | Result |
   |---|---|
   | always use `action.default`, ignoring the selection | red |
   | use the prefix on both sides instead of the suffix | red |
   | drop the `renderMarkdown` call | red |
   
   Two lifecycle details are commented in the spec, because each cost a 
debugging round and the next person will hit them:
   
   - The fixture needs **two** change-detection cycles. `ngOnInit` forces 
preview mode, so an edit mode set before the first `detectChanges()` is 
silently overwritten and the `@ViewChild("textarea")` never resolves — the 
symptom is `Cannot read properties of undefined (reading 'nativeElement')`.
   - The render assertion drains the microtask queue instead of awaiting 
`whenStable()`. `insert` schedules a `requestAnimationFrame` to refocus the 
textarea, which leaves the zone permanently unstable; `whenStable()` there 
hangs until the 5s timeout.
   
   No production file is touched.
   
   ### Any related issues, documentation, discussions?
   
   Closes #7353
   
   ### How was this PR tested?
   
   ```
   npx ng test --watch=false 
--include="**/markdown-description.component.spec.ts"
   ```
   
   ```
    Test Files  1 passed (1)
   ```
   
   4 new tests on top of the existing 15. `yarn format:ci` passes.
   
   ### Was this PR authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Opus 5)
   
   


-- 
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]

Reply via email to