-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(WinterCG): URL & URLSearchParams (#1801)
- Loading branch information
Showing
13 changed files
with
24,190 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
describe("Test URL ", function () { | ||
|
||
it("Test invalid URL parsing", function(){ | ||
var exceptionCaught = false; | ||
try { | ||
const url = new URL(''); | ||
}catch(e){ | ||
exceptionCaught = true; | ||
} | ||
expect(exceptionCaught).toBe(true); | ||
}); | ||
|
||
it("Test valid URL parsing", function(){ | ||
var exceptionCaught = false; | ||
try { | ||
const url = new URL('https://google.com'); | ||
}catch(e){ | ||
exceptionCaught = true; | ||
} | ||
expect(exceptionCaught).toBe(false); | ||
}); | ||
|
||
|
||
it("Test URL fields", function(){ | ||
var exceptionCaught = false; | ||
const url = new URL('https://google.com'); | ||
expect(url.protocol).toBe('https:'); | ||
expect(url.hostname).toBe('google.com'); | ||
}); | ||
|
||
}); |
64 changes: 64 additions & 0 deletions
64
test-app/app/src/main/assets/app/tests/testURLSearchParamsImpl.js
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,64 @@ | ||
describe("Test URLSearchParams ", function () { | ||
const fooBar = "foo=1&bar=2"; | ||
it("Test URLSearchParams keys", function(){ | ||
const params = new URLSearchParams(fooBar); | ||
const keys = params.keys(); | ||
expect(keys[0]).toBe("foo"); | ||
expect(keys[1]).toBe("bar"); | ||
}); | ||
|
||
it("Test URLSearchParams values", function(){ | ||
const params = new URLSearchParams(fooBar); | ||
const values = params.values(); | ||
expect(values[0]).toBe("1"); | ||
expect(values[1]).toBe("2"); | ||
}); | ||
|
||
|
||
it("Test URLSearchParams entries", function(){ | ||
const params = new URLSearchParams(fooBar); | ||
const entries = params.entries(); | ||
expect(entries[0][0]).toBe("foo"); | ||
expect(entries[0][1]).toBe("1"); | ||
|
||
expect(entries[1][0]).toBe("bar"); | ||
expect(entries[1][1]).toBe("2"); | ||
|
||
}); | ||
|
||
|
||
it("Test URLSearchParams size", function(){ | ||
const params = new URLSearchParams(fooBar); | ||
expect(params.size).toBe(2); | ||
}); | ||
|
||
it("Test URLSearchParams append", function(){ | ||
const params = new URLSearchParams(fooBar); | ||
params.append("first", "Osei"); | ||
expect(params.get("first")).toBe("Osei"); | ||
}); | ||
|
||
|
||
it("Test URLSearchParams delete", function(){ | ||
const params = new URLSearchParams(fooBar); | ||
params.append("first", "Osei"); | ||
params.delete("first"); | ||
expect(params.get("first")).toBe(undefined); | ||
}); | ||
|
||
|
||
it("Test URLSearchParams has", function(){ | ||
const params = new URLSearchParams(fooBar); | ||
expect(params.has("foo")).toBe(true); | ||
}); | ||
|
||
it("Test URLSearchParams changes propagates to URL parent", function(){ | ||
const toBe = 'https://github.com/triniwiz?first=Osei'; | ||
const url = new URL('https://github.com/triniwiz'); | ||
const params = url.searchParams; | ||
console.log(params); | ||
params.set('first', 'Osei'); | ||
expect(url.toString()).toBe(toBe); | ||
}); | ||
|
||
}); |
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
Oops, something went wrong.