2024-01-08 05:39:47 +00:00
|
|
|
import type { FocusEntityInfo } from "navigation/FocusEntity";
|
|
|
|
|
import { FocusEntity, identifyEntityFromPath } from "navigation/FocusEntity";
|
|
|
|
|
import { EditorState } from "@appsmith/entities/IDE/constants";
|
|
|
|
|
|
|
|
|
|
interface TestCase {
|
|
|
|
|
path: string;
|
|
|
|
|
expected: FocusEntityInfo;
|
|
|
|
|
}
|
2022-10-17 15:16:38 +00:00
|
|
|
|
|
|
|
|
describe("identifyEntityFromPath", () => {
|
2024-01-08 05:39:47 +00:00
|
|
|
const oldUrlCases: TestCase[] = [
|
2022-10-17 15:16:38 +00:00
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit",
|
2023-11-20 07:58:08 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.CANVAS,
|
|
|
|
|
id: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationId: "myAppId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
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",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationId: "myAppId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
widgetIds: "ryvc8i7oja",
|
|
|
|
|
},
|
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: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationId: "myAppId",
|
|
|
|
|
entity: "queries",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
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",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
apiId: "myApiId",
|
|
|
|
|
applicationId: "myAppId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
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",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
queryId: "myQueryId",
|
|
|
|
|
applicationId: "myAppId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
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: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationId: "myAppId",
|
|
|
|
|
entity: "jsObjects",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/jsObjects/myJSId",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.JS_OBJECT,
|
|
|
|
|
id: "myJSId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationId: "myAppId",
|
|
|
|
|
collectionId: "myJSId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/datasource",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.DATASOURCE_LIST,
|
|
|
|
|
id: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationId: "myAppId",
|
|
|
|
|
entity: "datasource",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-12-27 08:47:35 +00:00
|
|
|
path: "/applications/myAppId/pages/myPageId/edit/datasource/myDatasourceId",
|
2023-11-28 12:46:43 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.DATASOURCE,
|
|
|
|
|
id: "myDatasourceId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationId: "myAppId",
|
|
|
|
|
datasourceId: "myDatasourceId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
];
|
2024-01-08 05:39:47 +00:00
|
|
|
const pageSlugCases: TestCase[] = [
|
2022-10-17 15:16:38 +00:00
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit",
|
2023-11-20 07:58:08 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.CANVAS,
|
|
|
|
|
id: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationSlug: "eval",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
pageSlug: "page1-",
|
|
|
|
|
},
|
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",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationSlug: "myAppId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
pageSlug: "page1-",
|
|
|
|
|
widgetIds: "ryvc8i7oja",
|
|
|
|
|
},
|
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: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationSlug: "eval",
|
|
|
|
|
entity: "queries",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
pageSlug: "page1-",
|
|
|
|
|
},
|
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",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
apiId: "myApiId",
|
|
|
|
|
applicationSlug: "eval",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
pageSlug: "page1-",
|
|
|
|
|
},
|
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",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationSlug: "eval",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
pageSlug: "page1-",
|
|
|
|
|
queryId: "myQueryId",
|
|
|
|
|
},
|
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: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationSlug: "eval",
|
|
|
|
|
entity: "jsObjects",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
pageSlug: "page1-",
|
|
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit/jsObjects/myJSId",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.JS_OBJECT,
|
|
|
|
|
id: "myJSId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationSlug: "eval",
|
|
|
|
|
collectionId: "myJSId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
pageSlug: "page1-",
|
|
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/eval/page1-myPageId/edit/datasource",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.DATASOURCE_LIST,
|
|
|
|
|
id: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationSlug: "eval",
|
|
|
|
|
entity: "datasource",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
pageSlug: "page1-",
|
|
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-12-27 08:47:35 +00:00
|
|
|
path: "/app/eval/page1-myPageId/edit/datasource/myDatasourceId",
|
2023-11-28 12:46:43 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.DATASOURCE,
|
|
|
|
|
id: "myDatasourceId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
applicationSlug: "eval",
|
|
|
|
|
datasourceId: "myDatasourceId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
pageSlug: "page1-",
|
|
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
2022-10-17 15:16:38 +00:00
|
|
|
];
|
2024-01-08 05:39:47 +00:00
|
|
|
const customSlugCases: TestCase[] = [
|
2022-10-17 15:16:38 +00:00
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit",
|
2023-11-20 07:58:08 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.CANVAS,
|
|
|
|
|
id: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
customSlug: "myCustomSlug-",
|
|
|
|
|
},
|
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",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
customSlug: "myCustomSlug-",
|
|
|
|
|
widgetIds: "ryvc8i7oja",
|
|
|
|
|
},
|
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: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
customSlug: "myCustomSlug-",
|
|
|
|
|
entity: "queries",
|
|
|
|
|
},
|
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",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
customSlug: "myCustomSlug-",
|
|
|
|
|
apiId: "myApiId",
|
|
|
|
|
},
|
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",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
customSlug: "myCustomSlug-",
|
|
|
|
|
queryId: "myQueryId",
|
|
|
|
|
},
|
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: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
entity: "jsObjects",
|
|
|
|
|
customSlug: "myCustomSlug-",
|
|
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit/jsObjects/myJSId",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.JS_OBJECT,
|
|
|
|
|
id: "myJSId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.EDITOR,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
collectionId: "myJSId",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
customSlug: "myCustomSlug-",
|
|
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/app/myCustomSlug-myPageId/edit/datasource",
|
|
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.DATASOURCE_LIST,
|
|
|
|
|
id: "",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
entity: "datasource",
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
customSlug: "myCustomSlug-",
|
|
|
|
|
},
|
2023-11-28 12:46:43 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2023-12-27 08:47:35 +00:00
|
|
|
path: "/app/myCustomSlug-myPageId/edit/datasource/myDatasourceId",
|
2023-11-28 12:46:43 +00:00
|
|
|
expected: {
|
|
|
|
|
entity: FocusEntity.DATASOURCE,
|
|
|
|
|
id: "myDatasourceId",
|
2023-11-30 09:26:24 +00:00
|
|
|
appState: EditorState.DATA,
|
2024-01-08 05:39:47 +00:00
|
|
|
params: {
|
|
|
|
|
pageId: "myPageId",
|
|
|
|
|
customSlug: "myCustomSlug-",
|
|
|
|
|
datasourceId: "myDatasourceId",
|
|
|
|
|
},
|
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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|