From 5a9c191d531f7c5d7ceb3884485215ad326b4321 Mon Sep 17 00:00:00 2001 From: Alin Voinea Date: Tue, 23 Dec 2025 17:58:35 +0200 Subject: [PATCH] test: Fix jest warnings --- Makefile | 2 +- docker-compose.yml | 1 - src/components/theme/Banner/View.jsx | 4 ++-- .../theme/Widgets/ContributorsViewWidget.jsx | 18 +++++++++--------- .../theme/Widgets/CreatorsViewWidget.jsx | 18 +++++++++--------- .../Widgets/NavigationBehaviorWidget.test.jsx | 2 +- .../ContributorsViewWidget.test.jsx.snap | 16 ++++++++-------- .../CreatorsViewWidget.test.jsx.snap | 16 ++++++++-------- .../components/theme/Comments/Comments.jsx | 4 ++-- .../components/theme/Header/Header.test.jsx | 15 +++++++++++++++ src/helpers/setupPrintView.test.js | 18 +----------------- 11 files changed, 56 insertions(+), 58 deletions(-) diff --git a/Makefile b/Makefile index 522b5771..e11782cf 100644 --- a/Makefile +++ b/Makefile @@ -90,7 +90,7 @@ cypress-run: ## Run cypress integration tests .PHONY: test test: ## Run jest tests - ${DOCKER_COMPOSE} run -e CI=1 frontend test + COMPOSE_IGNORE_ORPHANS=1 ${DOCKER_COMPOSE} run -e CI=1 -e BROWSERSLIST_IGNORE_OLD_DATA=1 frontend test .PHONY: test-update test-update: ## Update jest tests snapshots diff --git a/docker-compose.yml b/docker-compose.yml index ae185753..99d81ac5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: "3" services: backend: image: eeacms/plone-backend diff --git a/src/components/theme/Banner/View.jsx b/src/components/theme/Banner/View.jsx index 1f6a14a0..d123b1f1 100644 --- a/src/components/theme/Banner/View.jsx +++ b/src/components/theme/Banner/View.jsx @@ -183,7 +183,7 @@ const View = (props) => { /> )} {rssLinks?.map((rssLink, index) => ( - <> + { href={rssLink.href} target="_blank" /> - + ))} } diff --git a/src/components/theme/Widgets/ContributorsViewWidget.jsx b/src/components/theme/Widgets/ContributorsViewWidget.jsx index 3255137e..8dea0889 100644 --- a/src/components/theme/Widgets/ContributorsViewWidget.jsx +++ b/src/components/theme/Widgets/ContributorsViewWidget.jsx @@ -4,16 +4,16 @@ const ContributorsViewWidget = ({ value, content, children, className }) => { const resolvedValue = content?.contributors_fullname || value || []; return resolvedValue ? ( - {resolvedValue.map((item, key) => ( - <> - {key ? ', ' : ''} - - {children - ? children(item.title || item.token || item) - : item.title || item.token || item} + {resolvedValue.map((item, index) => { + const label = item?.title || item?.token || item; + const key = `${label}-${index}`; + return ( + + {index ? ', ' : ''} + {children ? children(label) : label} - - ))} + ); + })} ) : ( '' diff --git a/src/components/theme/Widgets/CreatorsViewWidget.jsx b/src/components/theme/Widgets/CreatorsViewWidget.jsx index 99d49426..98589b4d 100644 --- a/src/components/theme/Widgets/CreatorsViewWidget.jsx +++ b/src/components/theme/Widgets/CreatorsViewWidget.jsx @@ -4,16 +4,16 @@ const CreatorsViewWidget = ({ value, content, children, className }) => { const resolvedValue = content?.creators_fullname || value || []; return resolvedValue ? ( - {resolvedValue.map((item, key) => ( - <> - {key ? ', ' : ''} - - {children - ? children(item.title || item.token || item) - : item.title || item.token || item} + {resolvedValue.map((item, index) => { + const label = item?.title || item?.token || item; + const key = `${label}-${index}`; + return ( + + {index ? ', ' : ''} + {children ? children(label) : label} - - ))} + ); + })} ) : ( '' diff --git a/src/components/theme/Widgets/NavigationBehaviorWidget.test.jsx b/src/components/theme/Widgets/NavigationBehaviorWidget.test.jsx index 22560ad6..a66c53f2 100644 --- a/src/components/theme/Widgets/NavigationBehaviorWidget.test.jsx +++ b/src/components/theme/Widgets/NavigationBehaviorWidget.test.jsx @@ -101,7 +101,7 @@ jest.mock('@plone/volto/components/manage/Widgets/ObjectWidget', () => { // Mock semantic-ui-react components jest.mock('semantic-ui-react', () => { - const MockAccordion = ({ children, ...props }) => ( + const MockAccordion = ({ children, fluid, styled, ...props }) => (
{children}
diff --git a/src/components/theme/Widgets/__snapshots__/ContributorsViewWidget.test.jsx.snap b/src/components/theme/Widgets/__snapshots__/ContributorsViewWidget.test.jsx.snap index 84119a95..1271edef 100644 --- a/src/components/theme/Widgets/__snapshots__/ContributorsViewWidget.test.jsx.snap +++ b/src/components/theme/Widgets/__snapshots__/ContributorsViewWidget.test.jsx.snap @@ -4,12 +4,12 @@ exports[`ContributorsViewWidget renders a full vocabulary array view widget comp - + Foo - , + , Bar @@ -19,14 +19,14 @@ exports[`ContributorsViewWidget renders a full vocabulary array view widget comp - + Foo - , + , Bar @@ -38,12 +38,12 @@ exports[`ContributorsViewWidget renders a simple array view widget component 1`] - + foo - , + , bar @@ -53,12 +53,12 @@ exports[`ContributorsViewWidget renders a vocabulary array view widget component - + Foo - , + , Bar diff --git a/src/components/theme/Widgets/__snapshots__/CreatorsViewWidget.test.jsx.snap b/src/components/theme/Widgets/__snapshots__/CreatorsViewWidget.test.jsx.snap index c1002586..44105a83 100644 --- a/src/components/theme/Widgets/__snapshots__/CreatorsViewWidget.test.jsx.snap +++ b/src/components/theme/Widgets/__snapshots__/CreatorsViewWidget.test.jsx.snap @@ -4,12 +4,12 @@ exports[`CreatorsViewWidget renders a full vocabulary array view widget componen - + Foo - , + , Bar @@ -19,14 +19,14 @@ exports[`CreatorsViewWidget renders a full vocabulary array view widget componen - + Foo - , + , Bar @@ -38,12 +38,12 @@ exports[`CreatorsViewWidget renders a simple array view widget component 1`] = ` - + foo - , + , bar @@ -53,12 +53,12 @@ exports[`CreatorsViewWidget renders a vocabulary array view widget component 1`] - + Foo - , + , Bar diff --git a/src/customizations/volto/components/theme/Comments/Comments.jsx b/src/customizations/volto/components/theme/Comments/Comments.jsx index 8fae6e05..de07414d 100644 --- a/src/customizations/volto/components/theme/Comments/Comments.jsx +++ b/src/customizations/volto/components/theme/Comments/Comments.jsx @@ -438,8 +438,8 @@ class Comments extends Component { open={this.state.showEdit} onCancel={this.onEditCancel} onOk={this.onEditOk} - id={this.state.editId} - text={this.state.editText} + id={this.state.editId ?? ''} + text={this.state.editText ?? ''} /> {permissions.can_reply && (
diff --git a/src/customizations/volto/components/theme/Header/Header.test.jsx b/src/customizations/volto/components/theme/Header/Header.test.jsx index 7df871bb..02214fa4 100644 --- a/src/customizations/volto/components/theme/Header/Header.test.jsx +++ b/src/customizations/volto/components/theme/Header/Header.test.jsx @@ -26,6 +26,21 @@ beforeAll( await require('@plone/volto/helpers/Loadable/Loadable').__setLoadables(), ); +jest.mock('semantic-ui-react', () => { + const React = require('react'); + const actual = jest.requireActual('semantic-ui-react'); + const Dropdown = React.forwardRef(({ text, trigger, ...props }, ref) => { + const resolvedTrigger = + trigger || (typeof text === 'function' ? text() : text); + return ; + }); + Dropdown.Menu = actual.Dropdown.Menu; + Dropdown.Item = actual.Dropdown.Item; + Dropdown.Header = actual.Dropdown.Header; + Dropdown.Divider = actual.Dropdown.Divider; + return { ...actual, Dropdown }; +}); + describe('Header', () => { it('renders a header component with homepage_inverse_view layout', () => { const store = mockStore({ diff --git a/src/helpers/setupPrintView.test.js b/src/helpers/setupPrintView.test.js index 56944e27..412442f8 100644 --- a/src/helpers/setupPrintView.test.js +++ b/src/helpers/setupPrintView.test.js @@ -383,24 +383,11 @@ describe('setupPrintView', () => { }); document.body.appendChild(iframe); - // Mock the iframe to never fire load event, causing timeout - const originalSetTimeout = global.setTimeout; - let timeoutCallback; - global.setTimeout = jest.fn((callback, delay) => { - if (delay === 5000) { - // This is the iframe timeout - timeoutCallback = callback; - } - return originalSetTimeout(callback, delay); - }); - await act(async () => { setupPrintView(dispatch); // Trigger the iframe timeout to simulate error condition - if (timeoutCallback) { - timeoutCallback(); - } + jest.advanceTimersByTime(5000); for (let i = 0; i < 10; i++) { jest.runAllTimers(); @@ -410,9 +397,6 @@ describe('setupPrintView', () => { // Should still call print even with timeout expect(window.print).toHaveBeenCalled(); - - // Restore original setTimeout - global.setTimeout = originalSetTimeout; }); it('prevents multiple resets of print state', async () => {