Skip to content

Commit 0fdf1fd

Browse files
authored
Merge pull request #2742 from devvaansh/WEB-391-unit-test-coverage-for-url-to-string-pipe
Web 391 unit test coverage for url to string pipe
2 parents 03e6703 + 0cf886d commit 0fdf1fd

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { UrlToStringPipe } from './url-to-string.pipe';
2+
3+
describe('UrlToStringPipe', () => {
4+
let pipe: UrlToStringPipe;
5+
6+
beforeEach(() => {
7+
pipe = new UrlToStringPipe();
8+
});
9+
10+
it('should create an instance', () => {
11+
expect(pipe).toBeTruthy();
12+
});
13+
14+
describe('URL Transformations', () => {
15+
it('should transform single-segment URL', () => {
16+
expect(pipe.transform('/users')).toBe('Users');
17+
});
18+
19+
it('should transform multi-segment URL with pipe separators', () => {
20+
expect(pipe.transform('/admin/system/configuration')).toBe('Admin | System | Configuration');
21+
});
22+
23+
it('should capitalize first letter of each word', () => {
24+
expect(pipe.transform('/dashboard')).toBe('Dashboard');
25+
});
26+
27+
it('should transform hyphenated segments into space-separated words', () => {
28+
expect(pipe.transform('/user-management')).toBe('User Management');
29+
});
30+
31+
it('should handle multiple hyphens in single segment', () => {
32+
expect(pipe.transform('/loan-product-details')).toBe('Loan Product Details');
33+
});
34+
35+
it('should handle hyphens in multiple segments', () => {
36+
expect(pipe.transform('/client-accounts/savings-accounts')).toBe('Client Accounts | Savings Accounts');
37+
});
38+
39+
it('should remove query parameters from URL', () => {
40+
expect(pipe.transform('/users?id=123')).toBe('Users');
41+
});
42+
43+
it('should handle query parameters in multi-segment URLs', () => {
44+
expect(pipe.transform('/clients/details?clientId=456')).toBe('Clients | Details');
45+
});
46+
47+
it('should handle multiple query parameters', () => {
48+
expect(pipe.transform('/reports/view?type=loan&status=active')).toBe('Reports | View');
49+
});
50+
51+
it('should decode URL-encoded spaces', () => {
52+
expect(pipe.transform('/users%20management')).toBe('Users management');
53+
});
54+
55+
it('should decode URL-encoded special characters', () => {
56+
expect(pipe.transform('/client%20%26%20accounts')).toBe('Client & accounts');
57+
});
58+
59+
it('should handle URL with only leading slash', () => {
60+
expect(pipe.transform('/')).toBe('');
61+
});
62+
63+
it('should handle URL with trailing slash', () => {
64+
expect(pipe.transform('/users/')).toBe('Users | ');
65+
});
66+
67+
it('should handle empty segments', () => {
68+
expect(pipe.transform('/users//accounts')).toBe('Users | | Accounts');
69+
});
70+
71+
it('should handle single character segments', () => {
72+
expect(pipe.transform('/a/b/c')).toBe('A | B | C');
73+
});
74+
75+
it('should handle numeric segments', () => {
76+
expect(pipe.transform('/client/123/accounts')).toBe('Client | 123 | Accounts');
77+
});
78+
79+
it('should handle mixed case input', () => {
80+
expect(pipe.transform('/UserManagement/ClientAccounts')).toBe('UserManagement | ClientAccounts');
81+
});
82+
83+
it('should handle uppercase input', () => {
84+
expect(pipe.transform('/API/Settings')).toBe('API | Settings');
85+
});
86+
});
87+
88+
describe('Real-World Usage', () => {
89+
it('should transform navigation breadcrumb URL', () => {
90+
expect(pipe.transform('/clients/view-client/general')).toBe('Clients | View Client | General');
91+
});
92+
93+
it('should transform settings page URL', () => {
94+
expect(pipe.transform('/system/manage-data-tables')).toBe('System | Manage Data Tables');
95+
});
96+
97+
it('should transform report URL with query params', () => {
98+
expect(pipe.transform('/reports/run-report?reportId=5')).toBe('Reports | Run Report');
99+
});
100+
101+
it('should transform user profile edit URL', () => {
102+
expect(pipe.transform('/users/edit-user/123')).toBe('Users | Edit User | 123');
103+
});
104+
105+
it('should transform deep nested URL', () => {
106+
expect(pipe.transform('/products/loan-products/edit-loan-product/details')).toBe(
107+
'Products | Loan Products | Edit Loan Product | Details'
108+
);
109+
});
110+
});
111+
});

0 commit comments

Comments
 (0)