PromucFlow_constructor/app/client/src/navigation/FocusEntity.test.ts
Hetu Nandu ac41ad250b
chore: Move entities/IDE/constants (#39064)
## Description

Remove the IDE constants from the entities folder and move it to the
common IDE folder
Create separate buttons exports for sidebar buttons
Update the button usages 

Fixes #39050 

## Automation

/ok-to-test tags="@tag.All"

### 🔍 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/13191919670>
> Commit: 5055b6ed0394b5f3fe1450bd7a042eb851fe39ab
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13191919670&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Fri, 07 Feb 2025 05:19:56 UTC
<!-- end of auto-generated comment: Cypress test results  -->


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


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

- **New Features**
- Introduced new editor state definitions and enhanced sidebar
configurations with conditional messaging for data source availability.

- **Refactor**
- Reorganized internal module structures and consolidated type
definitions to improve maintainability, consistency, and type safety.

- **Tests**
  - Updated test references to align with the new module organization.

These changes streamline the codebase and lay the groundwork for future
improvements while maintaining the existing end-user experience.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Ankita Kinger <ankita@appsmith.com>
2025-02-07 16:45:55 +05:30

384 lines
9.6 KiB
TypeScript

import type { FocusEntityInfo } from "navigation/FocusEntity";
import { FocusEntity, identifyEntityFromPath } from "navigation/FocusEntity";
import { EditorState } from "IDE/enums";
interface TestCase {
path: string;
expected: FocusEntityInfo;
}
const baseApplicationId = "a0123456789abcdef0000000";
const basePageId = "b0123456789abcdef0000000";
describe("identifyEntityFromPath", () => {
const oldUrlCases: TestCase[] = [
{
path: `/applications/${baseApplicationId}/pages/${basePageId}/edit`,
expected: {
entity: FocusEntity.CANVAS,
id: "",
appState: EditorState.EDITOR,
params: {
baseApplicationId,
basePageId,
},
},
},
{
path: `/applications/${baseApplicationId}/pages/${basePageId}/edit/widgets/ryvc8i7oja`,
expected: {
entity: FocusEntity.WIDGET,
id: "ryvc8i7oja",
appState: EditorState.EDITOR,
params: {
baseApplicationId,
basePageId,
widgetIds: "ryvc8i7oja",
},
},
},
{
path: `/applications/${baseApplicationId}/pages/${basePageId}/edit/queries`,
expected: {
entity: FocusEntity.QUERY_LIST,
id: "",
appState: EditorState.EDITOR,
params: {
baseApplicationId,
entity: "queries",
basePageId,
},
},
},
{
path: `/applications/${baseApplicationId}/pages/${basePageId}/edit/api/myApiId`,
expected: {
entity: FocusEntity.QUERY,
id: "myApiId",
appState: EditorState.EDITOR,
params: {
baseApiId: "myApiId",
baseApplicationId,
basePageId,
},
},
},
{
path: `/applications/${baseApplicationId}/pages/${basePageId}/edit/queries/myQueryId`,
expected: {
entity: FocusEntity.QUERY,
id: "myQueryId",
appState: EditorState.EDITOR,
params: {
baseQueryId: "myQueryId",
baseApplicationId,
basePageId,
},
},
},
{
path: `/applications/${baseApplicationId}/pages/${basePageId}/edit/jsObjects`,
expected: {
entity: FocusEntity.JS_OBJECT_LIST,
id: "",
appState: EditorState.EDITOR,
params: {
baseApplicationId,
entity: "jsObjects",
basePageId,
},
},
},
{
path: `/applications/${baseApplicationId}/pages/${basePageId}/edit/jsObjects/myJSId`,
expected: {
entity: FocusEntity.JS_OBJECT,
id: "myJSId",
appState: EditorState.EDITOR,
params: {
baseApplicationId,
baseCollectionId: "myJSId",
basePageId,
},
},
},
{
path: `/applications/${baseApplicationId}/pages/${basePageId}/edit/datasource`,
expected: {
entity: FocusEntity.DATASOURCE_LIST,
id: "",
appState: EditorState.DATA,
params: {
baseApplicationId,
entity: "datasource",
basePageId,
},
},
},
{
path: `/applications/${baseApplicationId}/pages/${basePageId}/edit/datasource/myDatasourceId`,
expected: {
entity: FocusEntity.DATASOURCE,
id: "myDatasourceId",
appState: EditorState.DATA,
params: {
baseApplicationId,
datasourceId: "myDatasourceId",
basePageId,
},
},
},
];
const pageSlugCases: TestCase[] = [
{
path: `/app/eval/page1-${basePageId}/edit`,
expected: {
entity: FocusEntity.CANVAS,
id: "",
appState: EditorState.EDITOR,
params: {
applicationSlug: "eval",
basePageId,
pageSlug: "page1-",
},
},
},
{
path: `/app/app-slug/page1-${basePageId}/edit/widgets/ryvc8i7oja`,
expected: {
entity: FocusEntity.WIDGET,
id: "ryvc8i7oja",
appState: EditorState.EDITOR,
params: {
applicationSlug: "app-slug",
basePageId,
pageSlug: "page1-",
widgetIds: "ryvc8i7oja",
},
},
},
{
path: `/app/eval/page1-${basePageId}/edit/queries`,
expected: {
entity: FocusEntity.QUERY_LIST,
id: "",
appState: EditorState.EDITOR,
params: {
applicationSlug: "eval",
entity: "queries",
basePageId,
pageSlug: "page1-",
},
},
},
{
path: `/app/eval/page1-${basePageId}/edit/api/myApiId`,
expected: {
entity: FocusEntity.QUERY,
id: "myApiId",
appState: EditorState.EDITOR,
params: {
baseApiId: "myApiId",
applicationSlug: "eval",
basePageId,
pageSlug: "page1-",
},
},
},
{
path: `/app/eval/page1-${basePageId}/edit/queries/myQueryId`,
expected: {
entity: FocusEntity.QUERY,
id: "myQueryId",
appState: EditorState.EDITOR,
params: {
applicationSlug: "eval",
basePageId,
pageSlug: "page1-",
baseQueryId: "myQueryId",
},
},
},
{
path: `/app/eval/page1-${basePageId}/edit/jsObjects`,
expected: {
entity: FocusEntity.JS_OBJECT_LIST,
id: "",
appState: EditorState.EDITOR,
params: {
applicationSlug: "eval",
entity: "jsObjects",
basePageId,
pageSlug: "page1-",
},
},
},
{
path: `/app/eval/page1-${basePageId}/edit/jsObjects/myJSId`,
expected: {
entity: FocusEntity.JS_OBJECT,
id: "myJSId",
appState: EditorState.EDITOR,
params: {
applicationSlug: "eval",
baseCollectionId: "myJSId",
basePageId,
pageSlug: "page1-",
},
},
},
{
path: `/app/eval/page1-${basePageId}/edit/datasource`,
expected: {
entity: FocusEntity.DATASOURCE_LIST,
id: "",
appState: EditorState.DATA,
params: {
applicationSlug: "eval",
entity: "datasource",
basePageId,
pageSlug: "page1-",
},
},
},
{
path: `/app/eval/page1-${basePageId}/edit/datasource/myDatasourceId`,
expected: {
entity: FocusEntity.DATASOURCE,
id: "myDatasourceId",
appState: EditorState.DATA,
params: {
applicationSlug: "eval",
datasourceId: "myDatasourceId",
basePageId,
pageSlug: "page1-",
},
},
},
];
const customSlugCases: TestCase[] = [
{
path: `/app/myCustomSlug-${basePageId}/edit`,
expected: {
entity: FocusEntity.CANVAS,
id: "",
appState: EditorState.EDITOR,
params: {
basePageId,
customSlug: "myCustomSlug-",
},
},
},
{
path: `/app/myCustomSlug-${basePageId}/edit/widgets/ryvc8i7oja`,
expected: {
entity: FocusEntity.WIDGET,
id: "ryvc8i7oja",
appState: EditorState.EDITOR,
params: {
basePageId,
customSlug: "myCustomSlug-",
widgetIds: "ryvc8i7oja",
},
},
},
{
path: `/app/myCustomSlug-${basePageId}/edit/queries`,
expected: {
entity: FocusEntity.QUERY_LIST,
id: "",
appState: EditorState.EDITOR,
params: {
basePageId,
customSlug: "myCustomSlug-",
entity: "queries",
},
},
},
{
path: `/app/myCustomSlug-${basePageId}/edit/api/myApiId`,
expected: {
entity: FocusEntity.QUERY,
id: "myApiId",
appState: EditorState.EDITOR,
params: {
basePageId,
customSlug: "myCustomSlug-",
baseApiId: "myApiId",
},
},
},
{
path: `/app/myCustomSlug-${basePageId}/edit/queries/myQueryId`,
expected: {
entity: FocusEntity.QUERY,
id: "myQueryId",
appState: EditorState.EDITOR,
params: {
basePageId,
customSlug: "myCustomSlug-",
baseQueryId: "myQueryId",
},
},
},
{
path: `/app/myCustomSlug-${basePageId}/edit/jsObjects`,
expected: {
entity: FocusEntity.JS_OBJECT_LIST,
id: "",
appState: EditorState.EDITOR,
params: {
basePageId,
entity: "jsObjects",
customSlug: "myCustomSlug-",
},
},
},
{
path: `/app/myCustomSlug-${basePageId}/edit/jsObjects/myJSId`,
expected: {
entity: FocusEntity.JS_OBJECT,
id: "myJSId",
appState: EditorState.EDITOR,
params: {
baseCollectionId: "myJSId",
basePageId,
customSlug: "myCustomSlug-",
},
},
},
{
path: `/app/myCustomSlug-${basePageId}/edit/datasource`,
expected: {
entity: FocusEntity.DATASOURCE_LIST,
id: "",
appState: EditorState.DATA,
params: {
entity: "datasource",
basePageId,
customSlug: "myCustomSlug-",
},
},
},
{
path: `/app/myCustomSlug-${basePageId}/edit/datasource/myDatasourceId`,
expected: {
entity: FocusEntity.DATASOURCE,
id: "myDatasourceId",
appState: EditorState.DATA,
params: {
basePageId,
customSlug: "myCustomSlug-",
datasourceId: "myDatasourceId",
},
},
},
];
const cases = oldUrlCases.concat(pageSlugCases.concat(customSlugCases));
it.each(cases)("$# $path", ({ expected, path }) => {
expect(identifyEntityFromPath(path)).toStrictEqual(expected);
});
});