|
1 | 1 | /* eslint-env mocha */
|
2 | 2 | import expect from "expect"
|
3 | 3 | import { fromJS } from "immutable"
|
4 |
| -import { mapToList, validateNumber, validateInteger, validateParam, validateFile, fromJSOrdered } from "core/utils" |
| 4 | +import { mapToList, validateNumber, validateInteger, validateParam, validateFile, fromJSOrdered, createDeepLinkPath, escapeDeepLinkPath } from "core/utils" |
5 | 5 | import win from "core/window"
|
6 | 6 |
|
7 | 7 | describe("utils", function() {
|
@@ -581,5 +581,55 @@ describe("utils", function() {
|
581 | 581 | const result = fromJSOrdered(param).toJS()
|
582 | 582 | expect( result ).toEqual( [1, 1, 2, 3, 5, 8] )
|
583 | 583 | })
|
| 584 | + }) |
| 585 | + |
| 586 | + describe("createDeepLinkPath", function() { |
| 587 | + it("creates a deep link path replacing spaces with underscores", function() { |
| 588 | + const result = createDeepLinkPath("tag id with spaces") |
| 589 | + expect(result).toEqual("tag_id_with_spaces") |
| 590 | + }) |
| 591 | + |
| 592 | + it("trims input when creating a deep link path", function() { |
| 593 | + let result = createDeepLinkPath(" spaces before and after ") |
| 594 | + expect(result).toEqual("spaces_before_and_after") |
| 595 | + |
| 596 | + result = createDeepLinkPath(" ") |
| 597 | + expect(result).toEqual("") |
584 | 598 | })
|
| 599 | + |
| 600 | + it("creates a deep link path with special characters", function() { |
| 601 | + const result = createDeepLinkPath("!@#$%^&*(){}[]") |
| 602 | + expect(result).toEqual("!@#$%^&*(){}[]") |
| 603 | + }) |
| 604 | + |
| 605 | + it("returns an empty string for invalid input", function() { |
| 606 | + expect( createDeepLinkPath(null) ).toEqual("") |
| 607 | + expect( createDeepLinkPath(undefined) ).toEqual("") |
| 608 | + expect( createDeepLinkPath(1) ).toEqual("") |
| 609 | + expect( createDeepLinkPath([]) ).toEqual("") |
| 610 | + expect( createDeepLinkPath({}) ).toEqual("") |
| 611 | + }) |
| 612 | + }) |
| 613 | + |
| 614 | + describe("escapeDeepLinkPath", function() { |
| 615 | + it("creates and escapes a deep link path", function() { |
| 616 | + const result = escapeDeepLinkPath("tag id with spaces?") |
| 617 | + expect(result).toEqual("tag_id_with_spaces\\?") |
| 618 | + }) |
| 619 | + |
| 620 | + it("escapes a deep link path that starts with a number", function() { |
| 621 | + const result = escapeDeepLinkPath("123") |
| 622 | + expect(result).toEqual("\\31 23") |
| 623 | + }) |
| 624 | + |
| 625 | + it("escapes a deep link path with a class selector", function() { |
| 626 | + const result = escapeDeepLinkPath("hello.world") |
| 627 | + expect(result).toEqual("hello\\.world") |
| 628 | + }) |
| 629 | + |
| 630 | + it("escapes a deep link path with an id selector", function() { |
| 631 | + const result = escapeDeepLinkPath("hello#world") |
| 632 | + expect(result).toEqual("hello\\#world") |
| 633 | + }) |
| 634 | + }) |
585 | 635 | })
|
0 commit comments