-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(angular-apollo-tailwind): append protocol if missing from user url (
#637) * fix(angular-apollo-tailwind): append protocol if missing from user url Refs: #591 * test(angular-apollo-tailwind): update with testcases Closes: #591
- Loading branch information
Showing
6 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...s/shared/src/lib/pipes/generate-url-with-protocol/generate-url-with-protocol.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { GenerateUrlWithProtocolPipe } from './generate-url-with-protocol.pipe'; | ||
|
||
describe('GenerateUrlWithProtocolPipe', () => { | ||
it('create an instance', () => { | ||
const pipe = new GenerateUrlWithProtocolPipe(); | ||
expect(pipe).toBeTruthy(); | ||
}); | ||
|
||
it('should append https to url with no protocol', () => { | ||
const pipe = new GenerateUrlWithProtocolPipe(); | ||
expect(pipe.transform('test.com')).toBe('https://test.com'); | ||
}); | ||
|
||
it('should return url untouched if it has protocol appended', () => { | ||
const pipe = new GenerateUrlWithProtocolPipe(); | ||
expect(pipe.transform('https://test.com')).toBe('https://test.com'); | ||
}); | ||
|
||
it('should not attempt to change url with http to https', () => { | ||
const pipe = new GenerateUrlWithProtocolPipe(); | ||
expect(pipe.transform('http://test.com')).toBe('http://test.com'); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
...ojects/shared/src/lib/pipes/generate-url-with-protocol/generate-url-with-protocol.pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
|
||
@Pipe({ | ||
name: 'generateUrlWithProtocol', | ||
}) | ||
export class GenerateUrlWithProtocolPipe implements PipeTransform { | ||
transform(value: string): string { | ||
return ['http://', 'https://'].some((protocol) => | ||
value.startsWith(protocol), | ||
) | ||
? value | ||
: `https://${value}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './dfns/format-distance.pipe'; | ||
export * from './number/round-up.pipe'; | ||
export * from './markdown/markdown.pipe'; | ||
export * from './generate-url-with-protocol/generate-url-with-protocol.pipe'; | ||
export * from './pipes.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters