Skip to content

Commit 13647ea

Browse files
chore(VE-6750/redirection-url-without-query-string-vb): hash routing and query string combined logic and test cases added
1 parent 804e487 commit 13647ea

3 files changed

Lines changed: 98 additions & 6 deletions

File tree

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ fileignoreconfig:
1111
- filename: src/visualBuilder/components/Collab/ThreadPopup/__test__/CommentTextArea.test.tsx
1212
checksum: d0ef271ee5381d9feab06bda6e7e89bd0a882fee87495627bd811c1f0a5459c7
1313
- filename: src/visualBuilder/utils/__test__/getVisualBuilderRedirectionUrl.test.ts
14-
checksum: 5a4ec2ca7f5cc6342b1d74c954637f6bab0b4a55f46696ea0a7f57f7f4b16457
14+
checksum: c50dc0a34b3aeb8ff50ac36af38e4ace9b6ee137522faa3d82ae2309ee285040
1515
version: "1.0"

src/visualBuilder/utils/__test__/getVisualBuilderRedirectionUrl.test.ts

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe("getVisualBuilderRedirectionUrl", () => {
2828

2929
const result = getVisualBuilderRedirectionUrl();
3030
expect(result.toString()).toBe(
31-
"https://app.example.com/#!/stack/12345/visual-builder?branch=main&environment=production&target-url=https%3A%2F%2Fexample.com%2F&locale=en-US"
31+
"https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com&branch=main&environment=production&locale=en-US"
3232
);
3333
});
3434

@@ -47,7 +47,7 @@ describe("getVisualBuilderRedirectionUrl", () => {
4747

4848
const result = getVisualBuilderRedirectionUrl();
4949
expect(result.toString()).toBe(
50-
"https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com%2F&locale=en-US"
50+
"https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com&locale=en-US"
5151
);
5252
});
5353

@@ -69,7 +69,7 @@ describe("getVisualBuilderRedirectionUrl", () => {
6969

7070
const result = getVisualBuilderRedirectionUrl();
7171
expect(result.toString()).toBe(
72-
"https://app.example.com/#!/stack/12345/visual-builder?branch=main&environment=production&target-url=https%3A%2F%2Fexample.com%2F&locale=fr-FR"
72+
"https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com&branch=main&environment=production&locale=fr-FR"
7373
);
7474
});
7575

@@ -89,7 +89,7 @@ describe("getVisualBuilderRedirectionUrl", () => {
8989

9090
const result = getVisualBuilderRedirectionUrl();
9191
expect(result.toString()).toBe(
92-
"https://app.example.com/#!/stack/12345/visual-builder?branch=main&environment=production&target-url=https%3A%2F%2Fexample.com%2F"
92+
"https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com&branch=main&environment=production"
9393
);
9494
});
9595

@@ -117,4 +117,94 @@ describe("getVisualBuilderRedirectionUrl", () => {
117117
);
118118
expect(result.toString()).not.toContain("?query=test");
119119
});
120+
it("should return the correct URL with slash type hash routing", () => {
121+
Object.defineProperty(window, "location", {
122+
writable: true,
123+
value: new URL("https://example.com/#/page"),
124+
});
125+
Config.get.mockReturnValue({
126+
stackDetails: {
127+
branch: "main",
128+
apiKey: "12345",
129+
environment: "production",
130+
locale: "en-US",
131+
},
132+
clientUrlParams: {
133+
url: "https://app.example.com",
134+
},
135+
});
136+
137+
const result = getVisualBuilderRedirectionUrl();
138+
expect(result.toString()).toBe(
139+
"https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com%2Fpage&branch=main&environment=production&locale=en-US"
140+
);
141+
});
142+
143+
it("should return the correct URL with no slash type hash routing", () => {
144+
Object.defineProperty(window, "location", {
145+
writable: true,
146+
value: new URL("https://example.com/#page"),
147+
});
148+
Config.get.mockReturnValue({
149+
stackDetails: {
150+
branch: "main",
151+
apiKey: "12345",
152+
environment: "production",
153+
locale: "en-US",
154+
},
155+
clientUrlParams: {
156+
url: "https://app.example.com",
157+
},
158+
});
159+
160+
const result = getVisualBuilderRedirectionUrl();
161+
expect(result.toString()).toBe(
162+
"https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com%2Fpage&branch=main&environment=production&locale=en-US"
163+
);
164+
});
165+
it("should return the correct URL with hash bang type hash routing", () => {
166+
Object.defineProperty(window, "location", {
167+
writable: true,
168+
value: new URL("https://example.com/#!/page"),
169+
});
170+
Config.get.mockReturnValue({
171+
stackDetails: {
172+
branch: "main",
173+
apiKey: "12345",
174+
environment: "production",
175+
locale: "en-US",
176+
},
177+
clientUrlParams: {
178+
url: "https://app.example.com",
179+
},
180+
});
181+
182+
const result = getVisualBuilderRedirectionUrl();
183+
expect(result.toString()).toBe(
184+
"https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com%2Fpage&branch=main&environment=production&locale=en-US"
185+
);
186+
});
187+
188+
it("should return the correct URL with hash bang type hash routing", () => {
189+
Object.defineProperty(window, "location", {
190+
writable: true,
191+
value: new URL("https://example.com/#!/page?query=test"),
192+
});
193+
Config.get.mockReturnValue({
194+
stackDetails: {
195+
branch: "main",
196+
apiKey: "12345",
197+
environment: "production",
198+
locale: "en-US",
199+
},
200+
clientUrlParams: {
201+
url: "https://app.example.com",
202+
},
203+
});
204+
205+
const result = getVisualBuilderRedirectionUrl();
206+
expect(result.toString()).toBe(
207+
"https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com%2Fpage&branch=main&environment=production&locale=en-US"
208+
);
209+
});
120210
});

src/visualBuilder/utils/getVisualBuilderRedirectionUrl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export default function getVisualBuilderRedirectionUrl(): URL {
3131
} else {
3232
pathFromHash = "/" + hash.substring(1);
3333
}
34-
url.pathname = (url.pathname + pathFromHash).replace(/\/\//g, "/");
34+
// remove query parameters from the path if we have both hash routing and query string
35+
let onlyPathname = pathFromHash.split("?")[0];
36+
url.pathname = (url.pathname + onlyPathname).replace(/\/\//g, "/");
3537
url.hash = "";
3638
} else {
3739
url.hash = "";

0 commit comments

Comments
 (0)