Skip to content

Conversation

@SandPod
Copy link
Contributor

@SandPod SandPod commented Feb 14, 2025

Add tests to validate wrap around in select list works as expected.

Bonus

  • Format the project with Dart 3.7.0

Summary by CodeRabbit

Summary by CodeRabbit

  • Tests
    • Added automated tests to validate prompt navigation behavior, ensuring that when users move past the last option, the selection wraps back to the first option for both multi-select and single-select interactions.
    • Reformatted existing test cases for improved readability without altering their functionality.
    • Updated expected outputs in tests for the CommandDocumentationGenerator to ensure correct markdown formatting.
    • Enhanced formatting of various test cases across multiple files for better clarity and maintainability.

@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2025

📝 Walkthrough

Walkthrough

New test cases have been added for both the multiselect and select prompts. The tests simulate user navigation inputs—pressing down arrow keys to traverse options and wrapping around from the last to the first option. One test checks that the multiselect prompt correctly selects the first option after wrapping, while the other verifies similar behavior for the single select prompt. Existing tests remain unchanged, with these additions enhancing coverage for prompt wrap-around behavior.

Changes

File(s) Change Summary
test/prompts/multiple_select_test.dart, test/prompts/select_test.dart Added new tests that simulate key navigation beyond the last option to check that both multiselect and select prompts correctly wrap around to the first option.
example/main.dart Reformatted a lambda function in logger.progress to a single line for improved readability.
lib/src/analytics/analytics.dart Reformatted the track method's parameter list to a single line and adjusted the _quietPost method's formatting for better readability.
lib/src/better_command_runner/better_command.dart Reformatted the constructor parameters to a single line for clarity.
lib/src/better_command_runner/better_command_runner.dart Reformatted type definitions and constructor parameters to single lines for improved readability.
lib/src/logger/helpers/progress.dart Added trailing commas in the ProgressAnimation and Progress classes for style consistency.
lib/src/logger/logger.dart Simplified method signatures for debug, info, and warning methods to single lines, and reformatted the TextLogStyle enum and BoxLogType constructor.
lib/src/logger/loggers/std_out_logger.dart Reformatted _log and write method calls to remove line breaks for clarity.
lib/src/package_version/package_version.dart Adjusted parameter formatting in fetchLatestPackageVersion and _storePubDevVersion methods, and reformatted the toJson method for readability.
lib/src/package_version/pub_api_client.dart Reformatted the constructor parameters for clarity.
lib/src/prompts/confirm.dart Modified the prompt message format in the confirm function based on the defaultValue parameter.
lib/src/prompts/select.dart Adjusted formatting in the select method and _SelectState class for improved readability.
test/better_command_runner/analytics_test.dart Reformatted test case definitions for improved readability without altering functionality.
test/better_command_runner/command_test.dart Reformatted the alignment of method calls and test descriptions for clarity.
test/better_command_runner/default_flags_test.dart Reformatted test cases for the --verbose, --quiet, and --analytics flags for better readability.
test/better_command_runner/exit_exceptions_test.dart Adjusted formatting of test cases for improved readability without changing logic.
test/better_command_runner/logging_test.dart Reformatted a test case for logging error messages to enhance readability.
test/better_command_runner/parse_log_level_test.dart Reformatted a test case checking setLogLevel callback behavior for clarity.
test/better_command_test.dart Reformatted variable initialization and test case structure for improved readability.
test/documentation_generator/generate_markdown_test.dart Updated expected output assertions for the spice command to reflect correct markdown structure.
test/local_storage_manager/local_storage_manager_test.dart Reformatted test descriptions and method calls for improved readability.
test/package_version_test.dart Modified assertions in test cases for fetchLatestPackageVersion to streamline tests while preserving core functionality.
test/prompts/confirm_test.dart Reformatted test cases for clarity without altering logic.
test/prompts/input_test.dart Simplified test case formatting for improved readability.
test/pub_api_client_test.dart Reformatted test case definitions for clarity without changing functionality.
test/test_utils/io_helper.dart Reformatted the collectOutput method for clarity.
test/test_utils/mock_stdin.dart Reformatted method signatures in MockStdin class for improved readability.
test/test_utils/prompts/key_code_sequence.dart Added trailing commas in arrowUpSequence and arrowDownSequence declarations.
test/test_utils/prompts/option_matcher.dart Reformatted the describeMismatch method for better readability.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant T as Test Harness
    participant MS as MultiSelectPrompt
    U->>T: Send down arrow key presses
    T->>MS: Forward key inputs
    MS->>MS: Execute wrap-around logic
    MS-->>T: Return first option selected
    T->>U: Present the multiselect result
