PromucFlow_constructor/app/client/src/constants/routes.test.ts
Abhijeet 989cd8ed67
chore: Unify ID extraction regex from browser url (#33925)
## Description
Regex update to make it compatible to extract identifiers for both Mongo
ObjectIds and UUIDs. This will help us to keep the unified logic
required in `pg` branch.

## Automation

/ok-to-test tags="@tag.Datasource, @tag.GenerateCRUD, @tag.ImportExport,
@tag.Fork, @tag.Workspace, @tag.Sanity"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9405554200>
> Commit: 3959703aab1d10e28d3b80057793476467126929
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9405554200&attempt=2"
target="_blank">Click here!</a>

<!-- end of auto-generated comment: Cypress test results  -->









## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
  - Enhanced URL path handling to support both UUID and Mongo ObjectIds.

- **Refactor**
- Replaced hardcoded page IDs with dynamic variables across multiple
test files for improved maintainability and flexibility.

- **Tests**
- Updated test cases to use dynamic page IDs, ensuring consistency and
easier updates in the future.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-06-11 15:14:54 +05:30

89 lines
2.5 KiB
TypeScript

import urlBuilder from "@appsmith/entities/URLRedirect/URLAssembly";
import { builderURL, viewerURL } from "@appsmith/RouteBuilder";
describe("builderURL", () => {
let location: typeof window.location;
beforeAll(() => {
location = window.location;
delete (window as any).location;
urlBuilder.updateURLParams(
{
applicationSlug: ":applicationSlug",
applicationId: ":applicationId",
applicationVersion: 2,
},
[
{
pageId: "0123456789abcdef00000000",
pageSlug: ":pageSlug",
},
],
);
});
it("persists embed query param", () => {
(window as any).location = new URL("https://example.com?embed=true");
const pageURL = builderURL({
pageId: "0123456789abcdef00000000",
});
const pageURLObject = new URL(`${window.origin}${pageURL}`);
expect(pageURLObject.searchParams.get("embed")).toBe("true");
});
it("does not append embed query param when it does not exist", () => {
(window as any).location = new URL("https://example.com");
const pageURL = builderURL({
pageId: "0123456789abcdef00000000",
});
const pageURLObject = new URL(`${window.origin}${pageURL}`);
expect(pageURLObject.searchParams.get("embed")).toBe(null);
});
afterAll(() => {
window.location = location;
jest.clearAllMocks();
});
});
describe("viewerURL", () => {
let location: typeof window.location;
beforeAll(() => {
location = window.location;
urlBuilder.updateURLParams(
{
applicationSlug: ":applicationSlug",
applicationId: ":applicationId",
applicationVersion: 2,
},
[
{
pageId: "0123456789abcdef00000000",
pageSlug: ":pageSlug",
},
],
);
});
it("persists embed query param", () => {
(window as any).location = new URL("https://example.com?embed=true");
const pageURL = viewerURL({
pageId: "0123456789abcdef00000000",
});
const pageURLObject = new URL(`${window.origin}${pageURL}`);
expect(pageURLObject.searchParams.get("embed")).toBe("true");
});
it("does not append embed query param when it does not exist", () => {
(window as any).location = new URL("https://example.com");
const pageURL = viewerURL({
pageId: "0123456789abcdef00000000",
});
const pageURLObject = new URL(`${window.origin}${pageURL}`);
expect(pageURLObject.searchParams.get("embed")).toBe(null);
});
afterAll(() => {
window.location = location;
});
});