diff --git a/src/components/BadRequestScreen/BadRequestScreen.test.js b/src/components/BadRequestScreen/BadRequestScreen.test.js new file mode 100644 index 000000000..9fa418b16 --- /dev/null +++ b/src/components/BadRequestScreen/BadRequestScreen.test.js @@ -0,0 +1,16 @@ +import { render, screen } from '@folio/jest-config-stripes/testing-library/react'; + +import BadRequestScreen from './BadRequestScreen'; + +jest.mock('../../Pluggable', () => (props) => props.children); + +describe('BadRequestScreen', () => { + it('renders expected message', () => { + render(); + + screen.getByText('stripes-core.front.error.header'); + screen.getByText(/stripes-core.front.error.general.message/); + }); +}); + + diff --git a/src/components/IfInterface/IfInterface.js b/src/components/IfInterface/IfInterface.js index 78edb9435..cd7f9acdc 100644 --- a/src/components/IfInterface/IfInterface.js +++ b/src/components/IfInterface/IfInterface.js @@ -1,14 +1,16 @@ -import React from 'react'; import PropTypes from 'prop-types'; -import { StripesContext } from '../../StripesContext'; +import { useStripes } from '../../StripesContext'; -const IfInterface = ({ children, name, version }) => ( - - {stripes => ( - stripes.hasInterface(name, version) ? children : null - )} - -); +const IfInterface = ({ children, name, version }) => { + const stripes = useStripes(); + const hasInterface = stripes.hasInterface(name, version); + + if (typeof children === 'function') { + return children({ hasInterface }); + } + + return hasInterface ? children : null; +}; IfInterface.propTypes = { children: PropTypes.node, diff --git a/src/components/IfInterface/IfInterface.test.js b/src/components/IfInterface/IfInterface.test.js new file mode 100644 index 000000000..430df9222 --- /dev/null +++ b/src/components/IfInterface/IfInterface.test.js @@ -0,0 +1,33 @@ +import { render, screen } from '@folio/jest-config-stripes/testing-library/react'; + +import { useStripes } from '../../StripesContext'; +import Stripes from '../../Stripes'; +import IfInterface from './IfInterface'; + +jest.mock('../../StripesContext'); +const stripes = new Stripes({ + discovery: { + interfaces: { + foo: '1.0' + } + }, + logger: { + log: jest.fn(), + } +}); + +// IfInterface is just a component version of Stripes::hasInterface +// See more extensive tests there. +describe('IfInterface', () => { + it('returns true if interface is present', () => { + useStripes.mockReturnValue(stripes); + render(monkey); + expect(screen.queryByText(/monkey/)).toBeTruthy(); + }); + + it('returns false if interface is absent', () => { + useStripes.mockReturnValue(stripes); + render(monkey); + expect(screen.queryByText(/monkey/)).toBeFalsy(); + }); +}); diff --git a/src/components/ResetPasswordNotAvailableScreen/ResetPasswordNotAvailableScreen.test.js b/src/components/ResetPasswordNotAvailableScreen/ResetPasswordNotAvailableScreen.test.js new file mode 100644 index 000000000..fd2211747 --- /dev/null +++ b/src/components/ResetPasswordNotAvailableScreen/ResetPasswordNotAvailableScreen.test.js @@ -0,0 +1,14 @@ +import { render, screen } from '@folio/jest-config-stripes/testing-library/react'; + +import BadRequestScreen from './ResetPasswordNotAvailableScreen'; + +jest.mock('../../Pluggable', () => (props) => props.children); + +describe('ResetPasswordNotAvailableScreen', () => { + it('renders expected message', () => { + render(); + + screen.getByText('stripes-core.front.error.header'); + screen.getByText('stripes-core.front.error.setPassword.message'); + }); +}); diff --git a/src/components/SessionEventContainer/FixedLengthSessionWarning.js b/src/components/SessionEventContainer/FixedLengthSessionWarning.js index 8871979e4..df6097add 100644 --- a/src/components/SessionEventContainer/FixedLengthSessionWarning.js +++ b/src/components/SessionEventContainer/FixedLengthSessionWarning.js @@ -49,7 +49,7 @@ const FixedLengthSessionWarning = () => { return '00:00'; }; - return {timestampFormatter()}; + return {timestampFormatter()}; }; export default FixedLengthSessionWarning;