Skip to content

test: raise global line coverage from 57% to 86% - #213

Merged
ktursunov merged 2 commits into
mainfrom
test/raise-global-coverage
Jul 22, 2026
Merged

test: raise global line coverage from 57% to 86%#213
ktursunov merged 2 commits into
mainfrom
test/raise-global-coverage

Conversation

@mitasovr

@mitasovr mitasovr commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

What

Adds ~330 unit tests (34 new test files, 8 extended) across the layers that had little or no coverage, and tunes the coverage config. No production code changes.

Metric Before After
Lines 57.0% 86.3%
Statements 55.6% 84.3%
Branches 47.6% 73.8%
Functions 52.2% 80.4%

Coverage added

  • Pure libs / API helpers: transforms, format, period-to-date-range, analytics-client, status, peers, scoring, derivations, metric-order, get-initials
  • React-query layer: team-view, ic-dashboard, sales-dashboard, v2/ic-extras, v2/team-extras
  • Widgets & hooks: use-period, feature-flags, period-selector-bar, counters-block, bullet-chart, metric-card, person-header, kpi-strip, collapsible-section, dashboard-empty-state, coming-soon, deal-flow-chart, sales-pacing-band
  • Screens & shell: sales-dashboard, ic-dashboard router, team-view-v2 gaps, app-sidebar, sidebar-v2-settings, metric-timeseries-view/-table, theme-provider, theme-switcher, error-fallback, catalog-provider, mock-banner, ic-view-toggle

Config change

vitest.config.ts coverage excludes now also skip:

  • src/components/ui/** — vendored shadcn/ui primitives
  • src/routes/** — thin TanStack Router wrappers around screens

Neither is project logic; excluding them keeps the global number (and the diff-coverage gate) focused on code we actually own. Worth a second opinion in review — trivially revertable.

Deliberately not covered

The legacy v1 dashboards (engineering-dashboard.tsx, team-view.tsx and their v1-only widgets/queries, ~320 lines) are left as is — they are slated for removal once the metrics-v2 rollout completes, so investing tests there would be wasted. A handful of files are unreachable from the live import graph (section-trend, treemap-composition, settled-result, menu-item-id) and are candidates for deletion in a follow-up.

Verification

  • pnpm vitest run --coverage (both projects, as CI runs it): 95 files / 657 tests pass
  • pnpm typecheck clean, pnpm lint clean (--max-warnings 0)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added comprehensive automated coverage for analytics requests, date ranges, formatting, scoring, feature flags, dashboard queries, navigation, themes, widgets, and dashboard states.
    • Added validation for filtering, grouping, exports, drilldowns, loading/error handling, empty states, and persisted preferences.
    • Improved coverage configuration to focus reporting on application-specific behavior.

Add ~330 unit tests across the layers that had little or no coverage:

- pure libs and API helpers: transforms, format, period-to-date-range,
  analytics-client, status, peers, scoring, derivations, metric-order
- the react-query layer: team-view, ic-dashboard, sales-dashboard,
  v2/ic-extras, v2/team-extras
- widgets and hooks: use-period, feature-flags, period-selector-bar,
  counters-block, bullet-chart, metric-card, person-header, kpi-strip,
  collapsible-section, dashboard-empty-state
- screens and shell: sales-dashboard, ic-dashboard router, team-view-v2
  gaps, app-sidebar, sidebar-v2-settings, metric-timeseries-view/table,
  theme-provider, theme-switcher, error-fallback, catalog-provider,
  mock-banner, ic-view-toggle

Also exclude vendored shadcn/ui primitives (src/components/ui/**) and
thin TanStack Router wrappers (src/routes/**) from coverage: neither is
project logic, and testing them adds noise rather than signal.

No production code changes. Remaining uncovered lines are almost
entirely the legacy v1 dashboards (kept as is on purpose) and a handful
of defensive branches.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Roman Mitasov <roman.mitasov@constructor.tech>
@mitasovr
mitasovr requested a review from a team as a code owner July 22, 2026 14:42
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

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

Next review available in: 43 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6ea4171f-16ce-47c6-af15-f6b09ff05c9c

📥 Commits

Reviewing files that changed from the base of the PR and between b0b7017 and 87ca886.

📒 Files selected for processing (2)
  • src/components/widgets/metric-views/metric-timeseries-presentations.test.tsx
  • src/queries/team-view.test.ts
📝 Walkthrough

Walkthrough

The PR adds broad Vitest coverage for API clients, date and formatting utilities, state stores, data transformations, React Query hooks, dashboard widgets, screen flows, feature flags, and tenant-aware catalog behavior. Coverage exclusions are expanded for UI primitives and router wrappers.

Changes

Application test coverage

Layer / File(s) Summary
API contracts and transformations
src/api/analytics-client.test.ts, src/api/catalog-provider.test.tsx, src/api/period-to-date-range.test.ts, src/api/transforms.test.ts
Validates request construction, date filters, error payloads, tenant cache behavior, date-range utilities, and dashboard data transformations.
Core components and settings
src/components/app-sidebar.test.tsx, src/components/error-fallback.test.tsx, src/components/ic-view-toggle.test.tsx, src/components/mock-banner.test.tsx, src/components/sidebar-v2-settings.test.tsx, src/components/theme-*.test.tsx
Covers routing, identity fallbacks, error actions, feature-flag controls, mock visibility, theme selection, persistence, and system-theme updates.
Dashboard widgets
src/components/widgets/**/*test.tsx
Covers chart and tile rendering, empty/loading/error states, retry actions, filters, exports, period selection, persistence, revalidation, and accessibility interactions.
State and domain utilities
src/hooks/use-period.test.ts, src/lib/**/*.test.ts
Validates persisted period and view state, feature flags, formatting, initials, derivations, metric ordering, peer statistics, scoring, and status rules.
Dashboard query hooks
src/queries/**/*.test.ts
Tests IC, sales, team, histogram, trend, drilldown, member bullet, and department distribution query behavior, including disabled, error, transformation, and batching paths.
Dashboard screen flows
src/screens/**/*.test.tsx, vitest.config.ts
Validates dashboard routing, sales and team loading/error/retry states, metric-group drilldowns, revalidation, empty rosters, and expanded coverage exclusions.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: cyberantonz, ktursunov

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.65% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the PR’s main change: a large test-only update that raises global coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/raise-global-coverage

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.

