From dd3790f32f85cda2bf89b28b468a2eec2792d649 Mon Sep 17 00:00:00 2001 From: Yury Saukou Date: Tue, 15 Aug 2023 14:30:01 +0400 Subject: [PATCH] UIORGS-346 Add test for categories settings --- .../CategorySettings.js | 0 .../CategorySettings/CategorySettings.test.js | 51 +++++++++++++++++++ src/Settings/CategorySettings/index.js | 1 + src/Settings/SettingsPage.js | 2 +- .../TypeSettings/TypeSettings.test.js | 10 ++++ 5 files changed, 63 insertions(+), 1 deletion(-) rename src/Settings/{ => CategorySettings}/CategorySettings.js (100%) create mode 100644 src/Settings/CategorySettings/CategorySettings.test.js create mode 100644 src/Settings/CategorySettings/index.js diff --git a/src/Settings/CategorySettings.js b/src/Settings/CategorySettings/CategorySettings.js similarity index 100% rename from src/Settings/CategorySettings.js rename to src/Settings/CategorySettings/CategorySettings.js diff --git a/src/Settings/CategorySettings/CategorySettings.test.js b/src/Settings/CategorySettings/CategorySettings.test.js new file mode 100644 index 00000000..96e8c62d --- /dev/null +++ b/src/Settings/CategorySettings/CategorySettings.test.js @@ -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} +
{rowFilter}
+ + +))); + +const stripesMock = { + connect: component => component, + hasPerm: jest.fn(() => true), +}; + +const renderCategorySettings = () => render( + , +); + +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(); + }); +}); diff --git a/src/Settings/CategorySettings/index.js b/src/Settings/CategorySettings/index.js new file mode 100644 index 00000000..3e7dfc8d --- /dev/null +++ b/src/Settings/CategorySettings/index.js @@ -0,0 +1 @@ +export { default as CategorySettings } from './CategorySettings'; diff --git a/src/Settings/SettingsPage.js b/src/Settings/SettingsPage.js index d3737b1a..65d7c8d4 100644 --- a/src/Settings/SettingsPage.js +++ b/src/Settings/SettingsPage.js @@ -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 = [ diff --git a/src/Settings/TypeSettings/TypeSettings.test.js b/src/Settings/TypeSettings/TypeSettings.test.js index e07f814c..499e8e4b 100644 --- a/src/Settings/TypeSettings/TypeSettings.test.js +++ b/src/Settings/TypeSettings/TypeSettings.test.js @@ -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(({ @@ -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(); + }); });