2022-10-17 15:16:38 +00:00
|
|
|
import { identifyEntityFromPath, FocusEntity } from "navigation/FocusEntity";
|
2023-11-30 09:26:24 +00:00
|
|
|
import { EditorState } from "../entities/IDE/constants";
|
2022-10-17 15:16:38 +00:00
|
|
|
|
|
|
|
|
describe("identifyEntityFromPath", () => {
|
|
|
|
|
const oldUrlCases = [
|
|
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit",
|
2023-11-20 07:58:08 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.CANVAS,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-20 07:58:08 +00:00
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
2023-02-21 13:38:16 +00:00
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/widgets/ryvc8i7oja",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.PROPERTY_PANE,
|
2023-02-21 13:38:16 +00:00
|
|
|
id: "ryvc8i7oja",
|
2022-12-08 07:21:58 +00:00
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2022-12-08 07:21:58 +00:00
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/queries",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.QUERY_LIST,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/api/myApiId",
|
2023-11-20 07:58:08 +00:00
|
|
|
expected: {
|
2023-11-28 12:46:43 +00:00
|
|
|
entity: FocusEntity.QUERY,
|
2023-11-20 07:58:08 +00:00
|
|
|
id: "myApiId",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-20 07:58:08 +00:00
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/queries/myQueryId",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.QUERY,
|
|
|
|
|
id: "myQueryId",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2022-12-08 07:21:58 +00:00
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/jsObjects",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.JS_OBJECT_LIST,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/jsObjects/myJSId",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.JS_OBJECT,
|
|
|
|
|
id: "myJSId",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/datasource",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.DATASOURCE_LIST,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/datasources/myDatasourceId",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.DATASOURCE,
|
|
|
|
|
id: "myDatasourceId",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
];
|
|
|
|
|
const pageSlugCases = [
|
|
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit",
|
2023-11-20 07:58:08 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.CANVAS,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-20 07:58:08 +00:00
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
2023-02-21 13:38:16 +00:00
|
|
|
path: "/app/myAppId/page1-myPageId/edit/widgets/ryvc8i7oja",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.PROPERTY_PANE,
|
2023-02-21 13:38:16 +00:00
|
|
|
id: "ryvc8i7oja",
|
2022-12-08 07:21:58 +00:00
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2022-12-08 07:21:58 +00:00
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit/queries",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.QUERY_LIST,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit/api/myApiId",
|
2023-11-20 07:58:08 +00:00
|
|
|
expected: {
|
2023-11-28 12:46:43 +00:00
|
|
|
entity: FocusEntity.QUERY,
|
2023-11-20 07:58:08 +00:00
|
|
|
id: "myApiId",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-20 07:58:08 +00:00
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit/queries/myQueryId",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.QUERY,
|
|
|
|
|
id: "myQueryId",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2022-12-08 07:21:58 +00:00
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit/jsObjects",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.JS_OBJECT_LIST,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit/jsObjects/myJSId",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.JS_OBJECT,
|
|
|
|
|
id: "myJSId",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit/datasource",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.DATASOURCE_LIST,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit/datasources/myDatasourceId",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.DATASOURCE,
|
|
|
|
|
id: "myDatasourceId",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
];
|
|
|
|
|
const customSlugCases = [
|
|
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit",
|
2023-11-20 07:58:08 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.CANVAS,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-20 07:58:08 +00:00
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
2023-02-21 13:38:16 +00:00
|
|
|
path: "/app/myCustomSlug-myPageId/edit/widgets/ryvc8i7oja",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.PROPERTY_PANE,
|
2023-02-21 13:38:16 +00:00
|
|
|
id: "ryvc8i7oja",
|
2022-12-08 07:21:58 +00:00
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2022-12-08 07:21:58 +00:00
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit/queries",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.QUERY_LIST,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit/api/myApiId",
|
2023-11-20 07:58:08 +00:00
|
|
|
expected: {
|
2023-11-28 12:46:43 +00:00
|
|
|
entity: FocusEntity.QUERY,
|
2023-11-20 07:58:08 +00:00
|
|
|
id: "myApiId",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-20 07:58:08 +00:00
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit/queries/myQueryId",
|
2022-12-08 07:21:58 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.QUERY,
|
|
|
|
|
id: "myQueryId",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2022-12-08 07:21:58 +00:00
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit/jsObjects",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.JS_OBJECT_LIST,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit/jsObjects/myJSId",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.JS_OBJECT,
|
|
|
|
|
id: "myJSId",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit/datasource",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.DATASOURCE_LIST,
|
|
|
|
|
id: "",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit/datasources/myDatasourceId",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.DATASOURCE,
|
|
|
|
|
id: "myDatasourceId",
|
|
|
|
|
pageId: "myPageId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const cases = oldUrlCases.concat(pageSlugCases.concat(customSlugCases));
|
|
|
|
|
|
|
|
|
|
it("works", () => {
|
|
|
|
|
for (const testCase of cases) {
|
2023-02-21 13:38:16 +00:00
|
|
|
const actual = identifyEntityFromPath(testCase.path);
|
2022-10-17 15:16:38 +00:00
|
|
|
expect(actual).toStrictEqual(testCase.expected);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|