Skip to content

Commit

Permalink
fix(angular-apollo-tailwind): append protocol if missing from user url (
Browse files Browse the repository at this point in the history
#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
asincole authored and hdJerry committed Nov 16, 2022
1 parent 59333fa commit eca9db2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
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');
});
});
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}`;
}
}
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';
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ import { NgModule } from '@angular/core';
import { RoundUpPipe } from './number/round-up.pipe';
import { FormatDistancePipe } from './dfns/format-distance.pipe';
import { MarkdownPipe } from './markdown/markdown.pipe';
import { GenerateUrlWithProtocolPipe } from './generate-url-with-protocol/generate-url-with-protocol.pipe';

@NgModule({
declarations: [FormatDistancePipe, RoundUpPipe, MarkdownPipe],
exports: [FormatDistancePipe, RoundUpPipe, MarkdownPipe],
declarations: [
FormatDistancePipe,
RoundUpPipe,
MarkdownPipe,
GenerateUrlWithProtocolPipe,
],
exports: [
FormatDistancePipe,
RoundUpPipe,
MarkdownPipe,
GenerateUrlWithProtocolPipe,
],
})
export class PipesModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h1 class="mt-2">
></hero-icon>
<a
class="link"
[href]="user.websiteUrl"
[href]="user.websiteUrl | generateUrlWithProtocol"
target="_blank"
rel="noreferrer"
>
Expand All @@ -88,7 +88,7 @@ <h1 class="mt-2">
></sd-twitter-icon>
<a
class="link"
[href]="'https:/twitter.com/' + user.twitterUsername"
[href]="'https://twitter.com/' + user.twitterUsername"
target="_blank"
rel="noreferrer"
>
Expand Down
2 changes: 2 additions & 0 deletions angular-apollo-tailwind/src/app/profile/profile.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ProfileRepoListItemComponent,
ProfileRepoListItemSkeletonComponent,
} from './components';
import { PipesModule } from '@shared';

@NgModule({
declarations: [
Expand Down Expand Up @@ -50,6 +51,7 @@ import {
ReactiveFormsModule,
ReposFilterDropdownModule,
PaginationModule,
PipesModule,
],
})
export class ProfileModule {}

0 comments on commit eca9db2

Please sign in to comment.