-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): CHECKOUT-3747 Configure instance with host URL
- Loading branch information
Showing
6 changed files
with
75 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import FormBuilder from './form-builder'; | ||
import FormPoster from './form-poster'; | ||
import FormPosterOptions from './form-poster-options'; | ||
|
||
export default function createFormPoster(): FormPoster { | ||
export default function createFormPoster(options?: FormPosterOptions): FormPoster { | ||
const formBuilder = new FormBuilder(); | ||
const formPoster = new FormPoster(formBuilder); | ||
const formPoster = new FormPoster(formBuilder, options); | ||
|
||
return formPoster; | ||
} |
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,3 @@ | ||
export default interface FormPosterOptions { | ||
host?: string; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function isAbsoluteUrl(url: string): boolean { | ||
return /^https?:\/\//.test(url); | ||
} | ||
|
||
export function joinPaths(pathA: string, pathB: string): string { | ||
return `${removeTrailingSlash(pathA)}/${removeLeadingSlash(pathB)}`; | ||
} | ||
|
||
function removeTrailingSlash(path: string): string { | ||
return path.replace(/\/$/, ''); | ||
} | ||
|
||
function removeLeadingSlash(path: string): string { | ||
return path.replace(/^\//, ''); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { isAbsoluteUrl, joinPaths } from '../src/url-utils'; | ||
|
||
describe('isAbsoluteUrl()', () => { | ||
it('returns true if absolute URL', () => { | ||
expect(isAbsoluteUrl('https://foobar.com/hello/world')) | ||
.toBeTruthy(); | ||
|
||
expect(isAbsoluteUrl('http://foobar.com/hello/world')) | ||
.toBeTruthy(); | ||
}); | ||
|
||
it('returns false if relative URL', () => { | ||
expect(isAbsoluteUrl('/hello/world')) | ||
.toBeFalsy(); | ||
|
||
expect(isAbsoluteUrl('/')) | ||
.toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('joinPaths()', () => { | ||
it('joins two paths together', () => { | ||
expect(joinPaths('https://foobar.com', 'hello/world')) | ||
.toEqual('https://foobar.com/hello/world'); | ||
}); | ||
|
||
it('strips out trailing and leading slashes automatically', () => { | ||
expect(joinPaths('https://foobar.com/', '/hello/world')) | ||
.toEqual('https://foobar.com/hello/world'); | ||
}); | ||
}); |