Skip to content

test: 完善测试覆盖,新增 121 个测试用例#43

Open
sunnylqm wants to merge 1 commit into
mainfrom
test/add-comprehensive-tests
Open

test: 完善测试覆盖,新增 121 个测试用例#43
sunnylqm wants to merge 1 commit into
mainfrom
test/add-comprehensive-tests

Conversation

@sunnylqm
Copy link
Copy Markdown
Collaborator

@sunnylqm sunnylqm commented Jun 3, 2026

Summary

为 pushy-admin 项目新增全面的单元测试,测试总数从 47 增加到 168(新增 121 个)。

新增/扩展的测试文件

src/utils/helper.test.ts (+30 tests)

  • cn() — 类名拼接、undefined/空值过滤
  • promiseAny() — 第一个成功、全部失败、空数组、快慢竞争
  • patchSearchParams() — 参数设置/删除/覆盖、自定义导航选项
  • ManageAppDrawerPlacement — 默认值、window 不存在、无效值、事件派发
  • ManageAppDrawerCollapsed — 读写 localStorage、边界值
  • isPasswordValid — 边界长度 6/16、空字符串、特殊字符
  • isValidExternalUrl — 空字符串、ftp、后缀域名匹配
  • isExpVersion — 边界值 1/99、多版本互不影响

src/utils/billing.test.ts (+36 tests)

  • resolveMonthlyPriceFactor() — 默认值、NaN/Infinity/负数/字符串
  • resolveMonthlyPrice() — 除法、舍入、零值、EPSILON 边界
  • parseBillingMonths() — 数字/字符串/小数/null/undefined
  • resolveBillingPlan() — 默认月数、零价格、自定义因子、异常抛出
  • getAnnualSavings() — 月付无节省、年价等于月总额
  • getBillingOptions() — 自定义年月数、字段完整性、排序

src/utils/hooks.test.tsx (+15 tests)

  • getPackageTimestampWarnings() — dict 为空/undefined、packages 为空、前缀不匹配、buildTime 一致/不同、unknown/0 忽略、多包、去重、下划线包名、排序
  • useLocalStorageCooldown — 其他 key 的 storage 事件、无效/负数存储值

src/utils/query-keys.test.ts (new, 12 tests)

  • versionKeys.byApp/page/all — 正确性、键隔离、唯一性

Summary by CodeRabbit

  • Tests
    • Expanded test coverage for billing utilities, including monthly price factors, billing months parsing, and various billing plan scenarios.
    • Enhanced test suite for helper utilities covering password validation, promise handling, and local storage edge cases.
    • Strengthened tests for hooks including package timestamp warnings and local storage cooldown behavior.
    • Added comprehensive test coverage for version query-key builders.

- helper.test.ts: add tests for cn(), promiseAny(), patchSearchParams(),
  ManageAppDrawerPlacement, ManageAppDrawerCollapsed, and boundary cases
  for isPasswordValid/isValidExternalUrl/isExpVersion
- billing.test.ts: add tests for resolveMonthlyPriceFactor(),
  resolveMonthlyPrice(), parseBillingMonths(), and edge cases for
  resolveBillingPlan/getAnnualSavings/getBillingOptions
- hooks.test.tsx: add 15 tests for getPackageTimestampWarnings() pure
  function (empty inputs, dedup, sorting, underscore names, ignored
  timestamps) plus cooldown edge cases (invalid/negative values, other
  storage keys)
- query-keys.test.ts: new file testing versionKeys factory (byApp, page,
  all, key isolation)

Total: 47 → 168 tests
@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 3, 2026

Deploy Preview for pushy ready!

Name Link
🔨 Latest commit fb90bd0
🔍 Latest deploy log https://app.netlify.com/projects/pushy/deploys/6a203b0bb5d4420008308aab
😎 Deploy Preview https://deploy-preview-43--pushy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7038ae95-be4e-4173-bf3e-82fd8507b8cd

📥 Commits

Reviewing files that changed from the base of the PR and between de6318d and fb90bd0.

📒 Files selected for processing (4)
  • src/utils/billing.test.ts
  • src/utils/helper.test.ts
  • src/utils/hooks.test.tsx
  • src/utils/query-keys.test.ts

📝 Walkthrough

Walkthrough

This PR adds comprehensive unit test coverage across four utility modules. The changes expand existing test suites for billing, helper, and hooks utilities with edge cases and boundary conditions, and introduce a new test suite for query key builders—totaling +1,010 new lines of test code with zero modifications to production code.

Changes

Test Coverage Expansion

Layer / File(s) Summary
Billing utilities test suite
src/utils/billing.test.ts
Expands imports and adds coverage for resolveMonthlyPriceFactor, resolveMonthlyPrice, parseBillingMonths with invalid-input fallbacks; extends resolveBillingPlan with month defaulting, factor storage, and annual switching; validates getAnnualSavings zero-savings scenarios; and comprehensively tests getBillingOptions for ordering, billing cycles, and field shape invariants.
Helper utilities test suite
src/utils/helper.test.ts
Expands imports and adds boundary-length password validation, CSS class composition with undefined filtering, promise racing, search parameter patching with navigation options, experiment version rollout boundaries, external URL validation with protocol/domain/fragment checks, localStorage edge cases for recent app storage, and full coverage for manage drawer placement and collapsed state getters/setters including persistence, event dispatch, and undefined window handling.
Hooks utilities test suite
src/utils/hooks.test.tsx
Introduces comprehensive test suite for getPackageTimestampWarnings covering empty/multi-package inputs, timestamp deduplication, and sorted output; updates useLocalStorageCooldown tests with precise remaining-seconds assertions, storage event dispatch validation, cooldown completion checks, and graceful invalid/negative value handling.
Query keys test suite
src/utils/query-keys.test.ts
Introduces new test file with full coverage for versionKeys query key builders: validates byApp tuple structure, page key construction with offset/limit variance, all key distinctness, and key isolation across different app identifiers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • reactnativecn/pushy-admin#42: Expands the same src/utils/helper.test.ts file with localStorage edge-case tests for getRecentAppIds and rememberRecentApp, overlapping on the same test coverage theme.

Poem

🐰 A rabbit hops through tests with care,
Checking edges everywhere—
Billing plans, helpers true, hooks that work,
Query keys where data lurk.
Coverage blooms with every case! 🌱

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly describes the main change: adding comprehensive test coverage with 121 new test cases, which directly aligns with the changeset's core objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/add-comprehensive-tests

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.

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.

1 participant