Skip to content

Commit bd54243

Browse files
authored
Merge branch 'master' into bug/oas3-accept-controls
2 parents ef8b37a + ef5904f commit bd54243

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

test/core/utils.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-env mocha */
22
import expect from "expect"
33
import { fromJS, OrderedMap } from "immutable"
4-
import { mapToList, validateNumber, validateInteger, validateParam, validateFile, fromJSOrdered, getAcceptControllingResponse } from "core/utils"
5-
import win from "core/window"
4+
import { mapToList, validateNumber, validateInteger, validateParam, validateFile, fromJSOrdered, getAcceptControllingResponse, createDeepLinkPath, escapeDeepLinkPath } from "core/utils"
5+
66

77
describe("utils", function() {
88

@@ -679,4 +679,54 @@ describe("utils", function() {
679679
expect(getAcceptControllingResponse(responses)).toBe(null)
680680
})
681681
})
682+
683+
describe("createDeepLinkPath", function() {
684+
it("creates a deep link path replacing spaces with underscores", function() {
685+
const result = createDeepLinkPath("tag id with spaces")
686+
expect(result).toEqual("tag_id_with_spaces")
687+
})
688+
689+
it("trims input when creating a deep link path", function() {
690+
let result = createDeepLinkPath(" spaces before and after ")
691+
expect(result).toEqual("spaces_before_and_after")
692+
693+
result = createDeepLinkPath(" ")
694+
expect(result).toEqual("")
695+
})
696+
697+
it("creates a deep link path with special characters", function() {
698+
const result = createDeepLinkPath("!@#$%^&*(){}[]")
699+
expect(result).toEqual("!@#$%^&*(){}[]")
700+
})
701+
702+
it("returns an empty string for invalid input", function() {
703+
expect( createDeepLinkPath(null) ).toEqual("")
704+
expect( createDeepLinkPath(undefined) ).toEqual("")
705+
expect( createDeepLinkPath(1) ).toEqual("")
706+
expect( createDeepLinkPath([]) ).toEqual("")
707+
expect( createDeepLinkPath({}) ).toEqual("")
708+
})
709+
})
710+
711+
describe("escapeDeepLinkPath", function() {
712+
it("creates and escapes a deep link path", function() {
713+
const result = escapeDeepLinkPath("tag id with spaces?")
714+
expect(result).toEqual("tag_id_with_spaces\\?")
715+
})
716+
717+
it("escapes a deep link path that starts with a number", function() {
718+
const result = escapeDeepLinkPath("123")
719+
expect(result).toEqual("\\31 23")
720+
})
721+
722+
it("escapes a deep link path with a class selector", function() {
723+
const result = escapeDeepLinkPath("hello.world")
724+
expect(result).toEqual("hello\\.world")
725+
})
726+
727+
it("escapes a deep link path with an id selector", function() {
728+
const result = escapeDeepLinkPath("hello#world")
729+
expect(result).toEqual("hello\\#world")
730+
})
731+
})
682732
})

0 commit comments

Comments
 (0)