PromucFlow_constructor/app/client/src/navigation/FocusEntity.test.ts
Ankita Kinger 80a3f57519
chore: Refactoring sidebar on app editor to support the same on package editor (#29212)
## Description

Refactoring sidebar on app editor to support the same on package editor

#### PR fixes following issue(s)
Fixes [#28476](https://github.com/appsmithorg/appsmith/issues/28476)

#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)

## Testing

#### How Has This Been Tested?
- [x] Manual
- [ ] JUnit
- [x] Jest
- [ ] Cypress

## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed

---------

Co-authored-by: Hetu Nandu <hetunandu@gmail.com>
2023-11-30 14:56:24 +05:30

264 lines
6.6 KiB
TypeScript

import { identifyEntityFromPath, FocusEntity } from "navigation/FocusEntity";
import { EditorState } from "../entities/IDE/constants";
describe("identifyEntityFromPath", () => {
const oldUrlCases = [
{
path: "/applications/myAppId/pages/myPageId/edit",
expected: {
entity: FocusEntity.CANVAS,
id: "",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/applications/myAppId/pages/myPageId/edit/widgets/ryvc8i7oja",
expected: {
entity: FocusEntity.PROPERTY_PANE,
id: "ryvc8i7oja",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/applications/myAppId/pages/myPageId/edit/queries",
expected: {
entity: FocusEntity.QUERY_LIST,
id: "",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/applications/myAppId/pages/myPageId/edit/api/myApiId",
expected: {
entity: FocusEntity.QUERY,
id: "myApiId",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/applications/myAppId/pages/myPageId/edit/queries/myQueryId",
expected: {
entity: FocusEntity.QUERY,
id: "myQueryId",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/applications/myAppId/pages/myPageId/edit/jsObjects",
expected: {
entity: FocusEntity.JS_OBJECT_LIST,
id: "",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/applications/myAppId/pages/myPageId/edit/jsObjects/myJSId",
expected: {
entity: FocusEntity.JS_OBJECT,
id: "myJSId",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/applications/myAppId/pages/myPageId/edit/datasource",
expected: {
entity: FocusEntity.DATASOURCE_LIST,
id: "",
pageId: "myPageId",
appState: EditorState.DATA,
},
},
{
path: "/applications/myAppId/pages/myPageId/edit/datasources/myDatasourceId",
expected: {
entity: FocusEntity.DATASOURCE,
id: "myDatasourceId",
pageId: "myPageId",
appState: EditorState.DATA,
},
},
];
const pageSlugCases = [
{
path: "/app/eval/page1-myPageId/edit",
expected: {
entity: FocusEntity.CANVAS,
id: "",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/myAppId/page1-myPageId/edit/widgets/ryvc8i7oja",
expected: {
entity: FocusEntity.PROPERTY_PANE,
id: "ryvc8i7oja",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/eval/page1-myPageId/edit/queries",
expected: {
entity: FocusEntity.QUERY_LIST,
id: "",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/eval/page1-myPageId/edit/api/myApiId",
expected: {
entity: FocusEntity.QUERY,
id: "myApiId",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/eval/page1-myPageId/edit/queries/myQueryId",
expected: {
entity: FocusEntity.QUERY,
id: "myQueryId",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/eval/page1-myPageId/edit/jsObjects",
expected: {
entity: FocusEntity.JS_OBJECT_LIST,
id: "",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/eval/page1-myPageId/edit/jsObjects/myJSId",
expected: {
entity: FocusEntity.JS_OBJECT,
id: "myJSId",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/eval/page1-myPageId/edit/datasource",
expected: {
entity: FocusEntity.DATASOURCE_LIST,
id: "",
pageId: "myPageId",
appState: EditorState.DATA,
},
},
{
path: "/app/eval/page1-myPageId/edit/datasources/myDatasourceId",
expected: {
entity: FocusEntity.DATASOURCE,
id: "myDatasourceId",
pageId: "myPageId",
appState: EditorState.DATA,
},
},
];
const customSlugCases = [
{
path: "/app/myCustomSlug-myPageId/edit",
expected: {
entity: FocusEntity.CANVAS,
id: "",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/myCustomSlug-myPageId/edit/widgets/ryvc8i7oja",
expected: {
entity: FocusEntity.PROPERTY_PANE,
id: "ryvc8i7oja",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/myCustomSlug-myPageId/edit/queries",
expected: {
entity: FocusEntity.QUERY_LIST,
id: "",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/myCustomSlug-myPageId/edit/api/myApiId",
expected: {
entity: FocusEntity.QUERY,
id: "myApiId",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/myCustomSlug-myPageId/edit/queries/myQueryId",
expected: {
entity: FocusEntity.QUERY,
id: "myQueryId",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/myCustomSlug-myPageId/edit/jsObjects",
expected: {
entity: FocusEntity.JS_OBJECT_LIST,
id: "",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/myCustomSlug-myPageId/edit/jsObjects/myJSId",
expected: {
entity: FocusEntity.JS_OBJECT,
id: "myJSId",
pageId: "myPageId",
appState: EditorState.EDITOR,
},
},
{
path: "/app/myCustomSlug-myPageId/edit/datasource",
expected: {
entity: FocusEntity.DATASOURCE_LIST,
id: "",
pageId: "myPageId",
appState: EditorState.DATA,
},
},
{
path: "/app/myCustomSlug-myPageId/edit/datasources/myDatasourceId",
expected: {
entity: FocusEntity.DATASOURCE,
id: "myDatasourceId",
pageId: "myPageId",
appState: EditorState.DATA,
},
},
];
const cases = oldUrlCases.concat(pageSlugCases.concat(customSlugCases));
it("works", () => {
for (const testCase of cases) {
const actual = identifyEntityFromPath(testCase.path);
expect(actual).toStrictEqual(testCase.expected);
}
});
});