Skip to content

Conversation

@DEVANSH-GAJJAR
Copy link

@DEVANSH-GAJJAR DEVANSH-GAJJAR commented Jan 11, 2026

Description

This PR adds unit tests for the Debouncer utility to ensure correct timing, cancellation, and disposal behavior.

Fixes #709

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking CHANGE which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Command used:

flutter test test/utils/debouncer.dart

How Has This Been Tested?

Unit tests were added for the Debouncer class and executed locally using Flutter’s test runner.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tag the PR with the appropriate labels

Summary by CodeRabbit

  • Tests

    • Added unit tests for the Debouncer utility covering execution after debounce delay, cancellation of prior invocations when retriggered, and cancellation on disposal.
  • Chores

    • Updated ignore rules to exclude build output directories from version control.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions
Copy link
Contributor

🎉 Welcome @DEVANSH-GAJJAR!
Thank you for your pull request! Our team will review it soon. 🔍

  • Please ensure your PR follows the contribution guidelines. ✅
  • All automated tests should pass before merging. 🔄
  • If this PR fixes an issue, link it in the description. 🔗

We appreciate your contribution! 🚀

@coderabbitai
Copy link

coderabbitai bot commented Jan 11, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

Added three ignore patterns to .gitignore and introduced a new test file test/utils/debouncer.dart containing three unit tests for the Debouncer utility.

Changes

Cohort / File(s) Summary
Build Directory Exclusions
\.gitignore
Appended ignore entries: build/, test/build/, and test/utils/build/.
Debouncer Tests
test/utils/debouncer.dart
New test file with three unit tests: verifies action runs after debounce delay, verifies repeated run calls cancel prior actions so only last runs, and verifies dispose cancels pending actions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A hop, a pause, a gentle delay,
I test the bounce that keeps bugs away,
Ignoring builds so the repo stays neat,
Three little tests make the rhythm complete. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'test: add unit tests for Debouncer utility' accurately summarizes the main change—adding unit tests for the Debouncer utility—and is concise and specific.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

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: 3

🤖 Fix all issues with AI agents
In @test/utils/debouncer.dart:
- Around line 6-17: The test "executes action after debounce duration" uses
Debouncer(milliseconds: 50) but only awaits Future.delayed(const
Duration(milliseconds: 60)), which is a tight 10ms buffer and can flake;
increase the delay to a safer value (e.g., 100ms or 150ms) in the Future.delayed
call so the debounced callback has ample time to run reliably in CI and slow
environments.
- Around line 19-34: The test "cancels previous action when run is called again"
uses a 50ms Debouncer and only awaits 60ms which is a small 10ms buffer and can
be flaky in CI; update the test in test/utils/debouncer.dart to increase the
post-run wait (e.g., await Future.delayed(const Duration(milliseconds: 100)) or
similar) so there is a safe margin beyond Debouncer(milliseconds: 50), keeping
the Debouncer instantiation and test logic (count, debouncer.run calls, expect)
unchanged.
- Around line 36-49: The test "dispose cancels pending action" uses a 50ms
Debouncer and only waits 60ms before asserting, which is flaky; increase the
post-dispose wait to a larger buffer (e.g., change Future.delayed(const
Duration(milliseconds: 60)) to at least 100–150ms or to (debouncer milliseconds
+ 50–100ms)) so the environment scheduling variance is covered; keep the test
logic and expect(called, false) unchanged and reference the Debouncer class and
the test name when making the change.
🧹 Nitpick comments (2)
.gitignore (1)

56-58: Consider simplifying the build directory ignore patterns.

The pattern build/ on line 56 already matches build directories at any level in the repository tree, making the more specific patterns on lines 57-58 (test/build/ and test/utils/build/) redundant. You can remove lines 57-58 to simplify the configuration.

♻️ Suggested simplification
 build/
-test/build/
-test/utils/build/
test/utils/debouncer.dart (1)

4-51: Good test coverage for core Debouncer functionality.

The tests effectively cover the main debouncer behaviors: execution timing, cancellation, and disposal. The test structure is clear and assertions are appropriate.

For even more comprehensive coverage, you could optionally consider adding tests for edge cases such as:

  • Multiple calls to dispose() (idempotency)
  • Calling run() after dispose()
  • Verifying that dispose() after the action has already executed is safe
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf1dbe2 and 875e2a9.

📒 Files selected for processing (2)
  • .gitignore
  • test/utils/debouncer.dart

@M4dhav
Copy link
Contributor

M4dhav commented Jan 11, 2026

Please open an issue for the PR and raise it to dev, not master

@DEVANSH-GAJJAR DEVANSH-GAJJAR changed the base branch from master to dev January 12, 2026 15:33
@DEVANSH-GAJJAR
Copy link
Author

Merge conflict resolved. Kept the dev branch version of CODEOWNERS and cleaned up the file.
Thanks!

@M4dhav
Copy link
Contributor

M4dhav commented Jan 14, 2026

There are some unrelated commits in the PR, could you delete those please

@DEVANSH-GAJJAR DEVANSH-GAJJAR force-pushed the test/add-unit-tests-service branch from 06b5269 to 678ca43 Compare January 15, 2026 05:30
@DEVANSH-GAJJAR
Copy link
Author

Thanks for pointing that out!
I’ve cleaned up the PR and removed the unrelated commits, keeping only the latest relevant commit for the Debouncer unit tests.
Please let me know if everything looks good now.

@M4dhav M4dhav linked an issue Jan 17, 2026 that may be closed by this pull request
@DEVANSH-GAJJAR
Copy link
Author

Hi, I have resolved the merge conflicts, and removed the unrelated commits

The PR is now clean and ready for review. Please let me know if any further changes are required.

Thanks!

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.

Add unit tests for Debouncer utility

2 participants