Skip to content

refactor(onboarding): implement dynamic step count calculation#52

Merged
DavidsonGomes merged 3 commits into
evolution-foundation:developfrom
lpcoutinho:refactor/onboarding-dynamic-step-count
May 18, 2026
Merged

refactor(onboarding): implement dynamic step count calculation#52
DavidsonGomes merged 3 commits into
evolution-foundation:developfrom
lpcoutinho:refactor/onboarding-dynamic-step-count

Conversation

@lpcoutinho

@lpcoutinho lpcoutinho commented May 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Refactored the onboarding page to calculate the total number of steps dynamically instead of using hardcoded values. This makes the progress tracking more maintainable and automatically adapts when steps are added or removed.

Changes

  • OnboardingPage.tsx:

    • Replaced hardcoded 7 in progress calculation with dynamic totalSteps
    • Fixed incorrect display showing 6 instead of 7 in progress text
    • Centralized step fields in onboardingSteps array
    • Calculate totalSteps from array length
  • OnboardingPage.spec.tsx (new):

    • Added comprehensive tests for dynamic step count
    • Verify total steps is calculated dynamically (not hardcoded)
    • Test progress updates when fields are filled
    • Test "Other" channel requires additional input
    • Test progress percentage calculation

Motivation

Previously, the progress count had two hardcoded values:

  • Calculation used 7 (correct number of fields)
  • Display showed 6 (incorrect)

This inconsistency and hardcoding made it error-prone when modifying the onboarding steps.

Testing

All 5 new tests pass:

  • ✅ Dynamic total steps calculation (7 steps)
  • ✅ Progress updates correctly
  • ✅ "Other" channel validation
  • ✅ Progress percentage accuracy
  • ✅ Redirect behavior

Checklist

  • Code follows project standards
  • Tests added/updated
  • All tests pass
  • Commits follow Conventional Commits

Summary by Sourcery

Tests:

  • Add unit tests for onboarding progress to verify dynamic step counting, progress updates, special handling of the "Other" channel, percentage calculation, and redirect behavior when no token is present.

lpcoutinho added 2 commits May 9, 2026 09:30
- Replace hardcoded value '7' in progress calculation with dynamic 'totalSteps'
- Fix incorrect display showing '6' instead of '7' in progress text
- Centralize step fields in 'onboardingSteps' array for maintainability
- Calculate totalSteps from array length to automatically reflect changes

This allows the onboarding progress to automatically adapt when
the number of steps changes.
- Verify total steps is calculated dynamically (not hardcoded)
- Test progress updates correctly when fields are filled
- Test 'Other' channel requires additional input to count as filled
- Test progress percentage calculation is accurate
- Document redirect behavior for unauthenticated users

These tests ensure the refactor works correctly and prevent regressions.
@sourcery-ai

sourcery-ai Bot commented May 9, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors onboarding progress tracking to derive both the filled step count and total step count from a centralized steps array, and adds a new test suite that asserts dynamic step calculation, progress behavior, and edge cases like the "Other" channel and redirect logic.

Sequence diagram for dynamic onboarding progress update

sequenceDiagram
  actor User
  participant OnboardingPage
  participant onboardingSteps
  participant ProgressBar

  User->>OnboardingPage: Change form field value
  OnboardingPage->>OnboardingPage: Update form state
  OnboardingPage->>OnboardingPage: Recompute isChannelValid
  OnboardingPage->>onboardingSteps: Build array from form fields
  OnboardingPage->>OnboardingPage: filledCount = filter(onboardingSteps).length
  OnboardingPage->>OnboardingPage: totalSteps = onboardingSteps.length
  OnboardingPage->>OnboardingPage: progressPct = round(filledCount / totalSteps * 100)
  OnboardingPage->>ProgressBar: Render with progressPct and text filledCount of totalSteps
  ProgressBar-->>User: Display updated progress (e.g., 3 de 7)
Loading

Class diagram for dynamic onboarding progress calculation

