Fix deeplinking for topbar plugin (#4181)

* Fix deeplinking for topbar plugin

* Lint & added tests for search parsing/serialization
This commit is contained in:
Grégoire Charvet 黑瓜
2018-02-27 06:46:18 +01:00
committed by kyle
parent e41067b4c1
commit 71d7c1a5ab
3 changed files with 59 additions and 1 deletions

View File

@@ -3,6 +3,8 @@ import expect from "expect"
import { fromJS, OrderedMap } from "immutable"
import {
mapToList,
parseSearch,
serializeSearch,
validatePattern,
validateMinLength,
validateMaxLength,
@@ -940,6 +942,48 @@ describe("utils", function() {
})
})
describe("parse and serialize search", function() {
afterEach(function() {
win.location.search = ""
})
describe("parsing", function() {
it("works with empty search", function() {
win.location.search = ""
expect(parseSearch()).toEqual({})
})
it("works with only one key", function() {
win.location.search = "?foo"
expect(parseSearch()).toEqual({foo: ""})
})
it("works with keys and values", function() {
win.location.search = "?foo=fooval&bar&baz=bazval"
expect(parseSearch()).toEqual({foo: "fooval", bar: "", baz: "bazval"})
})
it("decode url encoded components", function() {
win.location.search = "?foo=foo%20bar"
expect(parseSearch()).toEqual({foo: "foo bar"})
})
})
describe("serializing", function() {
it("works with empty map", function() {
expect(serializeSearch({})).toEqual("")
})
it("works with multiple keys with and without values", function() {
expect(serializeSearch({foo: "", bar: "barval"})).toEqual("foo=&bar=barval")
})
it("encode url components", function() {
expect(serializeSearch({foo: "foo bar"})).toEqual("foo=foo%20bar")
})
})
})
describe("sanitizeUrl", function() {
it("should sanitize a `javascript:` url", function() {
const res = sanitizeUrl("javascript:alert('bam!')")