From dae08212bad2e61e6a5d9fd2b993b39d3b10aabf Mon Sep 17 00:00:00 2001 From: Zak Burke Date: Tue, 14 May 2024 21:23:01 -0400 Subject: [PATCH 1/2] test --- .../TitleManager/TitleManager.test.js | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 src/components/TitleManager/TitleManager.test.js diff --git a/src/components/TitleManager/TitleManager.test.js b/src/components/TitleManager/TitleManager.test.js new file mode 100644 index 000000000..f51acf3db --- /dev/null +++ b/src/components/TitleManager/TitleManager.test.js @@ -0,0 +1,118 @@ +import { render, waitFor } from '@folio/jest-config-stripes/testing-library/react'; +import { createMemoryHistory } from 'history'; + +import TitleManager from './TitleManager'; +import Harness from '../../../test/jest/helpers/harness'; + +describe('TitleManager', () => { + it('renders a title with a default postfix', async () => { + const stripes = { + config: {}, + hasPerm: jest.fn(), + }; + + const page = 'record-application'; + + const history = createMemoryHistory(); + render( + + + <>thunder - chicken + + + ); + + await waitFor(() => expect(document.title).toBe(`${page} - FOLIO`)); + }); + + it('renders prefix, page, record, postfix', async () => { + const stripes = { + config: { + platformName: 'two mile' + }, + hasPerm: jest.fn(), + }; + + const prefix = 'pre' + const page = 'steve'; + const record = '8:41.5'; + + const history = createMemoryHistory(); + render( + + + <>thunder - chicken + + + ); + + await waitFor(() => expect(document.title).toBe(`${prefix}${page} - ${record} - ${stripes.config.platformName}`)); + }); + + + it('renders prefix, record, postfix', async () => { + const stripes = { + config: { + platformName: 'two mile' + }, + hasPerm: jest.fn(), + }; + + const prefix = 'pre' + const record = '8:41.5'; + + const history = createMemoryHistory(); + render( + + + <>thunder - chicken + + + ); + + await waitFor(() => expect(document.title).toBe(`${prefix}${record} - ${stripes.config.platformName}`)); + }); +}); + + + +// const APP = 'FOLIO'; + +// static defaultProps = { prefix: '' } + +// renderTitle = (currentTitle) => { +// const { prefix, page, record, stripes } = this.props; +// const postfix = stripes.config?.platformName || APP; + +// if (typeof currentTitle !== 'string') return ''; + +// const tokens = currentTitle.split(' - '); + +// /** +// * When there are 2 items - that means there are page and postfix. +// * If we don't clear the tokens[1] item then we'll have two postfixes - in tokens[1] and tokens[2] will be added later +// */ +// if (tokens.length === 2) { +// tokens[1] = ''; +// } + +// if (page) tokens[0] = page; +// if (record) tokens[1] = record; + +// tokens[2] = postfix; + +// return prefix + tokens +// .filter(t => t) +// .join(' - '); +// } + +// render() { +// return ( +// +// {this.props.children} +// +// ); +// } +// } + +// export default withStripes(TitleManager); From f283a5a12cd596baba5ecb32e16d1137daf27a1b Mon Sep 17 00:00:00 2001 From: Zak Burke Date: Thu, 16 May 2024 14:55:59 -0400 Subject: [PATCH 2/2] lint --- .../TitleManager/TitleManager.test.js | 51 ++----------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/src/components/TitleManager/TitleManager.test.js b/src/components/TitleManager/TitleManager.test.js index f51acf3db..f6b6af776 100644 --- a/src/components/TitleManager/TitleManager.test.js +++ b/src/components/TitleManager/TitleManager.test.js @@ -28,12 +28,12 @@ describe('TitleManager', () => { it('renders prefix, page, record, postfix', async () => { const stripes = { config: { - platformName: 'two mile' + platformName: 'two mile', }, hasPerm: jest.fn(), }; - const prefix = 'pre' + const prefix = 'pre'; const page = 'steve'; const record = '8:41.5'; @@ -53,12 +53,12 @@ describe('TitleManager', () => { it('renders prefix, record, postfix', async () => { const stripes = { config: { - platformName: 'two mile' + platformName: 'two mile', }, hasPerm: jest.fn(), }; - const prefix = 'pre' + const prefix = 'pre'; const record = '8:41.5'; const history = createMemoryHistory(); @@ -73,46 +73,3 @@ describe('TitleManager', () => { await waitFor(() => expect(document.title).toBe(`${prefix}${record} - ${stripes.config.platformName}`)); }); }); - - - -// const APP = 'FOLIO'; - -// static defaultProps = { prefix: '' } - -// renderTitle = (currentTitle) => { -// const { prefix, page, record, stripes } = this.props; -// const postfix = stripes.config?.platformName || APP; - -// if (typeof currentTitle !== 'string') return ''; - -// const tokens = currentTitle.split(' - '); - -// /** -// * When there are 2 items - that means there are page and postfix. -// * If we don't clear the tokens[1] item then we'll have two postfixes - in tokens[1] and tokens[2] will be added later -// */ -// if (tokens.length === 2) { -// tokens[1] = ''; -// } - -// if (page) tokens[0] = page; -// if (record) tokens[1] = record; - -// tokens[2] = postfix; - -// return prefix + tokens -// .filter(t => t) -// .join(' - '); -// } - -// render() { -// return ( -// -// {this.props.children} -// -// ); -// } -// } - -// export default withStripes(TitleManager);