|
1 | 1 | /* eslint-env mocha */ |
2 | 2 | import expect from "expect" |
3 | 3 | 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 | + |
6 | 6 |
|
7 | 7 | describe("utils", function() { |
8 | 8 |
|
@@ -679,4 +679,54 @@ describe("utils", function() { |
679 | 679 | expect(getAcceptControllingResponse(responses)).toBe(null) |
680 | 680 | }) |
681 | 681 | }) |
| 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 | + }) |
682 | 732 | }) |
0 commit comments