-
Notifications
You must be signed in to change notification settings - Fork 27.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { accumulateMetadata, MetadataItems } from './resolve-metadata' | ||
|
||
describe('accumulateMetadata', () => { | ||
describe('merge title', () => { | ||
it('should merge page title', async () => { | ||
const metadataItems: MetadataItems = [ | ||
[{ title: 'root' }, null], | ||
[{ title: 'layout' }, null], | ||
[{ title: 'page' }, null], | ||
] | ||
const metadata = await accumulateMetadata(metadataItems) | ||
expect(metadata).toMatchObject({ | ||
title: { absolute: 'page', template: null }, | ||
}) | ||
}) | ||
|
||
it('should merge page title', async () => { | ||
const metadataItems: MetadataItems = [ | ||
[{ title: 'root' }, null], | ||
[ | ||
{ title: { absolute: 'layout', template: '1st parent layout %s' } }, | ||
null, | ||
], | ||
[ | ||
{ title: { absolute: 'layout', template: '2nd parent layout %s' } }, | ||
null, | ||
], | ||
[null, null], // same level layout | ||
[{ title: 'page' }, null], | ||
] | ||
const metadata = await accumulateMetadata(metadataItems) | ||
expect(metadata).toMatchObject({ | ||
title: { absolute: '2nd parent layout page', template: null }, | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/next/src/lib/metadata/resolvers/resolve-title.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { resolveTitle } from './resolve-title' | ||
|
||
describe('resolveTitle', () => { | ||
it('should resolve nullable template as empty string title', () => { | ||
expect(resolveTitle('', null)).toEqual({ absolute: '', template: null }) | ||
expect(resolveTitle(null, null)).toEqual({ absolute: '', template: null }) | ||
}) | ||
|
||
it('should resolve title with template', () => { | ||
// returned template should equal the input title's template | ||
expect(resolveTitle('title', 'dash %s')).toEqual({ | ||
absolute: 'dash title', | ||
template: null, | ||
}) | ||
expect( | ||
resolveTitle({ default: 'title', template: '%s | absolute' }, 'dash %s') | ||
).toEqual({ absolute: 'dash title', template: '%s | absolute' }) | ||
expect( | ||
resolveTitle({ default: '', template: '%s | absolute' }, 'fake template') | ||
).toEqual({ absolute: 'fake template', template: '%s | absolute' }) | ||
}) | ||
}) |