Skip to content

Commit

Permalink
test update complete
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Oct 4, 2024
1 parent 0a94c17 commit a562e78
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
24 changes: 23 additions & 1 deletion tests/build-docs/buildNavTree.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { buildNavTree } = require('../../scripts/build-docs');

const {
basicNavItems,
sectionNavItems,
orphanNavItems,
missingFieldsNavItems,
invalidParentNavItems
invalidParentNavItems,
multipleSubsectionsNavItems
} = require('../fixtures/buildNavTreeData')

describe('buildNavTree', () => {
Expand Down Expand Up @@ -108,4 +110,24 @@ describe('buildNavTree', () => {
expect(error).toBeDefined();
});

it('should sort children within subsections based on weight', () => {
const result = buildNavTree(multipleSubsectionsNavItems);

const apiChildren = result['reference'].children.api.children;
expect(apiChildren[0].title).toBe('Authentication');
expect(apiChildren[1].title).toBe('Endpoints');
expect(apiChildren[2].title).toBe('Rate Limiting');

const specChildren = result['reference'].children.specification.children;
expect(specChildren[0].title).toBe('v1.0');
expect(specChildren[1].title).toBe('v2.0');
expect(specChildren[2].title).toBe('v3.0');

expect(apiChildren[0].weight).toBeLessThan(apiChildren[1].weight);
expect(apiChildren[1].weight).toBeLessThan(apiChildren[2].weight);

expect(specChildren[0].weight).toBeLessThan(specChildren[1].weight);
expect(specChildren[1].weight).toBeLessThan(specChildren[2].weight);
});

});
14 changes: 13 additions & 1 deletion tests/fixtures/buildNavTreeData.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@ module.exports = {
invalidParentNavItems: [
{ title: 'Valid Root', weight: 0, isRootSection: true, isSection: true, rootSectionId: 'valid-root', sectionWeight: 0, slug: '/docs/valid-root' },
{ title: 'Child with invalid parent', weight: 1, isSection: true, rootSectionId: 'valid-root', sectionId: 'child-invalid', parent: 'non-existent-parent', slug: '/docs/valid-root/child-invalid' },
]
],

multipleSubsectionsNavItems: [
{ title: 'Reference', weight: 0, isRootSection: true, isSection: true, rootSectionId: 'reference', sectionWeight: 0, slug: '/docs/reference' },
{ title: 'API', weight: 0, isSection: true, rootSectionId: 'reference', sectionId: 'api', parent: 'reference', slug: '/docs/reference/api' },
{ title: 'Endpoints', weight: 2, isSection: false, rootSectionId: 'reference', sectionId: 'api', slug: '/docs/reference/api/endpoints' },
{ title: 'Authentication', weight: 1, isSection: false, rootSectionId: 'reference', sectionId: 'api', slug: '/docs/reference/api/authentication' },
{ title: 'Rate Limiting', weight: 3, isSection: false, rootSectionId: 'reference', sectionId: 'api', slug: '/docs/reference/api/rate-limiting' },
{ title: 'Specification', weight: 1, isSection: true, rootSectionId: 'reference', sectionId: 'specification', parent: 'reference', slug: '/docs/reference/specification' },
{ title: 'v1.0', weight: 10, isSection: false, rootSectionId: 'reference', sectionId: 'specification', slug: '/docs/reference/specification/v1.0' },
{ title: 'v2.0', weight: 20, isSection: false, rootSectionId: 'reference', sectionId: 'specification', slug: '/docs/reference/specification/v2.0' },
{ title: 'v3.0', weight: 30, isSection: false, rootSectionId: 'reference', sectionId: 'specification', slug: '/docs/reference/specification/v3.0' }
]
};

0 comments on commit a562e78

Please sign in to comment.