Loading
sequenceDiagram
    participant U as User
    participant T as Test Harness
    participant S as SelectPrompt
    U->>T: Send down arrow key presses
    T->>S: Forward key inputs
    S->>S: Execute wrap-around logic
    S-->>T: Return first option selected
    T->>U: Present the select prompt result
Loading

Poem

I'm a hopping rabbit with a smile so wide,
Testing loops where options coincide.
Down the keys I gently roam,
Wrapping around to call "Option 1" home.
In code fields where logic's fun,
Carrots and tests dance as one!


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d927fe0 and 2225aeb.

📒 Files selected for processing (30)
  • example/main.dart (1 hunks)
  • lib/src/analytics/analytics.dart (4 hunks)
  • lib/src/better_command_runner/better_command.dart (1 hunks)
  • lib/src/better_command_runner/better_command_runner.dart (5 hunks)
  • lib/src/logger/helpers/progress.dart (3 hunks)
  • lib/src/logger/logger.dart (3 hunks)
  • lib/src/logger/loggers/std_out_logger.dart (7 hunks)
  • lib/src/package_version/package_version.dart (3 hunks)
  • lib/src/package_version/pub_api_client.dart (1 hunks)
  • lib/src/prompts/confirm.dart (1 hunks)
  • lib/src/prompts/select.dart (5 hunks)
  • test/better_command_runner/analytics_test.dart (4 hunks)
  • test/better_command_runner/command_test.dart (2 hunks)
  • test/better_command_runner/default_flags_test.dart (3 hunks)
  • test/better_command_runner/exit_exceptions_test.dart (1 hunks)
  • test/better_command_runner/logging_test.dart (1 hunks)
  • test/better_command_runner/parse_log_level_test.dart (1 hunks)
  • test/better_command_test.dart (1 hunks)
  • test/documentation_generator/generate_markdown_test.dart (1 hunks)
  • test/local_storage_manager/local_storage_manager_test.dart (11 hunks)
  • test/package_version_test.dart (3 hunks)
  • test/prompts/confirm_test.dart (2 hunks)
  • test/prompts/input_test.dart (1 hunks)
  • test/prompts/multiple_select_test.dart (9 hunks)
  • test/prompts/select_test.dart (5 hunks)
  • test/pub_api_client_test.dart (1 hunks)
  • test/test_utils/io_helper.dart (1 hunks)
  • test/test_utils/mock_stdin.dart (9 hunks)
  • test/test_utils/prompts/key_code_sequence.dart (1 hunks)
  • test/test_utils/prompts/option_matcher.dart (1 hunks)
✅ Files skipped from review due to trivial changes (22)
  • test/test_utils/prompts/key_code_sequence.dart
  • test/better_command_runner/analytics_test.dart
  • lib/src/prompts/select.dart
  • lib/src/better_command_runner/better_command.dart
  • test/better_command_runner/command_test.dart
  • test/local_storage_manager/local_storage_manager_test.dart
  • test/better_command_runner/logging_test.dart
  • test/test_utils/io_helper.dart
  • test/prompts/input_test.dart
  • lib/src/logger/loggers/std_out_logger.dart
  • test/better_command_runner/exit_exceptions_test.dart
  • test/better_command_runner/default_flags_test.dart
  • lib/src/package_version/pub_api_client.dart
  • lib/src/logger/helpers/progress.dart
  • test/better_command_test.dart
  • test/prompts/confirm_test.dart
  • lib/src/analytics/analytics.dart
  • lib/src/logger/logger.dart
  • example/main.dart
  • lib/src/better_command_runner/better_command_runner.dart
  • lib/src/package_version/package_version.dart
  • test/test_utils/mock_stdin.dart
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/prompts/select_test.dart
  • test/prompts/multiple_select_test.dart
🔇 Additional comments (12)
test/better_command_runner/parse_log_level_test.dart (1)

107-115: LGTM! The formatting changes improve readability.

The test case has been reformatted with better line breaks and indentation while preserving the original functionality.

However, this change appears unrelated to the PR's objective of adding wrap-around tests for select lists.

Likely an incorrect or invalid review comment.

test/test_utils/prompts/option_matcher.dart (1)

55-57: LGTM! Clean formatting change.

The multi-line formatting improves readability while maintaining the same functionality.

test/pub_api_client_test.dart (2)

1-164: Verify the relevance of changes to PR objectives.

