From eddaf668e104b6ee4c65035c4626dd46d9e27cd0 Mon Sep 17 00:00:00 2001 From: Yury Saukou Date: Tue, 26 Nov 2024 18:38:05 +0400 Subject: [PATCH] updates --- .../OrganizationVersionView.test.js | 14 +++++++ .../useVersionWrappedRowFormatter/styles.css | 2 +- .../useVersionWrappedRowFormatter.test.js | 41 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/common/hooks/useVersionWrappedRowFormatter/useVersionWrappedRowFormatter.test.js diff --git a/src/Organizations/OrganizationVersion/OrganizationVersionView/OrganizationVersionView.test.js b/src/Organizations/OrganizationVersion/OrganizationVersionView/OrganizationVersionView.test.js index a54824b5..63b2450f 100644 --- a/src/Organizations/OrganizationVersion/OrganizationVersionView/OrganizationVersionView.test.js +++ b/src/Organizations/OrganizationVersion/OrganizationVersionView/OrganizationVersionView.test.js @@ -8,6 +8,7 @@ import { render, screen, } from '@folio/jest-config-stripes/testing-library/react'; +import { useCategories } from '@folio/stripes-acq-components'; import { organization, @@ -16,6 +17,11 @@ import { import { ORGANIZATION_VERSIONS_VIEW_ROUTE } from '../../../common/constants'; import { OrganizationVersionView } from './OrganizationVersionView'; +jest.mock('@folio/stripes-acq-components', () => ({ + ...jest.requireActual('@folio/stripes-acq-components'), + useCategories: jest.fn(), +})); + const { organizationSnapshot } = organizationAuditEvent; const queryClient = new QueryClient(); @@ -40,6 +46,14 @@ const renderOrganizationVersionView = (props = {}) => render( ); describe('OrganizationVersion', () => { + beforeEach(() => { + useCategories.mockReturnValue({ categories: [{ id: 'f52ceea4-8e35-404b-9ebd-5c7db6613195', value: 'cat' }] }); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + it('should render version history view', async () => { renderOrganizationVersionView(); diff --git a/src/common/hooks/useVersionWrappedRowFormatter/styles.css b/src/common/hooks/useVersionWrappedRowFormatter/styles.css index 32c37302..69d7cc00 100644 --- a/src/common/hooks/useVersionWrappedRowFormatter/styles.css +++ b/src/common/hooks/useVersionWrappedRowFormatter/styles.css @@ -3,4 +3,4 @@ background-color: mark; margin: 0.15rem 0; } -} \ No newline at end of file +} diff --git a/src/common/hooks/useVersionWrappedRowFormatter/useVersionWrappedRowFormatter.test.js b/src/common/hooks/useVersionWrappedRowFormatter/useVersionWrappedRowFormatter.test.js new file mode 100644 index 00000000..f8a9b43b --- /dev/null +++ b/src/common/hooks/useVersionWrappedRowFormatter/useVersionWrappedRowFormatter.test.js @@ -0,0 +1,41 @@ +import { renderHook } from '@folio/jest-config-stripes/testing-library/react'; + +import { VersionViewContext } from '@folio/stripes-acq-components'; + +import { useVersionWrappedRowFormatter } from './useVersionWrappedRowFormatter'; + +const versionViewContext = { paths: ['testName[0]'] }; + +const getWrapper = (contextValue = {}) => ({ children }) => ( + + {children} + +); + +const mockBaseRowFormatter = ({ rowClass }) => ({ rowClass }); + +describe('useVersionWrappedRowFormatter', () => { + it('should return version wrapped row formatter if versionContext and name are provided', () => { + const { result } = renderHook(() => useVersionWrappedRowFormatter({ + baseRowFormatter: mockBaseRowFormatter, + name: 'testName', + }), { wrapper: getWrapper() }); + + const rowFormatter = result.current; + const row = { rowClass: 'testClass', rowIndex: 0 }; + + expect(rowFormatter(row).rowClass.includes('mark')).toBeTruthy(); + }); + + it('should not add mark class if row is not updated', () => { + const { result } = renderHook(() => useVersionWrappedRowFormatter({ + baseRowFormatter: mockBaseRowFormatter, + name: 'testName', + }), { wrapper: getWrapper({ paths: ['otherName[0]'] }) }); + + const rowFormatter = result.current; + const row = { rowClass: 'testClass', rowIndex: 0 }; + + expect(rowFormatter(row).rowClass.includes('mark')).toBeFalsy(); + }); +});