-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve path.replace to replace segments and provide uriToString for …
…Path and Query
- Loading branch information
Showing
8 changed files
with
160 additions
and
56 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
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
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 |
---|---|---|
|
@@ -43,19 +43,41 @@ describe('Uri', () => { | |
expect(uri.path.replace('different/path/to/file.json').toString()).toEqual('different/path/to/file.json'); | ||
}); | ||
|
||
it('should remove the file part of the path', () => { | ||
it('should replace the file part of the path', () => { | ||
let url = 'https://user:[email protected]/path/to/file.xml'; | ||
let uri = new Uri(url); | ||
|
||
expect(uri.path.removeFilename().toString()).toEqual('path/to'); | ||
expect(uri.path.replace('file.json', 'file').toString()).toEqual('path/to/file.json'); | ||
}); | ||
|
||
it('should replace the file part of the path', () => { | ||
it('should remove the last segment of the path', () => { | ||
let url = 'https://user:[email protected]/path/to/file.xml'; | ||
let uri = new Uri(url); | ||
|
||
expect(uri.path.delete().toString()).toEqual('path/to'); | ||
}); | ||
|
||
it('should replace the first segment of the path', () => { | ||
let url = 'https://user:[email protected]/path/to/file.xml'; | ||
let uri = new Uri(url); | ||
|
||
expect(uri.path.replace('new-path', 0).toString()).toEqual('new-path/to/file.xml'); | ||
}); | ||
|
||
it('should replace the second segment of the path', () => { | ||
let url = 'https://user:[email protected]/path/to/file.xml'; | ||
let uri = new Uri(url); | ||
|
||
expect(uri.path.replace('new-to', 1).toString()).toEqual('path/new-to/file.xml'); | ||
}); | ||
|
||
it('should return the uri as a string', () => { | ||
let url = 'https://user:[email protected]/path/to/file.xml'; | ||
let uri = new Uri(url); | ||
|
||
expect(uri.path.replaceFilename('goober.json').toString()).toEqual('path/to/goober.json'); | ||
expect(uri.path.replace('new-to', 1).uriToString()).toEqual('https://user:[email protected]/path/new-to/file.xml'); | ||
}); | ||
|
||
}); | ||
|
||
describe('Query', () => { | ||
|
@@ -66,6 +88,12 @@ describe('Uri', () => { | |
expect(uri.query.toString()).toBe('foo=bar'); | ||
}); | ||
|
||
it('should clear to the query string', () => { | ||
let url = 'https://user:[email protected]/path/to/file.xml?context=foo&credentials=bar'; | ||
let uri = new Uri(url); | ||
expect(uri.query.clear().toString()).toBe(''); | ||
}); | ||
|
||
it('should append to the query string', () => { | ||
let url = 'https://user:[email protected]/path/to/file.xml?context=foo&credentials=bar'; | ||
let uri = new Uri(url); | ||
|
@@ -79,6 +107,13 @@ describe('Uri', () => { | |
uri.query.merge({context: 'bar'}); | ||
expect(uri.query.toString()).toBe('context=bar&credentials=bar'); | ||
}); | ||
|
||
it('should, when cleared, return a proper url', () => { | ||
let url = 'https://user:[email protected]/path/to/file.xml?context=foo&credentials=bar'; | ||
let uri = new Uri(url); | ||
uri.query.clear(); | ||
expect(uri.toString()).toEqual('https://user:[email protected]/path/to/file.xml'); | ||
}); | ||
}); | ||
|
||
it('should change the host', () => { | ||
|
@@ -104,9 +139,10 @@ describe('Uri', () => { | |
expect(Array.isArray(uri.path.get())).toEqual(true); | ||
expect(uri.path.toString()).toEqual('path/to/file.xml'); | ||
expect(uri.query).toEqual(jasmine.any(Object)); | ||
expect(uri.query.add({foo: 'bar'}).toString()).toEqual('context=foo&credentials=bar&foo=bar') | ||
expect(uri.query.add({foo: 'bar'}).merge({foo: 'bars'}).toString()).toEqual('context=foo&credentials=bar&foo=bars') | ||
expect(uri.query.clear().add({foo: 'bar'}).merge({foo: 'bars'}).toString()).toEqual('foo=bars') | ||
expect(uri.query.add({foo: 'bar'}).toString()).toEqual('context=foo&credentials=bar&foo=bar'); | ||
expect(uri.query.add({foo: 'bar'}).merge({foo: 'bars'}).toString()).toEqual('context=foo&credentials=bar&foo=bars'); | ||
expect(uri.query.clear().add({foo: 'bar'}).merge({foo: 'bars'}).toString()).toEqual('foo=bars'); | ||
expect(uri.query.clear().add({foo: 'bar'}).merge({foo: 'bars'}).uriToString()).toEqual('https://user:[email protected]/path/to/file.xml?foo=bars'); | ||
}); | ||
|
||
}); |
Oops, something went wrong.