The changes in this file appear to be purely formatting-related, while the PR objectives mention adding tests for wrap-around behavior in select lists. This file tests pub API client functionality and doesn't contain any select list related tests.

Could you please confirm if the changes to this file were intentional? The actual tests for wrap-around behavior in select lists seem to be in test/prompts/multiple_select_test.dart and test/prompts/select_test.dart.


29-48: LGTM! The formatting changes improve readability.

The reformatting of test case definitions enhances readability by:

  • Using consistent indentation
  • Breaking long lines appropriately
  • Adding descriptive test names
  • Maintaining clear separation between test setup, execution, and assertions

Also applies to: 51-70, 73-94, 97-118, 120-140, 143-163

test/documentation_generator/generate_markdown_test.dart (2)

103-122: LGTM! Well-structured test assertion for command documentation.

The expected markdown output is properly formatted with clear sections for usage, description, and subcommands.


129-159: LGTM! Comprehensive test coverage for subcommand documentation.

The test properly verifies the markdown generation for subcommands, including their descriptions, usage syntax, and available options.

test/package_version_test.dart (5)

1-149: Inconsistency between PR objectives and file changes.

The PR title and description mention adding tests for wrap-around behavior in select lists. However, this file contains package version tests. Please verify if:

  1. The correct files are included in the review
  2. The PR description accurately reflects the intended changes

Likely an incorrect or invalid review comment.


9-26: LGTM! Test case validates cached version usage.

The test correctly verifies that when a cached version is still valid (within its "valid until" time), it is returned without attempting to fetch a new version.


28-64: LGTM! Comprehensive test for expired cache scenario.

The test thoroughly validates the behavior when cached version has expired:

  • Fetches new version from pub.dev
  • Stores the updated version with correct validity time
  • Returns the new version

93-120: LGTM! Test case validates first-time version fetch.

The test thoroughly verifies the behavior when fetching version for the first time:

  • Successfully fetches version
  • Stores it with correct validity time
  • Returns the fetched version

122-147: LGTM! Test case validates error handling.

The test properly verifies the behavior when version fetch fails:

  • Stores appropriate retry timeout
  • Returns null to indicate failure
lib/src/prompts/confirm.dart (1)

13-18: LGTM! Clear and intuitive prompt formatting.

The changes improve user experience by clearly indicating the default choice through case sensitivity ([Y/n] or [y/N]). The implementation is clean and handles all cases correctly.

Copy link
Collaborator

@christerswahn christerswahn left a comment

Choose a reason for hiding this comment

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

Looks good, just one comment!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
test/prompts/multiple_select_test.dart (1)

235-260: LGTM! Comprehensive test coverage for wrap-around functionality.

The test effectively validates that navigating past the first option wraps around to the last option. Together with the previous test, this provides complete coverage of wrap-around behavior.

Consider adding a test case that combines both up and down navigation to ensure smooth transitions in both directions. For example:

test('Given multiple select prompt with multiple options '
    'when navigating up and down past boundaries '
    'then wraps around correctly in both directions', () async {
  late Future<List<Option>> result;
  var options = [Option('Option 1'), Option('Option 2'), Option('Option 3')];

  await collectOutput(
    keyInputs: [
      ...arrowUpSequence, // Move to Option 3
      ...arrowDownSequence, // Move to Option 1
      ...arrowDownSequence, // Move to Option 2
      KeyCodes.space, // Select Option 2
      KeyCodes.enterCR,
    ],
    () {
      result = multiselect(
        'Choose multiple options:',
        options: options,
        logger: logger,
      );
    },
  );

  await expectLater(
    result,
    completion(containsAllOptions([Option('Option 2')])),
  );
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2225aeb and ea5a50e.

📒 Files selected for processing (2)
  • test/prompts/multiple_select_test.dart (9 hunks)
  • test/prompts/select_test.dart (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/prompts/select_test.dart
🔇 Additional comments (2)
test/prompts/multiple_select_test.dart (2)

12-175: LGTM! Clean formatting improvements.

The formatting changes improve readability while preserving the original test functionality.


206-233: LGTM! Well-structured test for wrap-around functionality.

The test effectively validates that navigating past the last option wraps around to the first option, with clear steps and appropriate assertions.

Copy link
Collaborator

@christerswahn christerswahn left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@SandPod SandPod merged commit 75a97a2 into main Feb 19, 2025
4 checks passed
@SandPod SandPod deleted the 18-wrap-around-validation-for-select-list branch February 19, 2025 13:41
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.

3 participants