Skip to content

Web 391 unit test coverage for url to string pipe#2742

Merged
gkbishnoi07 merged 1 commit intoopenMF:devfrom
devvaansh:WEB-391-unit-test-coverage-for-url-to-string-pipe
Nov 2, 2025
Merged

Web 391 unit test coverage for url to string pipe#2742
gkbishnoi07 merged 1 commit intoopenMF:devfrom
devvaansh:WEB-391-unit-test-coverage-for-url-to-string-pipe

Conversation

@devvaansh
Copy link
Member

@devvaansh devvaansh commented Nov 1, 2025

Description

This PR adds comprehensive unit test coverage for the UrlToStringPipe, a critical utility pipe used throughout the application for transforming URL paths into human-readable strings for navigation breadcrumbs and UI routing displays.

Changes Made
New File:

src/app/pipes/url-to-string.pipe.spec.ts - Complete test suite with 30 test cases achieving 100% code coverage

Test Coverage Details

The test suite includes 30 comprehensive test cases covering:

Basic URL Transformations (4 tests)

Single and multi-segment URLs
Proper capitalization and pipe separators
Hyphenated Path Segments (4 tests)

Converting hyphens to space-separated words
Multiple hyphens within segments
Mixed hyphenated and non-hyphenated paths
Query Parameters (5 tests)

Removing query parameters
Handling multiple query parameters
Complex URLs with various query string formats
URL Encoding (4 tests)

Decoding URL-encoded spaces and special characters
Multi-segment encoded URLs
Edge Cases (7 tests)

Empty URLs, trailing slashes, empty segments
Single character and numeric segments
Mixed case handling
Real-World Application Scenarios (5 tests)

Navigation breadcrumbs: /clients/view-client/general → Clients | View Client | General
Settings pages: /system/manage-data-tables → System | Manage Data Tables
Report URLs with query params
Deep nested URLs with multiple segments

Related issues and discussion

WEB-391

Screenshots, if any

Before

Screenshot 2025-11-02 at 2 37 47 AM

After

Screenshot 2025-11-02 at 2 38 52 AM Screenshot 2025-11-02 at 2 39 07 AM

100% test coverage

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • If you have multiple commits please combine them into one commit by squashing them.

  • Read and understood the contribution guidelines at web-app/.github/CONTRIBUTING.md.

Summary by CodeRabbit

  • Tests
    • Added a comprehensive unit test suite for URL-to-string transformations covering basic conversions, hyphenated segments, query-parameter stripping, encoding/decoding, edge cases (leading/trailing slashes, empty/single/numeric segments, mixed casing) and real-world paths (navigation, settings, reports, profiles, deep nesting). No production behavior changes; improves stability and helps prevent regressions.

@coderabbitai
Copy link

coderabbitai bot commented Nov 1, 2025

Walkthrough

Added a new unit test suite for UrlToStringPipe at src/app/pipes/url-to-string.pipe.spec.ts that verifies segment transformations, hyphen handling, query parameter stripping, URL decoding, and many edge and real-world URL scenarios. No production code changed.

Changes

Cohort / File(s) Summary
Test suite
src/app/pipes/url-to-string.pipe.spec.ts
New comprehensive unit tests covering: basic segment transformations and capitalization, hyphenated segments, query parameter removal, URL encoding/decoding, edge cases (leading/trailing slashes, empty segments, single-character and numeric segments, mixed casing), and real-world navigation scenarios (breadcrumbs, settings, reports, profiles, deep nesting).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify tests match the intended pipe behavior for capitalization and joining (e.g., " | ").
  • Confirm query parameter removal and decoding expectations are correct.
  • Check edge-case coverage (empty segments, slashes, numeric/single-char segments).
  • Ensure no production files were modified and test descriptions/assertions are clear.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Web 391 unit test coverage for url to string pipe" directly and clearly describes the main change in the changeset—the addition of comprehensive unit tests for the UrlToStringPipe. It is concise, specific, and avoids vague terminology, making it immediately clear to reviewers that this PR introduces test coverage for a specific pipe related to issue WEB-391. The title accurately reflects the primary objective of the PR without unnecessary verbosity or ambiguity.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@devvaansh devvaansh force-pushed the WEB-391-unit-test-coverage-for-url-to-string-pipe branch from 4318147 to 7c004f1 Compare November 1, 2025 21:24
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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 03e6703 and 7c004f1.

📒 Files selected for processing (1)
  • src/app/pipes/url-to-string.pipe.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/app/**

⚙️ CodeRabbit configuration file

src/app/**: For Angular code: verify component separation, trackBy on *ngFor,
strict type safety, and clean observable patterns.

Files:

  • src/app/pipes/url-to-string.pipe.spec.ts
**/*.spec.ts

⚙️ CodeRabbit configuration file

