PromucFlow_constructor/app/client/src/RouteBuilder.test.ts
Rimil Dey a91c5e94a3
fix: Encode query params in URLs (#22594)
## Description

URLs created from `navigateTo()` having query params that were
non-string values or special characters were not being displayed in the
URL. To fix this we encoded these values.

Fixes #16918 #12177 


## Media
https://www.loom.com/share/b9a9705770f04172ba1580d4a5b48739

## Type of change

- Bug fix (non-breaking change which fixes an issue)


## How Has This Been Tested?

- Manual
- Jest


### Test Plan


### Issues raised during DP testing


## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
2023-05-03 09:00:27 +05:30

34 lines
975 B
TypeScript

import { getQueryStringfromObject } from "./RouteBuilder";
describe("Route builder", () => {
describe("tests getQueryStringfromObject", () => {
const cases = [
{
index: 0,
input: { id: 0, a: "b&c ltd" },
expected: "?id=0&a=b%26c%20ltd",
},
{ index: 1, input: {}, expected: "" },
{
index: 2,
input: { rando: "রিমিল" },
expected: "?rando=%E0%A6%B0%E0%A6%BF%E0%A6%AE%E0%A6%BF%E0%A6%B2",
},
{
index: 3,
input: { a1: "1234*&^%~`<>:';,./?" },
expected: "?a1=1234*%26%5E%25~%60%3C%3E%3A'%3B%2C.%2F%3F",
},
{ index: 4, input: { isSignedIn: false }, expected: "?isSignedIn=false" },
];
test.each(cases.map((x) => [x.index, x.input, x.expected]))(
"test case %d",
(_, input, expected) => {
const result = getQueryStringfromObject(input as any);
expect(result).toStrictEqual(expected);
},
);
});
});