Skip to content

Commit

Permalink
normalized slug
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Oct 18, 2024
1 parent bbce1a4 commit 98f835b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tests/build-post-list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ describe('buildPostList', () => {
expect(output).toHaveProperty('about');
expect(output).toHaveProperty('docsTree');

const blogEntry = output.blog.find(item => item.slug === '/blog/release-notes-2.1.0');
const expectedSlug = normalize('/blog/release-notes-2.1.0');
const blogEntry = output.blog.find(item => normalize(item.slug) === expectedSlug);
console.log(blogEntry);

expect(blogEntry).toBeDefined();
expect(blogEntry.title).toBe('Release Notes 2.1.0');
});
Expand All @@ -72,8 +74,8 @@ describe('buildPostList', () => {
await buildPostList(postDirectories, tempDir, writeFilePath);

const output = JSON.parse(readFileSync(writeFilePath, 'utf-8'));
const firstReleaseNote = output.blog.find(item => item.slug === '/blog/release-notes-2.1.0');
const secondReleaseNote = output.blog.find(item => item.slug === '/blog/release-notes-2.1.1');
const firstReleaseNote = output.blog.find(item => normalize(item.slug) === normalize('/blog/release-notes-2.1.0'));
const secondReleaseNote = output.blog.find(item => normalize(item.slug) === normalize('/blog/release-notes-2.1.1'));

expect(firstReleaseNote).toBeDefined();
expect(firstReleaseNote.title).toBe('Release Notes 2.1.0');
Expand All @@ -89,12 +91,12 @@ describe('buildPostList', () => {

it('handles heading ids like {# myHeadingId}', () => {
const input = '## My Heading {#custom-id}';
expect(slugifyToC(input)).toBe('custom-id');
expect(slugifyToC(input)).toBe(normalize('custom-id'));
});

it('handles heading ids like {<a name="myHeadingId"/>}', () => {
const input = '## My Heading {<a name="custom-anchor-id"/>}';
expect(slugifyToC(input)).toBe('custom-anchor-id');
expect(slugifyToC(input)).toBe(normalize('custom-anchor-id'));
});

it('handles empty strings', () => {
Expand Down

0 comments on commit 98f835b

Please sign in to comment.