**/*.spec.ts: For tests: encourage clear Arrange-Act-Assert structure,
stable selectors, and minimal brittle timing dependencies.

Files:

  • src/app/pipes/url-to-string.pipe.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Run Lint, Build and Deploy
🔇 Additional comments (3)
src/app/pipes/url-to-string.pipe.spec.ts (3)

92-120: Verify edge case handling behavior.

Several edge case tests have expectations that may indicate unexpected behavior in the pipe implementation:

  1. Trailing slash (line 98): /users/ produces 'Users | ' with a trailing pipe and space for the empty final segment.
  2. Empty segments (line 102): /users//accounts produces 'Users | | Accounts' with double spaces between pipes.
  3. Mixed case preservation (line 114): /UserManagement/ClientAccounts preserves the original casing as 'UserManagement | ClientAccounts' rather than normalizing to title case.

Please confirm these behaviors are intentional. If not, consider whether the pipe should:

  • Strip trailing slashes before processing
  • Filter out empty segments
  • Normalize all segments to consistent title case

122-144: Excellent real-world test coverage.

The real-world scenario tests provide valuable coverage of actual application URL patterns including navigation breadcrumbs, settings pages, reports, user profiles, and deeply nested routes.


74-90: Incorrect review comment—test expectations are correct.

The pipe implementation only capitalizes the first character of hyphen-separated segments (by splitting on -). Spaces—whether literal or URL-encoded as %20—are not treated as word boundaries for capitalization. All test expectations align perfectly with this behavior:

  • 'Users management' is correct (only the first char capitalized; no hyphen to split on)
  • 'Loan Product details' is correct (loan-product['loan', 'product details'] → capitalize → 'Loan Product details')

The capitalization pattern is consistent and intentional per the implementation.

Likely an incorrect or invalid review comment.

@devvaansh devvaansh force-pushed the WEB-391-unit-test-coverage-for-url-to-string-pipe branch from 7c004f1 to 20ce310 Compare November 1, 2025 21:44
@devvaansh
Copy link
Member Author

@steinwinde plz take a look

@devvaansh devvaansh force-pushed the WEB-391-unit-test-coverage-for-url-to-string-pipe branch from 20ce310 to 0cf886d Compare November 2, 2025 10:26
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

🧹 Nitpick comments (1)
src/app/pipes/url-to-string.pipe.spec.ts (1)

14-86: Consider more granular describe blocks for better organization.

The PR description mentions grouping tests into: Basic URL transformations (4 tests), Hyphenated path segments (4 tests), Query parameters (5 tests), URL encoding (4 tests), and Edge cases (7 tests). Currently, all 22 tests are in a single "URL Transformations" describe block.

Consider restructuring with nested describe blocks to match the documented organization:

-  describe('URL Transformations', () => {
+  describe('URL Transformations', () => {
+    describe('Basic transformations', () => {
       it('should transform single-segment URL', () => {
         expect(pipe.transform('/users')).toBe('Users');
       });
       // ... other basic tests
+    });
+
+    describe('Hyphenated path segments', () => {
       it('should transform hyphenated segments into space-separated words', () => {
         expect(pipe.transform('/user-management')).toBe('User Management');
       });
       // ... other hyphen tests
+    });
+
+    describe('Query parameters', () => {
       it('should remove query parameters from URL', () => {
         expect(pipe.transform('/users?id=123')).toBe('Users');
       });
       // ... other query param tests
+    });
+
+    describe('URL encoding', () => {
       it('should decode URL-encoded spaces', () => {
         expect(pipe.transform('/users%20management')).toBe('Users management');
       });
       // ... other encoding tests
+    });
+
+    describe('Edge cases', () => {
       it('should handle URL with only leading slash', () => {
         expect(pipe.transform('/')).toBe('');
       });
       // ... other edge case tests
+    });
   });

This would improve test discoverability and match the documentation in the PR description.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20ce310 and 0cf886d.

📒 Files selected for processing (1)
  • src/app/pipes/url-to-string.pipe.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/app/**

⚙️ CodeRabbit configuration file

src/app/**: For Angular code: verify component separation, trackBy on *ngFor,
strict type safety, and clean observable patterns.

Files:

  • src/app/pipes/url-to-string.pipe.spec.ts
**/*.spec.ts

⚙️ CodeRabbit configuration file