@mitasovr
mitasovr requested a review from ktursunov July 22, 2026 14:43

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/queries/ic-dashboard.test.ts (1)

110-116: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Extract the shared react-query test harness to reduce duplication. All five query suites copy an identical wrapper() (QueryClient with retry:false, gcTime:0) plus near-identical odata/ok/err/PAGE builders. Hoisting these into a single test util (e.g. src/test/react-query.ts) keeps the harness consistent as it evolves. Optional and deferrable.

  • src/queries/ic-dashboard.test.ts#L110-L116: move wrapper() (and odata/PAGE) into the shared util and import it here.
  • src/queries/sales-dashboard.test.ts#L78-L84: replace the local wrapper()/odata with the shared import.
  • src/queries/team-view.test.ts#L83-L89: replace the local wrapper()/ok/err/odata with the shared import.
  • src/queries/v2/ic-extras.test.ts#L42-L48: replace the local wrapper()/ok/odata with the shared import.
  • src/queries/v2/team-extras.test.ts#L72-L78: replace the local wrapper()/ok/err with the shared import.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/queries/ic-dashboard.test.ts` around lines 110 - 116, Create a shared
React Query test utility containing wrapper() and the reusable odata, ok, err,
and PAGE builders, preserving their existing behavior. Update
src/queries/ic-dashboard.test.ts:110-116,
src/queries/sales-dashboard.test.ts:78-84, src/queries/team-view.test.ts:83-89,
src/queries/v2/ic-extras.test.ts:42-48, and
src/queries/v2/team-extras.test.ts:72-78 to import the shared symbols and remove
their duplicated local definitions.
src/components/widgets/period-selector-bar.test.tsx (1)

51-51: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Trim the 30s timeout or document why it’s needed
These four calendar-popover tests all use a 30s timeout; if that headroom is genuinely needed in CI, add a short note, otherwise reduce it so slowdowns surface sooner.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/widgets/period-selector-bar.test.tsx` at line 51, Update the
four calendar-popover tests in period-selector-bar.test.tsx to use a shorter
timeout appropriate for their execution, or add a concise comment documenting
why the existing 30-second timeout is required in CI.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/ic-view-toggle.test.tsx`:
- Around line 9-20: Import the React type namespace, or equivalent
ReactNode/ReactElement types, in the test mocks using React type annotations.
Update src/components/ic-view-toggle.test.tsx lines 9-20 and
src/components/theme-switcher.test.tsx lines 9-40; no other behavior changes are
needed.

---

Nitpick comments:
In `@src/components/widgets/period-selector-bar.test.tsx`:
- Line 51: Update the four calendar-popover tests in
period-selector-bar.test.tsx to use a shorter timeout appropriate for their
execution, or add a concise comment documenting why the existing 30-second
timeout is required in CI.

In `@src/queries/ic-dashboard.test.ts`:
- Around line 110-116: Create a shared React Query test utility containing
wrapper() and the reusable odata, ok, err, and PAGE builders, preserving their
existing behavior. Update src/queries/ic-dashboard.test.ts:110-116,
src/queries/sales-dashboard.test.ts:78-84, src/queries/team-view.test.ts:83-89,
src/queries/v2/ic-extras.test.ts:42-48, and
src/queries/v2/team-extras.test.ts:72-78 to import the shared symbols and remove
their duplicated local definitions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6478e031-9461-408f-a2bb-20b26884f6ea

📥 Commits

Reviewing files that changed from the base of the PR and between 3a97efb and b0b7017.

