From 97df2cc6ac5c3283707ff72bb3d4cd762d5a3b2f Mon Sep 17 00:00:00 2001 From: nileshgulia1 Date: Mon, 4 Sep 2023 12:42:13 +0530 Subject: [PATCH] fix: update and fix jest tests --- .../manage/Blocks/Group/Edit.test.jsx | 20 ++++++++++++++++++- .../manage/Blocks/Group/View.test.jsx | 13 +++++++++++- .../Group/__snapshots__/Edit.test.jsx.snap | 12 ++++++----- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/components/manage/Blocks/Group/Edit.test.jsx b/src/components/manage/Blocks/Group/Edit.test.jsx index 6c772f2..aa441db 100644 --- a/src/components/manage/Blocks/Group/Edit.test.jsx +++ b/src/components/manage/Blocks/Group/Edit.test.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import Edit from './Edit'; +import { default as Edit } from './Edit'; import configureStore from 'redux-mock-store'; import { Provider } from 'react-intl-redux'; import thunk from 'redux-thunk'; @@ -15,6 +15,21 @@ const store = mockStore({ }, }); +jest.mock('@plone/volto/components', () => ({ + BlocksForm: jest.fn(() =>
RenderBlocks
), + Icon: () =>
Icon
, + SidebarPortal: () =>
SidebarPortal
, + BlocksToolbar: () =>
BlocksToolbar
, + BlockDataForm: () =>
BlockDataForm
, + RenderBlocks: jest.fn(() =>
RenderBlocks
), +})); + +jest.mock('@plone/volto/helpers', () => ({ + withBlockExtensions: jest.fn((Component) => Component), + emptyBlocksForm: jest.fn(), + getBlocksLayoutFieldname: jest.fn(), +})); + describe('Edit', () => { const onChangeBlock = jest.fn(); const onChangeField = jest.fn(); @@ -41,6 +56,7 @@ describe('Edit', () => { pathname: '/', selected: true, manage: true, + variation: {}, }; it('should render without crashing', () => { @@ -101,6 +117,7 @@ describe('Edit', () => { pathname: '/', selected: true, manage: true, + variation: {}, }; const mockOnFocusPreviousBlock = jest.fn(); const mockOnFocusNextBlock = jest.fn(); @@ -163,6 +180,7 @@ describe('Edit', () => { pathname: '/', selected: true, manage: true, + variation: {}, }; const mockOnFocusPreviousBlock = jest.fn(); const mockOnFocusNextBlock = jest.fn(); diff --git a/src/components/manage/Blocks/Group/View.test.jsx b/src/components/manage/Blocks/Group/View.test.jsx index f9116b1..b9f96a0 100644 --- a/src/components/manage/Blocks/Group/View.test.jsx +++ b/src/components/manage/Blocks/Group/View.test.jsx @@ -7,6 +7,11 @@ import '@testing-library/jest-dom/extend-expect'; jest.mock('@plone/volto/components', () => ({ RenderBlocks: jest.fn(() =>
RenderBlocks
), + BodyComponent: () =>
BodyComponent
, +})); + +jest.mock('@plone/volto/helpers', () => ({ + withBlockExtensions: jest.fn((Component) => Component), })); describe('View', () => { @@ -15,6 +20,7 @@ describe('View', () => { data: {}, metadata: {}, properties: {}, + variation: {}, }; const component = renderer.create(); @@ -24,9 +30,12 @@ describe('View', () => { it('renders with default tag and without crashing', () => { const props = { - data: {}, + data: { + variation: {}, + }, metadata: {}, properties: {}, + variation: {}, }; const { container } = render(); expect(container.querySelector('div')).toBeInTheDocument(); @@ -40,6 +49,7 @@ describe('View', () => { data: { key: 'value' }, }, properties: {}, + variation: {}, }; const { container } = render(); expect(container.querySelector('section')).toBeInTheDocument(); @@ -55,6 +65,7 @@ describe('View', () => { }, metadata: { meta: 'data' }, properties: { prop: 'erty' }, + variation: {}, }; render(); expect(RenderBlocks).toHaveBeenCalledWith( diff --git a/src/components/manage/Blocks/Group/__snapshots__/Edit.test.jsx.snap b/src/components/manage/Blocks/Group/__snapshots__/Edit.test.jsx.snap index e526e26..ad4c1d1 100644 --- a/src/components/manage/Blocks/Group/__snapshots__/Edit.test.jsx.snap +++ b/src/components/manage/Blocks/Group/__snapshots__/Edit.test.jsx.snap @@ -13,14 +13,16 @@ exports[`Edit should render without crashing 1`] = ` > Section -
-
+ RenderBlocks +
+
+ BlocksToolbar +
+
+ SidebarPortal
`;