**/*.spec.ts: For tests: encourage clear Arrange-Act-Assert structure,
stable selectors, and minimal brittle timing dependencies.

Files:

  • src/app/pipes/url-to-string.pipe.spec.ts
🔇 Additional comments (3)
src/app/pipes/url-to-string.pipe.spec.ts (3)

79-85: Document the capitalization logic for mixed-case inputs.

These tests show that mixed-case inputs preserve their original casing ('UserManagement' stays 'UserManagement'), while lowercase inputs get capitalized ('/users''Users'). This behavior may be intentional but creates inconsistency:

  • /users'Users' (capitalized)
  • /UserManagement'UserManagement' (preserved)
  • /api → would become 'Api'
  • /API'API' (preserved)

Consider adding a comment in the test suite documenting this capitalization behavior, or verify whether all segments should be normalized to consistent casing for better UI consistency.


51-57: Dismiss the capitalization concern—tests accurately reflect the pipe's actual behavior.

The pipe only capitalizes words separated by hyphens (which are converted to spaces). URL-encoded spaces (%20) remain spaces in the decoded string and don't trigger word-by-word capitalization since the pipe splits only on hyphens, not spaces. The tests correctly reflect this intentional behavior:

  • /users%20management'Users management' (space not split)
  • /user-management'User Management' (hyphen split and both words capitalized)

The tests in lines 51-57 are consistent with the implementation and correctly document the pipe's actual behavior.


67-69: The test correctly reflects the pipe's intended behavior—no changes needed.

The implementation in src/app/pipes/url-to-string.pipe.ts deliberately preserves empty segments. The code joins all segments (including empty ones) with the ' | ' separator at line 22: .join(' | '). The test at lines 67-69 accurately verifies this behavior.

Additionally, the related test for trailing slashes (/users/'Users | ') confirms this is intentional design, not a bug. The pipe maintains URL structure integrity by preserving segment count, which is useful for breadcrumb navigation that reflects the exact path structure.

Likely an incorrect or invalid review comment.

});

it('should handle URL with trailing slash', () => {
expect(pipe.transform('/users/')).toBe('Users | ');
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify trailing slash behavior produces desired output.

The test expects /users/ to transform to 'Users | ' (with a trailing pipe separator and space). For navigation breadcrumbs and UI display, this trailing separator is likely undesirable and may indicate a bug in the pipe implementation rather than intended behavior.

Consider whether the expected output should simply be 'Users' instead. Verify the actual requirements for trailing slash handling.


I'll examine the pipe implementation and test context to verify whether the trailing separator is intended behavior or a bug.




🏁 Script executed:

#!/bin/bash
# Locate and examine the url-to-string pipe implementation
find . -type f -name "*url-to-string.pipe.ts" ! -path "*/node_modules/*" ! -path "*/.git/*" | head -20

Length of output: 37


🏁 Script executed:

#!/bin/bash
# View the full test file to understand the test context
cat src/app/pipes/url-to-string.pipe.spec.ts

Length of output: 3848


🏁 Script executed:

#!/bin/bash
# Look for the pipe implementation file
cat src/app/pipes/url-to-string.pipe.ts 2>/dev/null || echo "File not found at expected location"

Length of output: 900


Let me search for actual usages of this pipe to understand if the trailing separator behavior is intentional or a bug:


---

🏁 Script executed:

```shell
#!/bin/bash
# Find usages of the urlToString pipe in the codebase
rg -n "urlToString" --type=ts --type=html -g '!*.spec.ts' | head -30

Length of output: 68


🏁 Script executed:

#!/bin/bash
# Check if there are any component or service comments about expected behavior
rg -n -B5 -A5 "UrlToStringPipe" src/app --type=ts -g '!*.spec.ts'

Length of output: 3396


Update pipe implementation to filter empty segments and correct test expectations.

The trailing pipe and space are indeed undesirable. The implementation bug: url.slice(1).split('/') produces empty strings for trailing slashes (e.g., /users/['users', '']), which are joined directly without filtering, producing 'Users | '.

Required fixes:

  1. Update the pipe to filter empty segments: urlSubstrings.filter(seg => seg.length > 0)
  2. Update line 64 expectation from 'Users | ' to 'Users'
  3. Update line 68 expectation from 'Users | | Accounts' to 'Users | Accounts'

The JSDoc example (self-service/users :: Self Service | Users) confirms the intended behavior excludes trailing separators.

🤖 Prompt for AI Agents
In src/app/pipes/url-to-string.pipe.spec.ts around lines 64 and 68, the test
expectations assume the pipe leaves empty segments from trailing slashes
resulting in a trailing " | " and an extra empty segment; update the pipe
implementation to filter out empty URL segments (e.g., use
urlSubstrings.filter(seg => seg.length > 0) when deriving segments) and update
the test expectations: change line 64 from 'Users | ' to 'Users' and change line
68 from 'Users |  | Accounts' to 'Users | Accounts'.

Copy link
Collaborator

@gkbishnoi07 gkbishnoi07 left a comment

Choose a reason for hiding this comment

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

@devvaansh great work! Devvansh thanks for the Pr 😃

@gkbishnoi07 gkbishnoi07 merged commit 0fdf1fd into openMF:dev Nov 2, 2025
3 checks passed
@devvaansh devvaansh deleted the WEB-391-unit-test-coverage-for-url-to-string-pipe branch November 2, 2025 18:34
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