Skip to content

fix(aluno): finish-button hint + duration clamp (v2, rebased on #182)#184

Merged
EmiyaKiritsugu3 merged 3 commits into
mainfrom
fix/card-treino-empty-hint-v2
Jul 6, 2026
Merged

fix(aluno): finish-button hint + duration clamp (v2, rebased on #182)#184
EmiyaKiritsugu3 merged 3 commits into
mainfrom
fix/card-treino-empty-hint-v2

Conversation

@EmiyaKiritsugu3

@EmiyaKiritsugu3 EmiyaKiritsugu3 commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Two small aluno-side bug fixes bundled (v2 — rebased fresh on main after PR #182 merge; old PR #183 had WorkoutSession.tsx conflicts).

1. Dead finish-button UX — card-treino.tsx

Button "Finalizar e Avaliar Treino" disabled silently when completedCount === 0. No visual precondition feedback → users perceive dead button. Added conditional hint below button:

{completedCount === 0 && !isFeedbackLoading && (
  <p data-testid="finish-hint" className="text-sm text-muted-foreground text-center">
    Marque os exercícios concluídos acima para finalizar o treino.
  </p>
)}

3 new unit tests (hint visible, hint hides on check, stateful useWorkoutTracker mock with mockReturnValue override + rerender).

2. Toast "inesperado ao salvar no histórico" — WorkoutSession.tsx:173

Zod schema HistoricoTreinoBaseSchema requires duracaoMinutos: z.coerce.number().int().min(1). Quick workout (<30s) → Math.round((end - start) / 60000) returns 0 → schema fail → toast. Defensive clamp:

const duracaoMinutos = Math.max(1, Math.round((endTime.getTime() - startTime.getTime()) / 60000));

Re-applied on top of #182's mobile fullscreen rewrite (no conflict).

Gates

  • typecheck 0 errors
  • lint 0 errors
  • Vitest 1135/1135
  • prettier clean

Supersedes #183.

🤖 Generated with Claude Code


Summary by cubic

Adds a visible hint when the finish button is disabled and clamps workout duration to at least 1 minute to prevent save errors and confusing toasts. Improves the aluno workout flow and announces the hint to screen readers when it reappears.

  • Bug Fixes
    • CardTreino: Show a hint under "Finalizar e Avaliar Treino" when no exercises are checked; add aria-live="polite" so the hint is announced when it reappears.
    • WorkoutSession: Clamp duracaoMinutos to a minimum of 1 to satisfy the Zod schema and prevent the "inesperado ao salvar no histórico" toast on sub-minute sessions.

Written for commit 265de6c. Summary will update on new commits.

Review in cubic

EmiyaKiritsugu3 and others added 2 commits July 6, 2026 12:55
CardTreino footer ganha <p> condicional data-testid finish-hint
quando completedCount === 0 e sem feedback loading. Sinaliza
pre-condicao (marque exercicios) para o botao Finalizar e Avaliar
Treino que parecia morto quando disabled.

Test: stateful mock useWorkoutTracker para toggle. 15/15 card-treino,
1134/1134 suite.

Co-Authored-By: Claude <noreply@anthropic.com>
HistoricoTreinoBaseSchema requires duracaoMinutos >= 1. Quick workouts
(<30s) rounded to 0, failing save and surfacing "ocorreu um erro
inesperado ao salvar no histórico" toast.

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
smartmanagementsystem Ready Ready Preview, Comment Jul 6, 2026 4:12pm

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@EmiyaKiritsugu3, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 21 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1593c45e-9b98-4f11-b9bb-f3ce60ccfb46

📥 Commits

Reviewing files that changed from the base of the PR and between 005f66e and 265de6c.

📒 Files selected for processing (4)
  • src/components/WorkoutSession.test.tsx
  • src/components/WorkoutSession.tsx
  • src/components/dashboard/aluno/card-treino.test.tsx
  • src/components/dashboard/aluno/card-treino.tsx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/card-treino-empty-hint-v2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ecc-tools

ecc-tools Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/components/WorkoutSession.tsx">

<violation number="1" location="src/components/WorkoutSession.tsx:173">
P2: Custom agent: **Enforce Pragmatic Test Coverage**

This business-logic fix clamps workout duration to at least 1 minute to prevent a Zod schema failure on very short sessions, but the edge case isn't covered by tests. If the clamp is accidentally removed or altered, the failure path (duration of 0 causing a validation toast) would regress silently. Consider adding a test that mocks time so the workout ends in under a minute, then asserts that `onFinish` is called with `duracaoMinutos >= 1`.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/components/dashboard/aluno/card-treino.tsx Outdated
setIsFinishing(true);
const endTime = new Date();
const duracaoMinutos = Math.round((endTime.getTime() - startTime.getTime()) / 60000);
const duracaoMinutos = Math.max(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Custom agent: Enforce Pragmatic Test Coverage

This business-logic fix clamps workout duration to at least 1 minute to prevent a Zod schema failure on very short sessions, but the edge case isn't covered by tests. If the clamp is accidentally removed or altered, the failure path (duration of 0 causing a validation toast) would regress silently. Consider adding a test that mocks time so the workout ends in under a minute, then asserts that onFinish is called with duracaoMinutos >= 1.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/components/WorkoutSession.tsx, line 173:

<comment>This business-logic fix clamps workout duration to at least 1 minute to prevent a Zod schema failure on very short sessions, but the edge case isn't covered by tests. If the clamp is accidentally removed or altered, the failure path (duration of 0 causing a validation toast) would regress silently. Consider adding a test that mocks time so the workout ends in under a minute, then asserts that `onFinish` is called with `duracaoMinutos >= 1`.</comment>

<file context>
@@ -170,7 +170,10 @@ export function WorkoutSession({ treino, onFinish, onCancel }: Readonly<WorkoutS
     setIsFinishing(true);
     const endTime = new Date();
-    const duracaoMinutos = Math.round((endTime.getTime() - startTime.getTime()) / 60000);
+    const duracaoMinutos = Math.max(
+      1,
+      Math.round((endTime.getTime() - startTime.getTime()) / 60000)
</file context>

Comment thread src/components/dashboard/aluno/card-treino.test.tsx Outdated
- card-treino.tsx: finish-hint gains aria-live="polite" so AT announces
  reappearance when user unchecks last completed exercise.
- WorkoutSession.test.tsx: new test asserting onFinish receives
  duracaoMinutos >= 1 even on sub-minute session (regression guard for
  the Math.max(1, ...) clamp).
- card-treino.test.tsx: simplify "hides finish hint" test per cubic —
  set mockReturnValue directly to { 'ex-1': true } + rerender; drop
  mutable let, callback re-mock, fireEvent.click, silent no-op path.

Co-Authored-By: Claude <noreply@anthropic.com>
@ecc-tools

ecc-tools Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 2026

Copy link
Copy Markdown

@EmiyaKiritsugu3 EmiyaKiritsugu3 merged commit 3301f43 into main Jul 6, 2026
14 checks passed
@EmiyaKiritsugu3 EmiyaKiritsugu3 deleted the fix/card-treino-empty-hint-v2 branch July 6, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant