Skip to content

Commit

Permalink
fix: update and fix jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 committed Sep 4, 2023
1 parent 599e698 commit 97df2cc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
20 changes: 19 additions & 1 deletion src/components/manage/Blocks/Group/Edit.test.jsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -15,6 +15,21 @@ const store = mockStore({
},
});

jest.mock('@plone/volto/components', () => ({
BlocksForm: jest.fn(() => <div className="blocks-form">RenderBlocks</div>),
Icon: () => <div>Icon</div>,
SidebarPortal: () => <div>SidebarPortal</div>,
BlocksToolbar: () => <div>BlocksToolbar</div>,
BlockDataForm: () => <div>BlockDataForm</div>,
RenderBlocks: jest.fn(() => <div>RenderBlocks</div>),
}));

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();
Expand All @@ -41,6 +56,7 @@ describe('Edit', () => {
pathname: '/',
selected: true,
manage: true,
variation: {},
};

it('should render without crashing', () => {
Expand Down Expand Up @@ -101,6 +117,7 @@ describe('Edit', () => {
pathname: '/',
selected: true,
manage: true,
variation: {},
};
const mockOnFocusPreviousBlock = jest.fn();
const mockOnFocusNextBlock = jest.fn();
Expand Down Expand Up @@ -163,6 +180,7 @@ describe('Edit', () => {
pathname: '/',
selected: true,
manage: true,
variation: {},
};
const mockOnFocusPreviousBlock = jest.fn();
const mockOnFocusNextBlock = jest.fn();
Expand Down
13 changes: 12 additions & 1 deletion src/components/manage/Blocks/Group/View.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import '@testing-library/jest-dom/extend-expect';

jest.mock('@plone/volto/components', () => ({
RenderBlocks: jest.fn(() => <div>RenderBlocks</div>),
BodyComponent: () => <div>BodyComponent</div>,
}));

jest.mock('@plone/volto/helpers', () => ({
withBlockExtensions: jest.fn((Component) => Component),
}));

describe('View', () => {
Expand All @@ -15,6 +20,7 @@ describe('View', () => {
data: {},
metadata: {},
properties: {},
variation: {},
};
const component = renderer.create(<View {...props} />);

Expand All @@ -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(<View {...props} />);
expect(container.querySelector('div')).toBeInTheDocument();
Expand All @@ -40,6 +49,7 @@ describe('View', () => {
data: { key: 'value' },
},
properties: {},
variation: {},
};
const { container } = render(<View {...props} />);
expect(container.querySelector('section')).toBeInTheDocument();
Expand All @@ -55,6 +65,7 @@ describe('View', () => {
},
metadata: { meta: 'data' },
properties: { prop: 'erty' },
variation: {},
};
render(<View {...props} />);
expect(RenderBlocks).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ exports[`Edit should render without crashing 1`] = `
>
Section
</legend>
<div
className="blocks-form"
>
<fieldset
className="invisible"
disabled={false}
/>
RenderBlocks
</div>
<div>
BlocksToolbar
</div>
<div>
SidebarPortal
</div>
</fieldset>
`;

0 comments on commit 97df2cc

Please sign in to comment.