PromucFlow_constructor/app/client/test/testUtils.tsx
Ankita Kinger e1d09b47d3
chore: Removing the feature flag for using Entity Item component from ADS templates (#39093)
## Description

Removing the feature flag for using Entity Item component from ADS
templates in the Entity Explorer in App Editor.

Fixes [#39067](https://github.com/appsmithorg/appsmith/issues/39067)

## 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/13804174182>
> Commit: 8a4a2007c8e1411a9baa388cf841e5e489cb6778
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13804174182&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 12 Mar 2025 06:32:35 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**
- Improved entity renaming: input fields now automatically clear
previous text for smoother editing.
- Enhanced page navigation: active selections are now verified more
consistently, ensuring clearer context.
  - New feature flag added for enhanced entity item visibility.
- Added new methods for improved entity selection and verification in
tests.
- Introduced `parentId` properties in widget definitions to enhance
hierarchical structure.
- Updated selectors for widget names and collapsible elements in tests
for improved targeting.

- **Bug Fixes**
- Resolved issues with inconsistent element detection and state feedback
for a more stable interface.

- **Refactor**
- Updated widget hierarchy and locator logic for improved layout
rendering and overall UI consistency.
- Modified locator strategies to enhance element targeting across
various components.
  - Simplified method signatures for better clarity and maintainability.
  - Enhanced test selectors to improve reliability and maintainability.
- Removed obsolete commands and streamlined interaction methods in
tests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Hetu Nandu <hetunandu@gmail.com>
Co-authored-by: Hetu Nandu <hetu@appsmith.com>
2025-03-14 17:40:02 +05:30

116 lines
3.3 KiB
TypeScript

import type { ReactElement } from "react";
import React from "react";
import type { RenderOptions } from "@testing-library/react";
import { render, queries } from "@testing-library/react";
import { Provider } from "react-redux";
import { ThemeProvider } from "styled-components";
import { getCurrentThemeDetails } from "selectors/themeSelectors";
import * as customQueries from "./customQueries";
import { BrowserRouter } from "react-router-dom";
import type { AppState } from "ee/reducers";
import appReducer from "ee/reducers";
import { applyMiddleware, compose, createStore } from "redux";
import { reduxBatch } from "@manaflair/redux-batch";
import createSagaMiddleware from "redux-saga";
import store, { testStore } from "store";
import { sagasToRunForTests } from "./sagas";
import { all, call, spawn } from "redux-saga/effects";
import type { FeatureFlags } from "ee/entities/FeatureFlag";
import { fetchFeatureFlagsSuccess } from "../src/actions/userActions";
import { DEFAULT_FEATURE_FLAG_VALUE } from "ee/entities/FeatureFlag";
const testSagaMiddleware = createSagaMiddleware();
const testStoreWithTestMiddleWare = (initialState: Partial<AppState>) =>
createStore(
appReducer,
initialState,
compose(reduxBatch, applyMiddleware(testSagaMiddleware), reduxBatch),
);
const rootSaga = function* (sagasToRun = sagasToRunForTests) {
yield all(
sagasToRun.map((saga) =>
spawn(function* () {
while (true) {
yield call(saga);
break;
}
}),
),
);
};
interface State {
url?: string;
initialState?: Partial<AppState>;
sagasToRun?: typeof sagasToRunForTests;
featureFlags?: Partial<FeatureFlags>;
}
const setupState = (state?: State) => {
let reduxStore = store;
window.history.pushState({}, "Appsmith", state?.url || "/");
if (state && (state.initialState || state.featureFlags)) {
reduxStore = testStore(state.initialState || {});
if (state.featureFlags) {
reduxStore.dispatch(
fetchFeatureFlagsSuccess({
...DEFAULT_FEATURE_FLAG_VALUE,
release_ads_entity_item_enabled: true,
...state.featureFlags,
}),
);
}
}
if (state && state.sagasToRun) {
reduxStore = testStoreWithTestMiddleWare(reduxStore.getState());
testSagaMiddleware.run(() => rootSaga(state.sagasToRun));
}
const defaultTheme = getCurrentThemeDetails(reduxStore.getState());
return { reduxStore, defaultTheme };
};
const customRender = (
ui: ReactElement,
state?: State,
options?: Omit<RenderOptions, "queries">,
) => {
const { defaultTheme, reduxStore } = setupState(state);
return render(
<BrowserRouter>
<Provider store={reduxStore}>
<ThemeProvider theme={defaultTheme}>{ui}</ThemeProvider>
</Provider>
</BrowserRouter>,
{
queries: { ...queries, ...customQueries },
...options,
},
);
};
const hookWrapper = (state: State) => {
return ({ children }: { children: ReactElement }) => {
const { defaultTheme, reduxStore } = setupState(state);
return (
<BrowserRouter>
<Provider store={reduxStore}>
<ThemeProvider theme={defaultTheme}>{children}</ThemeProvider>
</Provider>
</BrowserRouter>
);
};
};
export * from "@testing-library/react";
export { customRender as render, hookWrapper };