chore: Added test for groupAndSortEntitySegmentList (#32007)

## Description

This PR adds test to check the functionality of
groupAndSortEntitySegmentList

Fixes #31872

## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!IMPORTANT]  
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/8419360291>
> Commit: `f4858d4b452c2662ddff53a1e7c1c5054fb02494`
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8419360291&attempt=1"
target="_blank">Click here!</a>
> All cypress tests have passed 🎉🎉🎉

<!-- end of auto-generated comment: Cypress test results  -->





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

## Summary by CodeRabbit

- **Tests**
- Introduced tests for the `groupAndSortEntitySegmentList` function to
ensure entity segment lists are grouped and sorted alphabetically
correctly.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
albinAppsmith 2024-03-26 09:40:46 +05:30 committed by GitHub
parent 19d5d49dd0
commit 7d2ad8a38b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,64 @@
import type { EntityItem } from "@appsmith/entities/IDE/constants";
import { groupAndSortEntitySegmentList } from "./appIDESelectors";
import { PluginType } from "entities/Action";
describe("groupAndSortEntitySegmentList", () => {
it("should group and sort entity segment list alphabetically", () => {
const items: EntityItem[] = [
{
title: "BalanceTransactions",
type: PluginType.API,
key: "1",
group: "Users",
},
{ title: "AllUsers", type: PluginType.API, key: "2", group: "Users" },
{ title: "Query 1", type: PluginType.SAAS, key: "3", group: "Movies" },
{
title: "Query 2",
type: PluginType.SAAS,
key: "4",
group: "Movies",
},
{
title: "Query 3",
type: PluginType.SAAS,
key: "5",
group: "Movies",
},
{ title: "Random", type: PluginType.API, key: "6" },
];
const result = groupAndSortEntitySegmentList(items);
// Users, Movies, NA
expect(result.length).toBe(3);
// Check sorting of groups alphabetically
expect(result.map((group) => group.group)).toEqual([
"Movies",
"NA",
"Users",
]);
// Check sorting of items within each group alphabetically
expect(result[0].items.map((item) => item.title)).toEqual([
"Query 1",
"Query 2",
"Query 3",
]);
expect(result[2].items.map((item) => item.title)).toEqual([
"AllUsers",
"BalanceTransactions",
]);
// Check items without group sorted correctly under "NA" group
expect(result[1].items.map((item) => item.title)).toEqual(["Random"]);
});
it("should handle empty input", () => {
const result = groupAndSortEntitySegmentList([]);
expect(result).toEqual([]);
});
// Add more test cases to cover edge cases or specific scenarios
});