|
| 1 | +import { jest } from '@jest/globals'; |
| 2 | +import configureStore from 'redux-mock-store'; |
| 3 | +import thunk from 'redux-thunk'; |
| 4 | +import { blocksConfig } from '@plone/volto/config/Blocks'; |
| 5 | +import installSlate from '@plone/volto-slate/index'; |
| 6 | + |
| 7 | +var mockSemanticComponents = jest.requireActual('semantic-ui-react'); |
| 8 | +var mockComponents = jest.requireActual('@plone/volto/components'); |
| 9 | +var config = jest.requireActual('@plone/volto/registry').default; |
| 10 | + |
| 11 | +config.blocks.blocksConfig = { |
| 12 | + ...blocksConfig, |
| 13 | + ...config.blocks.blocksConfig, |
| 14 | +}; |
| 15 | + |
| 16 | +jest.doMock('semantic-ui-react', () => ({ |
| 17 | + __esModule: true, |
| 18 | + ...mockSemanticComponents, |
| 19 | + Popup: ({ content, trigger }) => { |
| 20 | + return ( |
| 21 | + <div className="popup"> |
| 22 | + <div className="trigger">{trigger}</div> |
| 23 | + <div className="content">{content}</div> |
| 24 | + </div> |
| 25 | + ); |
| 26 | + }, |
| 27 | +})); |
| 28 | + |
| 29 | +jest.doMock('@plone/volto/components', () => { |
| 30 | + return { |
| 31 | + __esModule: true, |
| 32 | + ...mockComponents, |
| 33 | + SidebarPortal: ({ children }) => <div id="sidebar">{children}</div>, |
| 34 | + }; |
| 35 | +}); |
| 36 | + |
| 37 | +jest.doMock('@plone/volto/registry', () => |
| 38 | + [installSlate].reduce((acc, apply) => apply(acc), config), |
| 39 | +); |
| 40 | + |
| 41 | +const mockStore = configureStore([thunk]); |
| 42 | + |
| 43 | +global.fetch = jest.fn(() => |
| 44 | + Promise.resolve({ |
| 45 | + json: () => Promise.resolve({}), |
| 46 | + }), |
| 47 | +); |
| 48 | + |
| 49 | +global.store = mockStore({ |
| 50 | + intl: { |
| 51 | + locale: 'en', |
| 52 | + messages: {}, |
| 53 | + formatMessage: jest.fn(), |
| 54 | + }, |
| 55 | + content: { |
| 56 | + create: {}, |
| 57 | + subrequests: [], |
| 58 | + }, |
| 59 | + connected_data_parameters: {}, |
| 60 | + screen: { |
| 61 | + page: { |
| 62 | + width: 768, |
| 63 | + }, |
| 64 | + }, |
| 65 | +}); |
0 commit comments