Skip to content

Commit

Permalink
this is not a hook
Browse files Browse the repository at this point in the history
  • Loading branch information
gtibrett committed Mar 12, 2024
1 parent 5eb98e6 commit 2ed948b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export {default as SkipNav} from './SkipNav';
export {default as Tabs, TabContent} from './Tabs';
export {default as UkraineButton} from './UkraineButton';
export {default as useComponentDimensionsWithRef} from './useComponentDimensionsWithRef';
export {default as usePageTitle} from './usePageTitle';
export {default as usePageTitle} from './setPageTitle';
15 changes: 7 additions & 8 deletions src/usePageTitle.test.tsx → src/setPageTitle.test.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import {renderHook} from '@testing-library/react';
import usePageTitle from './usePageTitle';
import setPageTitle from './setPageTitle';

const siteTitle = 'site name';

describe('usePageTitle.ts', () => {
describe('setPageTitle.ts', () => {
test('set', async () => {
const title = 'test title';
renderHook(() => usePageTitle(title, siteTitle));
setPageTitle(title, siteTitle);

expect(document.title).toBe(`${title} - ${siteTitle}`);
});

test('env var based site title', async () => {
const title = 'test title';
const title = 'test title';

renderHook(() => usePageTitle(title));
setPageTitle(title);
expect(document.title).toBe(`${title}`);

process.env.REACT_APP_MUI_ADDITIONS_SITE_TITLE = 'site title';

renderHook(() => usePageTitle(title));
setPageTitle(title);
expect(document.title).toBe(`${title} - site title`);
});

test('failed set', async () => {
const title = <span>test title</span>;
renderHook(() => usePageTitle(String(title), siteTitle));
setPageTitle(String(title), siteTitle);

expect(document.title).toBe(`[object Object] - ${siteTitle}`);
});
Expand Down
2 changes: 1 addition & 1 deletion src/usePageTitle.ts → src/setPageTitle.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function usePageTitle(newTitle: string, siteTitle: string = process.env.REACT_APP_MUI_ADDITIONS_SITE_TITLE || '') {
export default function setPageTitle(newTitle: string, siteTitle: string = process.env.REACT_APP_MUI_ADDITIONS_SITE_TITLE || '') {
document.title = `${newTitle}${siteTitle ? ` - ${siteTitle}` : ''}`;
}

0 comments on commit 2ed948b

Please sign in to comment.