Skip to content

Commit

Permalink
fix: Fix links withpagePerSection (#1715)
Browse files Browse the repository at this point in the history
Fixes #1702
  • Loading branch information
mitsuruog authored Nov 17, 2020
1 parent 2b7bfe2 commit 3e2ff01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/client/utils/__tests__/processSections.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const sections = deepfreeze([
const options = { useRouterLinks: false, hashPath: [] };

describe('processSections', () => {
it('should recursively process all sections and components', () => {
test('should recursively process all sections and components', () => {
const result = processSections(sections, options);
const sectionsExpected = result[0].sections || [];
const comp = sectionsExpected.length
Expand All @@ -33,9 +33,17 @@ describe('processSections', () => {
expect(comp?.href).toBe('/#button');
});

it('should set visibleName property on each section', () => {
test('should set visibleName property on each section', () => {
const result = processSections(sections, options);
const sectionsExpected = result[0].sections || [];
expect(sectionsExpected[0].visibleName).toBe('Components');
});

test('should recursively process all nested sections when useRouterLinks is true has passed', () => {
const result = processSections([{ name: 'Component', sections: [{ name: 'Button' }] }], {
useRouterLinks: true,
});
expect(result?.[0].href).toBe('/#/Component');
expect(result?.[0].sections?.[0].href).toBe('/#/Component/Button');
});
});
4 changes: 2 additions & 2 deletions src/client/utils/processSections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export default function processSections(
sections: Rsg.Section[],
{ useRouterLinks, useHashId = false, hashPath = [] }: HrefOptions
): Rsg.Section[] {
return sections.map(section => {
return sections.map((section) => {
const options = {
useRouterLinks,
useRouterLinks: Boolean(useRouterLinks && section.name),
useHashId: section.sectionDepth === 0,
hashPath: [...hashPath, section.name ? section.name : '-'],
};
Expand Down

0 comments on commit 3e2ff01

Please sign in to comment.