Skip to content

Commit

Permalink
add tests for version dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Jun 3, 2024
1 parent 3f3b709 commit 1e570be
Show file tree
Hide file tree
Showing 37 changed files with 137,693 additions and 35 deletions.
1 change: 1 addition & 0 deletions fern/apis/navigation/definition/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ types:
- WithRedirect
properties:
type: literal<"version">
default: boolean
versionId: VersionId
child: VersionChild
availability: optional<Availability>
Expand Down
12 changes: 6 additions & 6 deletions packages/fdr-sdk/src/navigation/NodeCollector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface NavigationNodeWithMetadataAndParents {
}

export class NodeCollector {
private idToNode = new Map<FernNavigation.NodeId, NavigationNodeWithMetadata>();
private idToNode = new Map<FernNavigation.NodeId, NavigationNode>();
private slugToNode: Record<FernNavigation.Slug, NavigationNodeWithMetadataAndParents> = {};
private orphanedNodes: NavigationNodeWithMetadata[] = [];

Expand All @@ -62,6 +62,7 @@ export class NodeCollector {

constructor(rootNode: NavigationNode) {
traverseNavigation(rootNode, (node, _index, parents) => {
this.idToNode.set(node.id, node);
if (node.type === "sidebarRoot") {
this.#last = undefined;
this.#lastNeighboringNode = undefined;
Expand All @@ -70,7 +71,6 @@ export class NodeCollector {
if (!hasMetadata(node)) {
return;
}
this.idToNode.set(node.id, node);
const existing = this.slugToNode[node.slug];
if (existing == null) {
this.#setNode(node.slug, node, parents);
Expand Down Expand Up @@ -114,7 +114,7 @@ export class NodeCollector {
return this.getSlugMap();
}

public get(id: FernNavigation.NodeId): NavigationNodeWithMetadata | undefined {
public get(id: FernNavigation.NodeId): NavigationNode | undefined {
return this.idToNode.get(id);
}

Expand All @@ -133,8 +133,8 @@ export class NodeCollector {
});

public getVersionNodes = once((): FernNavigation.VersionNode[] => {
return Object.values(this.slugToNode)
.filter(({ node }) => node.type === "version")
.map(({ node }) => node as FernNavigation.VersionNode);
return [...this.idToNode.values()]
.filter((node): node is FernNavigation.VersionNode => node.type === "version")
.map((node) => node);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ function testNavigationConfigConverter(fixtureName: string): void {
expect(JSON.stringify([...pageIds], undefined, 2)).toMatchFileSnapshot(
`output/${fixtureName}/pageIds.json`,
);

expect(JSON.stringify(slugCollector.getVersionNodes(), undefined, 2)).toMatchFileSnapshot(
`output/${fixtureName}/versionNodes.json`,
);
});
});
}
Expand Down

Large diffs are not rendered by default.

110,827 changes: 110,827 additions & 0 deletions packages/fdr-sdk/src/navigation/__test__/fixtures/polytomic.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Loading

0 comments on commit 1e570be

Please sign in to comment.