Skip to content

Commit

Permalink
remove asynchronousity
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra committed Mar 3, 2025
1 parent e140913 commit 230f070
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ describe('LayerPanel', () => {
target.columnId !== 'a' ? { dropTypes: ['field_replace'], nextLabel: '' } : undefined
);

const { instance } = await mountWithReduxStore(
const { instance } = mountWithReduxStore(
<ChildDragDropProvider value={createMockedDragDropContext({ dragging: draggingField })}>
<LayerPanel {...getDefaultProps()} />
</ChildDragDropProvider>
Expand Down Expand Up @@ -760,7 +760,7 @@ describe('LayerPanel', () => {
nextLabel: '',
});

const { instance } = await mountWithReduxStore(
const { instance } = mountWithReduxStore(
<ChildDragDropProvider value={createMockedDragDropContext({ dragging: draggingOperation })}>
<LayerPanel {...getDefaultProps()} />
</ChildDragDropProvider>
Expand Down Expand Up @@ -820,7 +820,7 @@ describe('LayerPanel', () => {
const holder = document.createElement('div');
document.body.appendChild(holder);

const { instance } = await mountWithReduxStore(
const { instance } = mountWithReduxStore(
<ChildDragDropProvider value={createMockedDragDropContext({ dragging: draggingOperation })}>
<LayerPanel {...getDefaultProps()} />
</ChildDragDropProvider>,
Expand Down Expand Up @@ -858,7 +858,7 @@ describe('LayerPanel', () => {
],
});

const { instance } = await mountWithReduxStore(
const { instance } = mountWithReduxStore(
<ChildDragDropProvider value={createMockedDragDropContext({ dragging: draggingOperation })}>
<LayerPanel {...getDefaultProps()} />
</ChildDragDropProvider>
Expand Down Expand Up @@ -895,7 +895,7 @@ describe('LayerPanel', () => {
],
});

const { instance } = await mountWithReduxStore(
const { instance } = mountWithReduxStore(
<ChildDragDropProvider value={createMockedDragDropContext({ dragging: draggingOperation })}>
<LayerPanel {...getDefaultProps()} activeVisualization={mockVis} />
</ChildDragDropProvider>
Expand Down Expand Up @@ -936,7 +936,7 @@ describe('LayerPanel', () => {
mockDatasource.onDrop.mockReturnValue(true);
const updateVisualization = jest.fn();

const { instance } = await mountWithReduxStore(
const { instance } = mountWithReduxStore(
<ChildDragDropProvider value={createMockedDragDropContext({ dragging: draggingOperation })}>
<LayerPanel
{...getDefaultProps()}
Expand Down Expand Up @@ -987,7 +987,7 @@ describe('LayerPanel', () => {
mockDatasource.onDrop.mockReturnValue(false);
const updateVisualization = jest.fn();

const { instance } = await mountWithReduxStore(
const { instance } = mountWithReduxStore(
<ChildDragDropProvider value={createMockedDragDropContext({ dragging: draggingOperation })}>
<LayerPanel
{...getDefaultProps()}
Expand Down Expand Up @@ -1027,7 +1027,7 @@ describe('LayerPanel', () => {

mockDatasource.onDrop.mockReturnValue(true);

const { instance } = await mountWithReduxStore(
const { instance } = mountWithReduxStore(
<ChildDragDropProvider value={createMockedDragDropContext({ dragging: draggingOperation })}>
<LayerPanel {...getDefaultProps()} />
</ChildDragDropProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('suggestion_panel', () => {
});

it('should avoid completely to render SuggestionPanel when in fullscreen mode', async () => {
const { instance, lensStore } = await mountWithReduxStore(
const { instance, lensStore } = mountWithReduxStore(
<SuggestionPanelWrapper {...defaultProps} />
);
expect(instance.find(SuggestionPanel).exists()).toBe(true);
Expand All @@ -131,7 +131,7 @@ describe('suggestion_panel', () => {
});

it('should display apply-changes prompt when changes not applied', async () => {
const { instance, lensStore } = await mountWithReduxStore(<SuggestionPanel {...defaultProps} />, {
const { instance, lensStore } = mountWithReduxStore(<SuggestionPanel {...defaultProps} />, {
preloadedState: {
...preloadedState,
visualization: {
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('suggestion_panel', () => {
});

it('should list passed in suggestions', async () => {
const { instance } = await mountWithReduxStore(<SuggestionPanel {...defaultProps} />, {
const { instance } = mountWithReduxStore(<SuggestionPanel {...defaultProps} />, {
preloadedState,
});

Expand Down Expand Up @@ -199,21 +199,19 @@ describe('suggestion_panel', () => {
});

it('should not update suggestions if current state is moved to staged preview', async () => {
const { instance, lensStore } = await mountWithReduxStore(
<SuggestionPanel {...defaultProps} />,
{ preloadedState }
);
const { instance, lensStore } = mountWithReduxStore(<SuggestionPanel {...defaultProps} />, {
preloadedState,
});
getSuggestionsMock.mockClear();
lensStore.dispatch(setState({ stagedPreview }));
instance.update();
expect(getSuggestionsMock).not.toHaveBeenCalled();
});

it('should update suggestions if staged preview is removed', async () => {
const { instance, lensStore } = await mountWithReduxStore(
<SuggestionPanel {...defaultProps} />,
{ preloadedState }
);
const { instance, lensStore } = mountWithReduxStore(<SuggestionPanel {...defaultProps} />, {
preloadedState,
});
getSuggestionsMock.mockClear();
lensStore.dispatch(setState({ stagedPreview, ...suggestionState }));
instance.update();
Expand All @@ -234,9 +232,7 @@ describe('suggestion_panel', () => {
});

it('should rollback suggestion if current panel is clicked', async () => {
const { instance, lensStore } = await mountWithReduxStore(
<SuggestionPanel {...defaultProps} />
);
const { instance, lensStore } = mountWithReduxStore(<SuggestionPanel {...defaultProps} />);

act(() => {
instance.find(SELECTORS.SUGGESTION_TILE_BUTTON).at(2).simulate('click');
Expand All @@ -261,7 +257,7 @@ describe('suggestion_panel', () => {
});

it('should dispatch visualization switch action if suggestion is clicked', async () => {
const { instance, lensStore } = await mountWithReduxStore(<SuggestionPanel {...defaultProps} />, {
const { instance, lensStore } = mountWithReduxStore(<SuggestionPanel {...defaultProps} />, {
preloadedState,
});

Expand Down Expand Up @@ -315,7 +311,7 @@ describe('suggestion_panel', () => {

mockDatasource.toExpression.mockReturnValue('datasource_expression');

const { instance } = await mountWithReduxStore(<SuggestionPanel {...defaultProps} />, {
const { instance } = mountWithReduxStore(<SuggestionPanel {...defaultProps} />, {
preloadedState,
});

Expand Down Expand Up @@ -343,14 +339,14 @@ describe('suggestion_panel', () => {
},
};

const { instance } = await mountWithReduxStore(<SuggestionPanel {...defaultProps} />, {
const { instance } = mountWithReduxStore(<SuggestionPanel {...defaultProps} />, {
preloadedState: newPreloadedState,
});
expect(instance.html()).toEqual(null);
});

it('should hide the selections when the accordion is hidden', async () => {
const { instance } = await mountWithReduxStore(<SuggestionPanel {...defaultProps} />);
const { instance } = mountWithReduxStore(<SuggestionPanel {...defaultProps} />);
expect(instance.find(EuiAccordion)).toHaveLength(1);
act(() => {
instance.find(EuiAccordion).at(0).simulate('change');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ describe('workspace_panel', () => {

const visualizationShowing = () => instance.exists(expressionRendererMock);

const mounted = await mountWithReduxStore(
const mounted = mountWithReduxStore(
<WorkspacePanel
{...defaultProps}
datasourceMap={{
Expand Down Expand Up @@ -431,7 +431,7 @@ describe('workspace_panel', () => {
mockDatasource.getLayers.mockReturnValue(['first']);
const props = defaultProps;

const mounted = await mountWithReduxStore(
const mounted = mountWithReduxStore(
<WorkspacePanel
{...props}
datasourceMap={{
Expand Down Expand Up @@ -467,7 +467,7 @@ describe('workspace_panel', () => {
mockDatasource.getLayers.mockReturnValue(['first']);
const props = defaultProps;

const mounted = await mountWithReduxStore(
const mounted = mountWithReduxStore(
<WorkspacePanel
{...props}
datasourceMap={{
Expand Down Expand Up @@ -505,7 +505,7 @@ describe('workspace_panel', () => {
mockDatasource.getLayers.mockReturnValue(['first']);
const props = defaultProps;

const mounted = await mountWithReduxStore(
const mounted = mountWithReduxStore(
<WorkspacePanel
{...props}
datasourceMap={{
Expand Down Expand Up @@ -540,7 +540,7 @@ describe('workspace_panel', () => {
mockDatasource.toExpression.mockReturnValue('datasource');
mockDatasource.getLayers.mockReturnValue(['table1']);

const mounted = await mountWithReduxStore(
const mounted = mountWithReduxStore(
<WorkspacePanel
{...defaultProps}
datasourceMap={{
Expand Down Expand Up @@ -585,7 +585,7 @@ describe('workspace_panel', () => {

expressionRendererMock = jest.fn((_arg) => <span />);

const mounted = await mountWithReduxStore(
const mounted = mountWithReduxStore(
<WorkspacePanel
{...defaultProps}
datasourceMap={{
Expand Down Expand Up @@ -629,7 +629,7 @@ describe('workspace_panel', () => {
.mockReturnValueOnce('datasource second');

expressionRendererMock = jest.fn((_arg) => <span />);
const mounted = await mountWithReduxStore(
const mounted = mountWithReduxStore(
<WorkspacePanel
{...defaultProps}
datasourceMap={{
Expand Down Expand Up @@ -687,7 +687,7 @@ describe('workspace_panel', () => {

const getUserMessages = jest.fn(() => messages);

const mounted = await mountWithReduxStore(
const mounted = mountWithReduxStore(
<WorkspacePanel
{...defaultProps}
getUserMessages={getUserMessages}
Expand Down Expand Up @@ -717,7 +717,7 @@ describe('workspace_panel', () => {
let userMessages = [] as UserMessage[];
const getUserMessageFn = jest.fn(() => userMessages);

const mounted = await mountWithReduxStore(
const mounted = mountWithReduxStore(
<WorkspacePanel
{...defaultProps}
getUserMessages={getUserMessageFn}
Expand Down Expand Up @@ -786,7 +786,7 @@ describe('workspace_panel', () => {
const mockAddUserMessages = jest.fn(() => mockRemoveUserMessages);
const mockGetUserMessages = jest.fn<UserMessage[], unknown[]>(() => []);

const mounted = await mountWithReduxStore(
const mounted = mountWithReduxStore(
<WorkspacePanel
{...defaultProps}
datasourceMap={{
Expand Down Expand Up @@ -814,7 +814,7 @@ describe('workspace_panel', () => {
first: mockDatasource.publicAPIMock,
};

const mounted = await mountWithReduxStore(
const mounted = mountWithReduxStore(
<WorkspacePanel
{...defaultProps}
datasourceMap={{
Expand Down Expand Up @@ -844,7 +844,7 @@ describe('workspace_panel', () => {
framePublicAPI.datasourceLayers = {
first: mockDatasource.publicAPIMock,
};
const mounted = await mountWithReduxStore(
const mounted = mountWithReduxStore(
<WorkspacePanel
{...defaultProps}
datasourceMap={{
Expand Down
16 changes: 8 additions & 8 deletions x-pack/platform/plugins/shared/lens/public/mocks/store_mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function makeLensStore({
}: {
storeDeps?: LensStoreDeps;
preloadedState?: Partial<LensAppState>;
}) {
} = {}) {
const data = storeDeps.lensServices.data;
const store = makeConfigureStore(storeDeps, {
lens: {
Expand All @@ -119,10 +119,10 @@ export function makeLensStore({
export interface MountStoreProps {
storeDeps?: LensStoreDeps;
preloadedState?: Partial<LensAppState>;
dispatch?: jest.Mock;
}

export const mountWithReduxStore = async (
// legacy enzyme usage: remove when all tests are migrated to @testing-library/react
export const mountWithReduxStore = (
component: React.ReactElement,
store?: MountStoreProps,
options?: {
Expand All @@ -131,12 +131,12 @@ export const mountWithReduxStore = async (
attachTo?: HTMLElement;
}
) => {
const { store: lensStore, deps } = makeLensStore(store || {});
const { store: lensStore, deps } = makeLensStore(store);

let wrappingComponent: React.FC<PropsWithChildren<{}>> = ({ children }) => (
<Provider store={lensStore}>{children}</Provider>
);
if (options?.wrappingComponent) {
if (options?.wrappingComponent) {
wrappingComponent = ({ children }) => {
return options?.wrappingComponent?.({
...options?.wrappingComponentProps,
Expand All @@ -146,9 +146,9 @@ export const mountWithReduxStore = async (
}

const instance = mountWithProviders(component, {
...options,
wrappingComponent,
} as unknown as ReactWrapper);
...options,
wrappingComponent,
} as unknown as ReactWrapper);

return { instance, lensStore, deps };
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { layerTypes } from '../../common/layer_types';
describe('lensSlice', () => {
let store: EnhancedStore<{ lens: LensAppState }>;
beforeEach(() => {
store = makeLensStore({}).store;
store = makeLensStore().store;
jest.clearAllMocks();
});
const customQuery = { query: 'custom' } as Query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const renderWithProviders = (
return rtlRender;
};

// legacy enzyme usage: remove when all tests are migrated to @testing-library/react
export const mountWithProviders = (component: React.ReactElement, options?: MountRendererProps) => {
const { wrappingComponent, wrappingComponentProps } = options || {};

Expand Down

0 comments on commit 230f070

Please sign in to comment.