This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contact-page-redesign): Add utility and unit test.
- Loading branch information
Showing
3 changed files
with
48 additions
and
11 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
packages/app/src/utils/__tests__/format-link-according-to-type.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,34 @@ | ||
import { suite } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
import { formatLinkAccordingToType } from '../format-link-according-to-type'; | ||
|
||
const FormatLinkAccordingToType = suite('formatLinkAccordingToType'); | ||
|
||
FormatLinkAccordingToType('should not do anything to a regular link', () => { | ||
const linkType = 'regular'; | ||
const href = '/'; | ||
|
||
const result = formatLinkAccordingToType(href, linkType); | ||
|
||
assert.is(result, '/'); | ||
}); | ||
|
||
FormatLinkAccordingToType('should format as a telephone link', () => { | ||
const linkType = 'phone'; | ||
const href = '123-456-789'; | ||
|
||
const result = formatLinkAccordingToType(href, linkType); | ||
|
||
assert.is(result, 'tel:123456789'); | ||
}); | ||
|
||
FormatLinkAccordingToType('should format as a email link', () => { | ||
const linkType = 'email'; | ||
const href = '[email protected]'; | ||
|
||
const result = formatLinkAccordingToType(href, linkType); | ||
|
||
assert.is(result, 'mailto:[email protected]'); | ||
}); | ||
|
||
FormatLinkAccordingToType.run(); |
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,13 @@ | ||
/** | ||
* Returns a formatted link based on the link type of email, phone, regular | ||
*/ | ||
export const formatLinkAccordingToType = (href: string, linkType: string | undefined) => { | ||
switch (linkType) { | ||
case 'email': | ||
return `mailto:${href}`; | ||
case 'phone': | ||
return `tel:${href.replace(/\s/g, '').replaceAll('-', '')}`; | ||
default: | ||
return href; | ||
} | ||
}; |