From 9b781a6a7b1eec887a5c9cb936150f90f9f3a736 Mon Sep 17 00:00:00 2001 From: Emiya Kiritsugu Date: Sat, 4 Jul 2026 10:49:00 -0300 Subject: [PATCH] fix(test): resolve 14 SonarQube S5906 smells + 2 S5914 (toHaveLength + toBeUndefined) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit S5906: replace .length.toBe(N) with toHaveLength(N) across 9 test files (financeiro-client, WorkoutSession, dashboard-nav, card-feedback, workout-editor, columns, circular-progress, exercise-options, nan-guards). Replace .toBeGreaterThan(0) with .toBeGreaterThanOrEqual(1) for clarity. S5914: replace .toBe(undefined) with .toBeUndefined() in nan-guards.test.ts. Line 29 (.toBe('')) is correct — not a smell. Closes #160. --- .../financeiro/financeiro-client.test.tsx | 4 ++-- .../treinos/__tests__/nan-guards.test.ts | 2 +- src/components/WorkoutSession.test.tsx | 4 ++-- src/components/dashboard-nav.test.tsx | 2 +- .../dashboard/aluno/card-feedback.test.tsx | 2 +- .../dashboard/aluno/workout-editor.test.tsx | 2 +- src/components/dashboard/alunos/columns.test.tsx | 2 +- src/components/ui/circular-progress.test.tsx | 2 +- src/lib/exercise-options.test.ts | 16 ++++++++-------- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/app/dashboard/financeiro/financeiro-client.test.tsx b/src/app/dashboard/financeiro/financeiro-client.test.tsx index edb0d563..3b986b00 100644 --- a/src/app/dashboard/financeiro/financeiro-client.test.tsx +++ b/src/app/dashboard/financeiro/financeiro-client.test.tsx @@ -129,13 +129,13 @@ describe('FinanceiroClient', () => { it('renders "Inadimplente" badge for each student', () => { render(); const badges = screen.getAllByText('Inadimplente'); - expect(badges.length).toBe(2); + expect(badges).toHaveLength(2); }); it('renders "Registrar Pagamento" buttons', () => { render(); const buttons = screen.getAllByText('Registrar Pagamento'); - expect(buttons.length).toBe(2); + expect(buttons).toHaveLength(2); }); it('shows empty state when no inadimplentes', () => { diff --git a/src/app/dashboard/treinos/__tests__/nan-guards.test.ts b/src/app/dashboard/treinos/__tests__/nan-guards.test.ts index 63bc8076..a313a3ee 100644 --- a/src/app/dashboard/treinos/__tests__/nan-guards.test.ts +++ b/src/app/dashboard/treinos/__tests__/nan-guards.test.ts @@ -25,7 +25,7 @@ describe('NaN guard patterns', () => { it('empty string becomes undefined with ||, not empty string', () => { const empty = ''; - expect(empty || undefined).toBe(undefined); + expect(empty || undefined).toBeUndefined(); expect(empty ?? undefined).toBe(''); // '' passes through ?? }); diff --git a/src/components/WorkoutSession.test.tsx b/src/components/WorkoutSession.test.tsx index 868fc5a8..2c20ddf3 100644 --- a/src/components/WorkoutSession.test.tsx +++ b/src/components/WorkoutSession.test.tsx @@ -129,8 +129,8 @@ describe('WorkoutSession', () => { render(); const pesoInputs = screen.getAllByPlaceholderText('Peso (kg)'); const repsInputs = screen.getAllByPlaceholderText('Reps'); - expect(pesoInputs.length).toBe(3); - expect(repsInputs.length).toBe(3); + expect(pesoInputs).toHaveLength(3); + expect(repsInputs).toHaveLength(3); }); it('disables "Anterior" button on first exercise', () => { diff --git a/src/components/dashboard-nav.test.tsx b/src/components/dashboard-nav.test.tsx index 7584b20b..b9eac339 100644 --- a/src/components/dashboard-nav.test.tsx +++ b/src/components/dashboard-nav.test.tsx @@ -125,7 +125,7 @@ describe('DashboardNav', () => { const activeButtons = menuButtons.filter( (btn) => btn.getAttribute('data-is-active') === 'true' ); - expect(activeButtons.length).toBe(1); + expect(activeButtons).toHaveLength(1); }); it('links have correct href attributes', () => { diff --git a/src/components/dashboard/aluno/card-feedback.test.tsx b/src/components/dashboard/aluno/card-feedback.test.tsx index a609a1cd..e4af5f0a 100644 --- a/src/components/dashboard/aluno/card-feedback.test.tsx +++ b/src/components/dashboard/aluno/card-feedback.test.tsx @@ -34,7 +34,7 @@ describe('CardFeedback', () => { render(); expect(screen.getByText(/Pulsando Bio-Dados/i)).toBeTruthy(); const skeletons = screen.getAllByTestId('skeleton'); - expect(skeletons.length).toBe(3); + expect(skeletons).toHaveLength(3); }); it('renders feedback title and message when provided', () => { diff --git a/src/components/dashboard/aluno/workout-editor.test.tsx b/src/components/dashboard/aluno/workout-editor.test.tsx index b1f9e9c5..13cea808 100644 --- a/src/components/dashboard/aluno/workout-editor.test.tsx +++ b/src/components/dashboard/aluno/workout-editor.test.tsx @@ -208,6 +208,6 @@ describe('WorkoutEditor', () => { mockUseWorkoutExercises.mockReturnValue({ ...defaultHookReturn, exercicios: exercises }); render(); - expect(screen.getAllByTestId('exercise-row').length).toBe(2); + expect(screen.getAllByTestId('exercise-row')).toHaveLength(2); }); }); diff --git a/src/components/dashboard/alunos/columns.test.tsx b/src/components/dashboard/alunos/columns.test.tsx index c18a2743..48a67ec8 100644 --- a/src/components/dashboard/alunos/columns.test.tsx +++ b/src/components/dashboard/alunos/columns.test.tsx @@ -103,7 +103,7 @@ describe('columns', () => { it('returns an array of column definitions', () => { expect(Array.isArray(columnDefs)).toBe(true); - expect(columnDefs.length).toBe(6); + expect(columnDefs).toHaveLength(6); }); it('has photo column with accessorKey fotoUrl', () => { diff --git a/src/components/ui/circular-progress.test.tsx b/src/components/ui/circular-progress.test.tsx index 8368908d..cc11ec36 100644 --- a/src/components/ui/circular-progress.test.tsx +++ b/src/components/ui/circular-progress.test.tsx @@ -12,7 +12,7 @@ describe('CircularProgress', () => { it('renders SVG circles', () => { const { container } = render(); const circles = container.querySelectorAll('circle'); - expect(circles.length).toBe(2); + expect(circles).toHaveLength(2); }); it('displays value when showValue is true', () => { diff --git a/src/lib/exercise-options.test.ts b/src/lib/exercise-options.test.ts index 66ee2a1e..42e1e3d1 100644 --- a/src/lib/exercise-options.test.ts +++ b/src/lib/exercise-options.test.ts @@ -10,11 +10,11 @@ import { EXERCICIOS_POR_GRUPO } from './constants'; describe('exerciciosOptions', () => { it('is a non-empty array', () => { expect(Array.isArray(exerciciosOptions)).toBe(true); - expect(exerciciosOptions.length).toBeGreaterThan(0); + expect(exerciciosOptions.length).toBeGreaterThanOrEqual(1); }); it('has the same number of groups as EXERCICIOS_POR_GRUPO', () => { - expect(exerciciosOptions.length).toBe(EXERCICIOS_POR_GRUPO.length); + expect(exerciciosOptions).toHaveLength(EXERCICIOS_POR_GRUPO.length); }); it('each entry has a label matching the group name and a non-empty options array', () => { @@ -30,11 +30,11 @@ describe('exerciciosOptions', () => { for (const group of exerciciosOptions) { for (const opt of group.options) { expect(typeof opt.value).toBe('string'); - expect(opt.value.length).toBeGreaterThan(0); + expect(opt.value.length).toBeGreaterThanOrEqual(1); expect(typeof opt.label).toBe('string'); - expect(opt.label.length).toBeGreaterThan(0); + expect(opt.label.length).toBeGreaterThanOrEqual(1); expect(Array.isArray(opt.keywords)).toBe(true); - expect(opt.keywords.length).toBeGreaterThan(0); + expect(opt.keywords.length).toBeGreaterThanOrEqual(1); } } }); @@ -43,12 +43,12 @@ describe('exerciciosOptions', () => { describe('flatExerciciosOptions', () => { it('is a non-empty array', () => { expect(Array.isArray(flatExerciciosOptions)).toBe(true); - expect(flatExerciciosOptions.length).toBeGreaterThan(0); + expect(flatExerciciosOptions.length).toBeGreaterThanOrEqual(1); }); it('contains the total count of all exercises across groups', () => { const totalExercises = EXERCICIOS_POR_GRUPO.reduce((sum, g) => sum + g.exercicios.length, 0); - expect(flatExerciciosOptions.length).toBe(totalExercises); + expect(flatExerciciosOptions).toHaveLength(totalExercises); }); it('each entry has value, label, and description', () => { @@ -105,7 +105,7 @@ describe('DEFAULT_EXERCISE', () => { it('has repeticoes as a non-empty string', () => { expect(typeof DEFAULT_EXERCISE.repeticoes).toBe('string'); - expect(DEFAULT_EXERCISE.repeticoes.length).toBeGreaterThan(0); + expect(DEFAULT_EXERCISE.repeticoes.length).toBeGreaterThanOrEqual(1); }); });