PromucFlow_constructor/app/client/test/testUtils.tsx
Ashok Kumar M 8c8141650a
Feature: Widget grouping Phase I (Multi select and Bulk Delete) + Canvas Enhancements. (#4219)
* Feature: Canvas layer enhancements(DIP)

* feedback fixes

* fixing build

* dip

* dip

* dip

* fixing build

* dip

* dev fixes

* dip

* Fixing top bottom resize handles

* dip

* reposition widget name on top edges.

* dip

* dip

* dip

* dip

* renaming selectedWidget to lastSelectedWidget

* code clean up

* Fixing list widget as per grid scale.

* Fixing existing specs.

* Adding migration test cases.

* dip

* FIxing proppane in modal.

* fixing modal z-indedx.

* fix for modal name.

* dip

* dip

* dip

* adding test cases for hotkeys.

* dip

* dip

* fixing build

* Trying some performance improvements for jests.

* 17 mins with runinband lets try without it.

* minor bug fixes.

* code clean up

* save migrated app on fetch.

* fixing few cypress tests

* fixing cypress tests

* fixing cypress tests.

* fixing cypress

* updated DSL

* Addressing code review comments.

* test fails

* dip

* eslint fixes.

* fixing debugger cypress tests.

* updating latest page version.

* updating migration changes to cypress dsl's.

* updating chart data fixes for cypress tests.

Co-authored-by: Apple <nandan@thinkify.io>
2021-05-18 23:59:39 +05:30

88 lines
2.7 KiB
TypeScript

import React, { ReactElement } from "react";
import { render, RenderOptions, queries } from "@testing-library/react";
import { Provider, useDispatch } from "react-redux";
import { ThemeProvider } from "../src/constants/DefaultTheme";
import { getCurrentThemeDetails } from "../src/selectors/themeSelectors";
import * as customQueries from "./customQueries";
import { BrowserRouter } from "react-router-dom";
import appReducer, { AppState } from "reducers";
import { DndProvider } from "react-dnd";
import TouchBackend from "react-dnd-touch-backend";
import { noop } from "utils/AppsmithUtils";
import { getCanvasWidgetsPayload } from "sagas/PageSagas";
import { updateCurrentPage } from "actions/pageActions";
import { editorInitializer } from "utils/EditorUtils";
import { ReduxActionTypes } from "constants/ReduxActionConstants";
import { initEditor } from "actions/initActions";
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";
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;
}
}),
),
);
};
const customRender = (
ui: ReactElement,
state?: {
url?: string;
initialState?: Partial<AppState>;
sagasToRun?: typeof sagasToRunForTests;
},
options?: Omit<RenderOptions, "queries">,
) => {
let reduxStore = store;
window.history.pushState({}, "Appsmith", state?.url || "/");
if (state && state.initialState) {
reduxStore = testStore(state.initialState || {});
}
if (state && state.sagasToRun) {
reduxStore = testStoreWithTestMiddleWare(reduxStore.getState());
testSagaMiddleware.run(() => rootSaga(state.sagasToRun));
}
const defaultTheme = getCurrentThemeDetails(reduxStore.getState());
return render(
<BrowserRouter>
<Provider store={reduxStore}>
<DndProvider
backend={TouchBackend}
options={{
enableMouseEvents: true,
}}
>
<ThemeProvider theme={defaultTheme}>{ui}</ThemeProvider>
</DndProvider>
</Provider>
</BrowserRouter>,
{
queries: { ...queries, ...customQueries },
...options,
},
);
};
export * from "@testing-library/react";
export { customRender as render };