Skip to content

[Test Improver] Add unit tests for projectAndNamespaceFiltering.utils - #109

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/project-ns-filtering-utils-b6266dfe055bc3cd
Draft

[Test Improver] Add unit tests for projectAndNamespaceFiltering.utils#109
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/project-ns-filtering-utils-b6266dfe055bc3cd

Conversation

@github-actions

Copy link
Copy Markdown

🤖 This PR was created by Test Improver, an automated AI assistant focused on improving test coverage.

Goal and Rationale

shell/plugins/steve/projectAndNamespaceFiltering.utils.ts had no test coverage. It implements namespace/project filtering logic for the Steve API store — controlling which resources are fetched from specific namespaces/projects via the projectsornamespaces query parameter. The createParam function has non-trivial branching: prefix stripping (ns://, project://), include vs. exclude handling (leading -), and multi-value join logic. isEnabled guards behind three separate conditions (store type, workspace switcher, feature flag).

Approach

  • isApplicable (5 tests): verifies Array detection for opt.namespaced — empty array, populated array, undefined, string, absent property.
  • isEnabled (6 tests): mocks rootGetters with currentProduct and management/byId returning a perf setting. Covers happy path plus each early-return condition (wrong inStore, showWorkspaceSwitcher, forceNsFilterV2 disabled, default settings, null product).
  • createParam (10 tests): covers undefined/empty input, plain namespace, ns:// prefix strip, project:// prefix strip, multi-include join, mixed-prefix join, single/multi exclude with leading dash, and the precedence rule that exclude overwrites include when both are present.
  • checkAndCreateParam (4 tests): end-to-end delegation — non-array opt returns '', empty array returns '', populated array produces the query param, prefix stripping works.

Coverage Impact

25 tests added. All branches in createParam, isApplicable, and checkAndCreateParam covered; isEnabled covers all 4 branches.

Trade-offs

  • Tests mock rootGetters inline — consistent with existing patterns in settings.test.ts.
  • No new dependencies.

Reproducibility

YARN_IGNORE_ENGINES=true NODE_OPTIONS=--max_old_space_size=8192 yarn test:ci --testPathPattern='projectAndNamespaceFiltering.utils.test.ts'

Test Status

✅ All 25 tests pass. ESLint: 0 warnings.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • download.cypress.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "download.cypress.io"

See Network Configuration for more information.

Generated by Daily Test Improver · ● 4.3M ·

Add 25 unit tests for `projectAndNamespaceFiltering.utils.ts`:

- isApplicable: 5 cases — array (empty/non-empty), undefined,
  string-typed namespaced, and absent property
- isEnabled: 6 cases — happy path, wrong inStore, workspace switcher
  enabled, forceNsFilterV2 disabled, default perf settings (disabled),
  null currentProduct
- createParam: 10 cases — undefined/empty input, plain namespace,
  ns:// prefix strip, project:// prefix strip, multi-include join,
  mixed-prefix join, single/multi exclude with leading dash,
  exclude-overrides-include precedence
- checkAndCreateParam: 4 cases — non-array opt, empty array, populated
  array, ns:// prefix stripping

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants