@@ -10,6 +10,16 @@ const ENV_DATA_WITH_HASH = {
10
10
hostRootUrl : "https://example.com/root/#/" ,
11
11
} ;
12
12
13
+ const ENV_DATA_WITH_QUERY = {
14
+ ...ENV_DATA ,
15
+ hostRootUrl : "https://example.com/root/?foo=bar" ,
16
+ } ;
17
+
18
+ const ENV_DATA_WITH_QUERY_AND_HASH = {
19
+ ...ENV_DATA ,
20
+ hostRootUrl : "https://example.com/root/?foo=bar#/" ,
21
+ } ;
22
+
13
23
describe ( "The frame router element" , ( ) => {
14
24
beforeAll ( ( ) => {
15
25
window . customElements . define ( "frame-router" , FrameRouterElement ) ;
@@ -25,7 +35,7 @@ describe("The frame router element", () => {
25
35
* behavior.
26
36
*/
27
37
describe ( "Host URL management" , ( ) => {
28
- it ( "Removes a trailing slash on the host URL if present" , ( ) => {
38
+ it ( "Removes a trailing slash on the host URL if present with no hash " , ( ) => {
29
39
const router = new FrameRouterElement ( ) ;
30
40
router . clientConfig = {
31
41
clients : { } ,
@@ -65,6 +75,43 @@ describe("The frame router element", () => {
65
75
} ) ;
66
76
} ) ;
67
77
68
- // TODO: Test expected query behavior here
78
+ it ( "Removes trailing slash from pathname when the provided host URL with query params; urlObject and location have no hash" , ( ) => {
79
+ const router = new FrameRouterElement ( ) ;
80
+ router . clientConfig = {
81
+ clients : { } ,
82
+ envData : ENV_DATA_WITH_QUERY ,
83
+ } ;
84
+ //@ts -ignore
85
+ expect ( router . _envData ) . toEqual ( {
86
+ ...ENV_DATA_WITH_QUERY ,
87
+ hostRootUrl : "https://example.com/root?foo=bar" ,
88
+ } ) ;
89
+ } ) ;
90
+
91
+ it ( "Does not add slash between hash and query params if location has hash; urlObject has no hash" , ( ) => {
92
+ window . location . hash = "foo" ;
93
+ const router = new FrameRouterElement ( ) ;
94
+ router . clientConfig = {
95
+ clients : { } ,
96
+ envData : ENV_DATA_WITH_QUERY ,
97
+ } ;
98
+ //@ts -ignore
99
+ expect ( router . _envData ) . toEqual ( {
100
+ ...ENV_DATA_WITH_QUERY ,
101
+ hostRootUrl : "https://example.com/root/?foo=bar#" ,
102
+ } ) ;
103
+ } ) ;
104
+
105
+ it ( "Does not modify provided host URL with query params if urlObject has hash; location hash N/A" , ( ) => {
106
+ const router = new FrameRouterElement ( ) ;
107
+ router . clientConfig = {
108
+ clients : { } ,
109
+ envData : ENV_DATA_WITH_QUERY_AND_HASH ,
110
+ } ;
111
+ //@ts -ignore
112
+ expect ( router . _envData ) . toEqual ( {
113
+ ...ENV_DATA_WITH_QUERY_AND_HASH ,
114
+ } ) ;
115
+ } ) ;
69
116
} ) ;
70
117
} ) ;
0 commit comments