refactor(transcribe): extract t-mark + draw-cue policy into tested helpers (#327)
Some checks failed
CI / Unit & Component Tests (push) Failing after 2m33s
CI / OCR Service Tests (push) Successful in 24s
CI / Backend Unit Tests (push) Successful in 3m42s
CI / fail2ban Regex (push) Successful in 43s
CI / Semgrep Security Scan (push) Successful in 22s
CI / Compose Bucket Idempotency (push) Successful in 1m7s
Some checks failed
CI / Unit & Component Tests (push) Failing after 2m33s
CI / OCR Service Tests (push) Successful in 24s
CI / Backend Unit Tests (push) Successful in 3m42s
CI / fail2ban Regex (push) Successful in 43s
CI / Semgrep Security Scan (push) Successful in 22s
CI / Compose Bucket Idempotency (push) Successful in 1m7s
Review follow-up (Sara, fast-follow): the t no-active-region guard and the draw-cue arm/disarm rule lived inline in the page with no direct coverage. Extracted to pure resolveTrainingMark() (no-op when no region; recognition enrolled flip) and canArmDraw()/shouldDisarmDraw(), each with unit tests (10 cases total). The page now arms the draw cue only via canArmDraw and disarms via shouldDisarmDraw, and routes t through resolveTrainingMark. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit was merged in pull request #728.
This commit is contained in:
20
frontend/src/lib/document/transcription/drawCue.ts
Normal file
20
frontend/src/lib/document/transcription/drawCue.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Policy for the "draw a new region" keyboard cue (the `n` shortcut) in the
|
||||
* transcribe panel — issue #327.
|
||||
*
|
||||
* The cue is only valid while editing: `n` arms it in edit mode, and it must
|
||||
* clear when a region is drawn or when the panel leaves edit mode. Pure so both
|
||||
* rules are testable without mounting the page.
|
||||
*/
|
||||
|
||||
type PanelMode = 'read' | 'edit';
|
||||
|
||||
/** The draw cue may only be armed while in edit mode. */
|
||||
export function canArmDraw(panelMode: PanelMode): boolean {
|
||||
return panelMode === 'edit';
|
||||
}
|
||||
|
||||
/** Leaving edit mode must disarm the draw cue. */
|
||||
export function shouldDisarmDraw(panelMode: PanelMode): boolean {
|
||||
return !canArmDraw(panelMode);
|
||||
}
|
||||
Reference in New Issue
Block a user