From d01bb489311b5e9b350faea310b2afb9c8fb3f44 Mon Sep 17 00:00:00 2001 From: Zak Burke Date: Thu, 5 Dec 2024 10:35:43 -0500 Subject: [PATCH 1/4] test ResetPasswordNotAvailableScreen (#1573) --- .../ResetPasswordNotAvailableScreen.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/components/ResetPasswordNotAvailableScreen/ResetPasswordNotAvailableScreen.test.js 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'); + }); +}); From a99341cdc7fa573825f8b0848ace31173e9eaeb2 Mon Sep 17 00:00:00 2001 From: Zak Burke Date: Thu, 5 Dec 2024 11:00:02 -0500 Subject: [PATCH 2/4] test BadRequestScreen (#1572) --- .../BadRequestScreen/BadRequestScreen.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/components/BadRequestScreen/BadRequestScreen.test.js 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/); + }); +}); + + From bb49c800f1e0645847f41fe49739807c7608bc5c Mon Sep 17 00:00:00 2001 From: Zak Burke Date: Thu, 5 Dec 2024 16:25:01 -0500 Subject: [PATCH 3/4] test IfInterface (#1574) --- src/components/IfInterface/IfInterface.js | 20 ++++++----- .../IfInterface/IfInterface.test.js | 33 +++++++++++++++++++ 2 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 src/components/IfInterface/IfInterface.test.js 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(); + }); +}); From 85a6b578ad47c65320e76f85578eced38b8885c9 Mon Sep 17 00:00:00 2001 From: Zak Burke Date: Fri, 6 Dec 2024 08:07:13 -0500 Subject: [PATCH 4/4] STCOR-921 typo: add missing whitespace (#1575) Refs STCOR-921 --- .../SessionEventContainer/FixedLengthSessionWarning.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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;