classDiagram
  class OnboardingPage {
    +form_teamSize: string
    +form_dailyVolume: string
    +form_mainChannel: string
    +form_mainChannelOther: string
    +form_biggestPain: string
    +form_crmExperience: string
    +form_mainGoal: string
    +isChannelValid: boolean
    +onboardingSteps: readonly any[]
    +filledCount: number
    +totalSteps: number
    +progressPct: number
    +handleSubmit(): Promise~void~
  }

  class useLanguageHook {
    +t(key: string): string
  }

  class useAuthHook {
    +isAuthenticated: boolean
    +refreshUser(): Promise~void~
  }

  class setupService {
    +saveSurvey(data: any): Promise~any~
  }

  class surveyService {
    +saveSurvey(data: any): Promise~any~
  }

  class AppLogo {
  }

  OnboardingPage --> useLanguageHook : uses
  OnboardingPage --> useAuthHook : uses
  OnboardingPage --> setupService : calls
  OnboardingPage --> surveyService : calls
  OnboardingPage --> AppLogo : renders

  %% Internal relationships
  OnboardingPage "1" o-- "*" onboardingSteps : derives
  OnboardingPage ..> filledCount : calculates
  OnboardingPage ..> totalSteps : length of onboardingSteps
  OnboardingPage ..> progressPct : from filledCount and totalSteps
  OnboardingPage ..> isChannelValid : derived from mainChannel and mainChannelOther
Loading

File-Level Changes

Change Details Files
Refactor onboarding progress computation to derive counts from a centralized steps array.
  • Introduce an onboardingSteps array that contains all fields contributing to onboarding progress, including the conditional channel validity token.
  • Derive filledCount by filtering truthy values from onboardingSteps instead of inline array construction.
  • Compute totalSteps from onboardingSteps.length and use it as the denominator for progressPct.
  • Update progress text to display filledCount and totalSteps rather than a hardcoded total value.
src/pages/Setup/OnboardingPage.tsx
Add a focused test suite validating dynamic onboarding progress behavior and related flows.
  • Mock translation, auth context, services, logo component, and sessionStorage to isolate OnboardingPage behavior in tests.
  • Add tests that verify the total step count is rendered dynamically and not hardcoded.
  • Add tests that assert progress increments as form fields are filled and that the "Other" channel only counts as completed when its companion input is filled.
  • Add a test that ensures progress percentage reaches 100% when all steps are completed and that the progress bar width reflects this.
  • Add a test that asserts redirect logic triggers when there is no survey token and the user is unauthenticated.
src/pages/Setup/OnboardingPage.spec.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-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.

Hey - I've left some high level feedback:

  • The new tests are tightly coupled to the exact Portuguese copy and string format (e.g. /0 de 7$/i, /de 7$/i), which can become brittle if translations or wording change; consider exposing a progress-specific hook/utility or a data attribute so tests can assert the numeric logic without depending on localized text.
  • In the progress percentage test you assert 100% completion by matching an inline style string (div[style*="width: 100%"]), which is sensitive to implementation details; prefer asserting against a role/ARIA attribute, a data-testid, or a numeric prop/value that represents the progress percentage.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new tests are tightly coupled to the exact Portuguese copy and string format (e.g. `/0 de 7$/i`, `/de 7$/i`), which can become brittle if translations or wording change; consider exposing a progress-specific hook/utility or a data attribute so tests can assert the numeric logic without depending on localized text.
- In the progress percentage test you assert 100% completion by matching an inline `style` string (`div[style*="width: 100%"]`), which is sensitive to implementation details; prefer asserting against a role/ARIA attribute, a data-testid, or a numeric prop/value that represents the progress percentage.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

…testability

- Add role="progressbar" with aria-valuenow, aria-valuemin, aria-valuemax
- Add data-testid="progress-bar-fill" for progress bar
- Add data-testid="progress-text" with data-filled and data-total attributes
- Update tests to use data-testid and ARIA instead of text matching
- Remove dependency on translated text in tests
- Remove dependency on inline style strings in tests

This makes tests more robust and less coupled to implementation details.
@lpcoutinho

Copy link
Copy Markdown
Contributor Author

Atualizações recentes

Melhorei os testes seguindo o feedback do code review:

  • Adicionado atributos ARIA (role="progressbar", aria-valuenow, aria-valuemin, aria-valuemax)
  • Adicionado data-testid e data-* attributes para acesso direto aos valores numéricos
  • Testes agora verificam a lógica via atributos, não via texto traduzido ou estilos inline

Isso torna os testes mais robustos e menos frágeis a mudanças na interface.

@DavidsonGomes DavidsonGomes merged commit 0a85ec5 into evolution-foundation:develop May 18, 2026
1 check 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