📒 Files selected for processing (42)
  • src/api/analytics-client.test.ts
  • src/api/catalog-provider.test.tsx
  • src/api/period-to-date-range.test.ts
  • src/api/transforms.test.ts
  • src/components/app-sidebar.test.tsx
  • src/components/error-fallback.test.tsx
  • src/components/ic-view-toggle.test.tsx
  • src/components/mock-banner.test.tsx
  • src/components/sidebar-v2-settings.test.tsx
  • src/components/theme-provider.test.tsx
  • src/components/theme-switcher.test.tsx
  • src/components/widgets/bullet-chart.test.tsx
  • src/components/widgets/collapsible-section.test.tsx
  • src/components/widgets/coming-soon.test.tsx
  • src/components/widgets/deal-flow-chart.test.tsx
  • src/components/widgets/kpi-strip.test.tsx
  • src/components/widgets/metric-card.test.tsx
  • src/components/widgets/metric-views/metric-timeseries-presentations.test.tsx
  • src/components/widgets/metric-views/metric-timeseries-view.test.tsx
  • src/components/widgets/period-selector-bar.test.tsx
  • src/components/widgets/person-header.test.tsx
  • src/components/widgets/sales-pacing-band.test.tsx
  • src/components/widgets/v2/counters-block.test.tsx
  • src/components/widgets/v2/dashboard-empty-state.test.tsx
  • src/hooks/use-period.test.ts
  • src/lib/feature-flags.test.ts
  • src/lib/format.test.ts
  • src/lib/insight/get-initials.test.ts
  • src/lib/insight/v2/derivations.test.ts
  • src/lib/insight/v2/metric-order.test.ts
  • src/lib/peers.test.ts
  • src/lib/scoring.test.ts
  • src/lib/status.test.ts
  • src/queries/ic-dashboard.test.ts
  • src/queries/sales-dashboard.test.ts
  • src/queries/team-view.test.ts
  • src/queries/v2/ic-extras.test.ts
  • src/queries/v2/team-extras.test.ts
  • src/screens/ic-dashboard/index.test.tsx
  • src/screens/ic-dashboard/sales-dashboard.test.tsx
  • src/screens/team-view-v2.test.tsx
  • vitest.config.ts

Comment on lines +9 to +20
Link: ({
to,
children,
...rest
}: {
to?: string;
children?: React.ReactNode;
} & Record<string, unknown>) => (
<a data-to={to} {...(rest as object)}>
{children}
</a>
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm whether a global/UMD React type is available without an explicit import.
fd -e json tsconfig | xargs -I{} sh -c 'echo "== {} =="; cat {}' 2>/dev/null
rg -n "allowUmdGlobalAccess" -g "tsconfig*.json"
rg -n "declare global" -t ts

Repository: constructorfabric/insight-front

Length of output: 1894


🏁 Script executed:

#!/bin/bash
set -euo pipefail

for f in src/components/ic-view-toggle.test.tsx src/components/theme-switcher.test.tsx; do
  echo "== $f =="
  cat -n "$f"
  echo
done

echo "== React type references =="
rg -n "\bReact\.(ReactNode|ReactElement)\b|\bimport type React\b|\bimport .*React" src/components/*.test.tsx src/**/*.d.ts src/**/*.ts 2>/dev/null || true

echo "== tsconfig / vitest config files =="
fd -e json -e ts -e mts -e cts 'vitest|vite|tsconfig' . | sed 's#^\./##'

Repository: constructorfabric/insight-front

Length of output: 7865


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== ambient declarations mentioning React =="
rg -n --glob '!node_modules' --glob '!dist' --glob '!build' 'declare\s+global|export\s+as\s+namespace\s+React|namespace\s+React\b|import\s+type\s+React\b' src . 2>/dev/null || true

echo "== package / tsconfig references to react typings =="
rg -n '"types"\s*:\s*\[[^]]*react|`@types/react`|allowUmdGlobalAccess|jsxImportSource' package.json tsconfig*.json src 2>/dev/null || true

Repository: constructorfabric/insight-front

Length of output: 933


Import the React type namespace in these test mocks.

React.ReactNode / React.ReactElement is used here, but neither test file imports React. Add import type React from "react"; (or switch to direct type { ReactNode, ReactElement } imports) in:

  • src/components/ic-view-toggle.test.tsx
  • src/components/theme-switcher.test.tsx
📍 Affects 2 files
  • src/components/ic-view-toggle.test.tsx#L9-L20 (this comment)
  • src/components/theme-switcher.test.tsx#L9-L40
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/ic-view-toggle.test.tsx` around lines 9 - 20, Import the React
type namespace, or equivalent ReactNode/ReactElement types, in the test mocks
using React type annotations. Update src/components/ic-view-toggle.test.tsx
lines 9-20 and src/components/theme-switcher.test.tsx lines 9-40; no other
behavior changes are needed.

…overage

Signed-off-by: Roman Mitasov <roman.mitasov@constructor.tech>

# Conflicts:
#	src/screens/team-view-v2.test.tsx
@ktursunov
ktursunov merged commit c3e7018 into main Jul 22, 2026
6 checks passed
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.

2 participants