Skip to content

Commit

Permalink
UIORGS-346 Add test for categories settings
Browse files Browse the repository at this point in the history
  • Loading branch information
usavkov-epam committed Aug 15, 2023
1 parent 6cad28b commit dd3790f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
File renamed without changes.
51 changes: 51 additions & 0 deletions src/Settings/CategorySettings/CategorySettings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { render } from '@testing-library/react';

import { ControlledVocab } from '@folio/stripes/smart-components';

import CategorySettings from './CategorySettings';

jest.mock('@folio/stripes-smart-components/lib/ControlledVocab', () => jest.fn(({
rowFilter,
label,
rowFilterFunction,
preCreateHook,
listSuppressor,
}) => (
<>
{label}
<div onChange={rowFilterFunction}>{rowFilter}</div>
<button
data-testid="button-new"
type="button"
onClick={() => {
preCreateHook();
listSuppressor();
}}
>
New
</button>
</>
)));

const stripesMock = {
connect: component => component,
hasPerm: jest.fn(() => true),
};

const renderCategorySettings = () => render(
<CategorySettings
stripes={stripesMock}
/>,
);

describe('CategorySettings', () => {
it('should check action suppression', () => {
renderCategorySettings();

const { actionSuppressor } = ControlledVocab.mock.calls[0][0];

expect(stripesMock.hasPerm).toHaveBeenCalled();
expect(actionSuppressor.edit()).toBeFalsy();
expect(actionSuppressor.delete()).toBeFalsy();
});
});
1 change: 1 addition & 0 deletions src/Settings/CategorySettings/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as CategorySettings } from './CategorySettings';
2 changes: 1 addition & 1 deletion src/Settings/SettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormattedMessage } from 'react-intl';

import { Settings } from '@folio/stripes/smart-components';

import CategorySettings from './CategorySettings';
import { CategorySettings } from './CategorySettings';
import { TypeSettings } from './TypeSettings';

const pages = [
Expand Down
10 changes: 10 additions & 0 deletions src/Settings/TypeSettings/TypeSettings.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { render, screen } from '@testing-library/react';

import { ControlledVocab } from '@folio/stripes/smart-components';

import TypeSettings from './TypeSettings';

jest.mock('@folio/stripes-smart-components/lib/ControlledVocab', () => jest.fn(({
Expand Down Expand Up @@ -49,4 +51,12 @@ describe('TypeSettings component', () => {
it('should display new button', async () => {
expect(screen.getByText('New')).toBeInTheDocument();
});

it('should check action suppression', () => {
const { actionSuppressor } = ControlledVocab.mock.calls[0][0];

expect(stripesMock.hasPerm).toHaveBeenCalled();
expect(actionSuppressor.edit()).toBeFalsy();
expect(actionSuppressor.delete()).toBeFalsy();
});
});

0 comments on commit dd3790f

Please sign in to comment.