Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
usavkov-epam committed Nov 26, 2024
1 parent ebc77ca commit eddaf66
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
render,
screen,
} from '@folio/jest-config-stripes/testing-library/react';
import { useCategories } from '@folio/stripes-acq-components';

import {
organization,
Expand All @@ -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();
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/common/hooks/useVersionWrappedRowFormatter/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
background-color: mark;
margin: 0.15rem 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -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 }) => (
<VersionViewContext.Provider value={{ ...versionViewContext, ...contextValue }}>
{children}
</VersionViewContext.Provider>
);

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();
});
});

0 comments on commit eddaf66

Please sign in to comment.