Skip to content

Commit 883e1c2

Browse files
vNovskiFrancescoMolinaro
authored andcommitted
[DSC-1484] feature: added internal link service
1 parent afa29ca commit 883e1c2

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/app/core/services/internal-link.service.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ describe('InternalLinkService', () => {
4747

4848
describe('transformInternalLink', () => {
4949
it('should transform internal link by removing currentURL', () => {
50-
const result = service.getRelativePath('https://currentdomain/my-link');
50+
const result = service.transformInternalLink('https://currentdomain/my-link');
5151
expect(result).toBe('/my-link');
5252
});
5353

5454
it('should transform internal link by adding leading "/" if missing', () => {
55-
const result = service.getRelativePath('currentdomain/my-link');
55+
const result = service.transformInternalLink('currentdomain/my-link');
5656
expect(result).toBe('/my-link');
5757
});
5858

5959
it('should return unchanged link for external link', () => {
60-
const result = service.getRelativePath('https://externalDomain/my-link');
60+
const result = service.transformInternalLink('https://externalDomain/my-link');
6161
expect(result).toBe('https://externalDomain/my-link');
6262
});
6363

6464
it('should return unchanged link for internal link with leading "/"', () => {
65-
const result = service.getRelativePath('/my-link');
65+
const result = service.transformInternalLink('/my-link');
6666
expect(result).toBe('/my-link');
6767
});
6868
});

src/app/core/services/internal-link.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class InternalLinkService {
1919
* Check if the provided link is internal, i.e., it starts with a '/' or matches the current URL.
2020
*
2121
* @param link The link to be checked.
22+
* @param currentURL The current URL to compare against.
2223
* @returns A boolean indicating whether the link is internal.
2324
*/
2425
public isLinkInternal(link: string): boolean {
@@ -33,12 +34,13 @@ export class InternalLinkService {
3334
}
3435

3536
/**
36-
* Get the relative path for an internal link based on the current URL.
37+
* Transform an internal link based on the current URL.
3738
*
38-
* @param link The internal link to be transformed.
39-
* @returns The relative path for the given internal link.
39+
* @param link The link to be transformed.
40+
* @param currentURL The current URL used for transformation.
41+
* @returns The transformed internal link.
4042
*/
41-
public getRelativePath(link: string): string {
43+
public transformInternalLink(link: string): string {
4244
// Create a Domain object for the provided link
4345
const currentDomain = new URL(this.currentURL).hostname;
4446

0 commit comments

Comments
 (0)