PromucFlow_constructor/app/client/cypress/support/Objects/FeatureFlags.ts
albinAppsmith 46786ae003
feat: Enable new toolbar for cypress (#37148)
## Description

This PR enabled IDE toolbar for cypress.

Fixes #37217

## 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/12115693818>
> Commit: f2af8705e91af400b3a80f6684cce7fb487f1ca3
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12115693818&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Mon, 02 Dec 2024 12:19:38 UTC
<!-- end of auto-generated comment: Cypress test results  -->


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


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

- **New Features**
- Introduced a new feature flag `release_actions_redesign_enabled` to
enhance user experience.
- **Bug Fixes**
- Updated method calls in various test cases to improve consistency and
reliability in interactions, specifically renaming methods related to
data sources and queries.
- Improved error handling and validation in tests for MongoDB query
functionalities.
- **Documentation**
- Enhanced test coverage and assertions for various functionalities,
including API actions, Google Sheets queries, and JavaScript function
execution.
- **Style**
- Updated CSS selectors for improved consistency and maintainability
across components and test cases.
- **Tests**
- Refactored multiple test cases to utilize new helper methods,
improving code clarity and reducing direct DOM manipulation.
- Enhanced visual tests for JSEditor and improved interaction with the
run button.
- Added new assertions and enhanced the structure of tests for various
components, including API response handling and widget interactions.
- Streamlined interaction with the settings toolbar in various test
cases by encapsulating functionality within the `PluginActionForm`
class.
- Introduced new `data-testid` attributes across various components to
enhance testability.
- **Chores**
- Removed unused imports and streamlined method calls for better
performance and readability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-12-03 09:21:43 +05:30

111 lines
3.2 KiB
TypeScript

import { LICENSE_FEATURE_FLAGS } from "../Constants";
import { ObjectsRegistry } from "./Registry";
import produce from "immer";
const defaultFlags = {
release_side_by_side_ide_enabled: true,
rollout_remove_feature_walkthrough_enabled: false, // remove this flag from here when it's removed from code
release_actions_redesign_enabled: true,
};
export const featureFlagIntercept = (
flags: Record<string, boolean> = {},
reload = true,
) => {
getConsolidatedDataApi({ ...flags, ...defaultFlags }, false);
const response = {
responseMeta: {
status: 200,
success: true,
},
data: {
...flags,
...defaultFlags,
},
errorDisplay: "",
};
cy.intercept("GET", "/api/v1/users/features", response);
if (reload) ObjectsRegistry.AggregateHelper.CypressReload();
};
export const getConsolidatedDataApi = (
flags: Record<string, boolean> = {},
reload = true,
) => {
cy.intercept("GET", "/api/v1/consolidated-api/*?*", (req) => {
req.reply((res: any) => {
if (
res.statusCode === 200 ||
res.statusCode === 401 ||
res.statusCode === 500
) {
const originalResponse = res?.body;
const updatedResponse = produce(originalResponse, (draft: any) => {
draft.data.featureFlags.data = {
...flags,
};
});
return res.send(updatedResponse);
}
});
}).as("getConsolidatedData");
if (reload) ObjectsRegistry.AggregateHelper.CypressReload();
};
export const featureFlagInterceptForLicenseFlags = () => {
cy.intercept(
{
method: "GET",
url: "/api/v1/users/features",
},
(req) => {
req.reply((res) => {
if (res) {
const originalResponse = res.body;
let modifiedResponse: any = {};
Object.keys(originalResponse.data).forEach((flag) => {
if (LICENSE_FEATURE_FLAGS.includes(flag)) {
modifiedResponse[flag] = originalResponse.data[flag];
}
});
modifiedResponse = {
...modifiedResponse,
release_app_sidebar_enabled: true,
};
res.send({
responseMeta: {
status: 200,
success: true,
},
data: { ...modifiedResponse },
errorDisplay: "",
});
}
});
},
).as("getLicenseFeatures");
cy.intercept("GET", "/api/v1/consolidated-api/*?*", (req) => {
req.reply((res: any) => {
if (res.statusCode === 200) {
const originalResponse = res?.body;
const updatedResponse = produce(originalResponse, (draft: any) => {
draft.data.featureFlags.data = {};
Object.keys(originalResponse.data.featureFlags.data).forEach(
(flag) => {
if (LICENSE_FEATURE_FLAGS.includes(flag)) {
draft.data.featureFlags.data[flag] =
originalResponse.data.featureFlags.data[flag];
}
},
);
draft.data.featureFlags.data["release_app_sidebar_enabled"] = true;
});
return res.send(updatedResponse);
}
});
}).as("getConsolidatedData");
ObjectsRegistry.AggregateHelper.CypressReload();
};