2022-10-17 15:16:38 +00:00
|
|
|
import { identifyEntityFromPath, FocusEntity } from "navigation/FocusEntity";
|
|
|
|
|
|
|
|
|
|
describe("identifyEntityFromPath", () => {
|
|
|
|
|
const oldUrlCases = [
|
|
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit",
|
|
|
|
|
hash: "",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: { entity: FocusEntity.CANVAS, id: "", pageId: "myPageId" },
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit#ryvc8i7oja",
|
|
|
|
|
hash: "#ryvc8i7oja",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.PROPERTY_PANE,
|
|
|
|
|
id: "#ryvc8i7oja",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/api/myApiId",
|
|
|
|
|
hash: "",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: { entity: FocusEntity.API, id: "myApiId", pageId: "myPageId" },
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/queries/myQueryId",
|
|
|
|
|
hash: "",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.QUERY,
|
|
|
|
|
id: "myQueryId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
const pageSlugCases = [
|
|
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit",
|
|
|
|
|
hash: "",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: { entity: FocusEntity.CANVAS, id: "", pageId: "myPageId" },
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/myAppId/page1-myPageId/edit#ryvc8i7oja",
|
|
|
|
|
hash: "#ryvc8i7oja",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.PROPERTY_PANE,
|
|
|
|
|
id: "#ryvc8i7oja",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit/api/myApiId",
|
|
|
|
|
hash: "",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: { entity: FocusEntity.API, id: "myApiId", pageId: "myPageId" },
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit/queries/myQueryId",
|
|
|
|
|
hash: "",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.QUERY,
|
|
|
|
|
id: "myQueryId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
const customSlugCases = [
|
|
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit",
|
|
|
|
|
hash: "",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: { entity: FocusEntity.CANVAS, id: "", pageId: "myPageId" },
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit#ryvc8i7oja",
|
|
|
|
|
hash: "#ryvc8i7oja",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.PROPERTY_PANE,
|
|
|
|
|
id: "#ryvc8i7oja",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit/api/myApiId",
|
|
|
|
|
hash: "",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: { entity: FocusEntity.API, id: "myApiId", pageId: "myPageId" },
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit/queries/myQueryId",
|
|
|
|
|
hash: "",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.QUERY,
|
|
|
|
|
id: "myQueryId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const cases = oldUrlCases.concat(pageSlugCases.concat(customSlugCases));
|
|
|
|
|
|
|
|
|
|
it("works", () => {
|
|
|
|
|
for (const testCase of cases) {
|
|
|
|
|
const actual = identifyEntityFromPath(testCase.path, testCase.hash);
|
|
|
|
|
expect(actual).toStrictEqual(testCase.expected);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|