|
1 | 1 | import { describe, expect, test } from "vitest";
|
2 |
| -import { SidebarInputNodeT, SidebarT } from "../../types/sanity-schema"; |
| 2 | +import { DesignsystemSidebarSectionT, SidebarInputNodeT } from "@/types"; |
3 | 3 | import {
|
4 | 4 | generateSidebar,
|
5 | 5 | sortDeprecated,
|
@@ -50,7 +50,7 @@ const outputIndex = [
|
50 | 50 | { ...baseItem, kategori: "core", heading: "c", tag: "deprecated" as const },
|
51 | 51 | ];
|
52 | 52 |
|
53 |
| -const outputComplete: SidebarT = [ |
| 53 | +const outputComplete: DesignsystemSidebarSectionT = [ |
54 | 54 | {
|
55 | 55 | pages: [
|
56 | 56 | { slug: "/123", tag: "beta", heading: "f" },
|
@@ -90,4 +90,56 @@ describe("generateSidebar function", () => {
|
90 | 90 | test("generated output is correct", () => {
|
91 | 91 | expect(generateSidebar(input, "komponenter")).toEqual(outputComplete);
|
92 | 92 | });
|
| 93 | + |
| 94 | + test("should place standalone articles on top", () => { |
| 95 | + expect( |
| 96 | + generateSidebar( |
| 97 | + [ |
| 98 | + ...input, |
| 99 | + { |
| 100 | + ...baseItem, |
| 101 | + kategori: "standalone", |
| 102 | + heading: "B", |
| 103 | + }, |
| 104 | + { |
| 105 | + ...baseItem, |
| 106 | + kategori: "standalone", |
| 107 | + heading: "A", |
| 108 | + }, |
| 109 | + ], |
| 110 | + "komponenter", |
| 111 | + ), |
| 112 | + ).toEqual([ |
| 113 | + { slug: "/123", tag: "beta", heading: "A" }, |
| 114 | + { slug: "/123", tag: "beta", heading: "B" }, |
| 115 | + ...outputComplete, |
| 116 | + ]); |
| 117 | + }); |
| 118 | + |
| 119 | + test("should sort standalone articles by index", () => { |
| 120 | + expect( |
| 121 | + generateSidebar( |
| 122 | + [ |
| 123 | + ...input, |
| 124 | + { |
| 125 | + ...baseItem, |
| 126 | + kategori: "standalone", |
| 127 | + heading: "B", |
| 128 | + sidebarindex: 0, |
| 129 | + }, |
| 130 | + { |
| 131 | + ...baseItem, |
| 132 | + kategori: "standalone", |
| 133 | + heading: "A", |
| 134 | + sidebarindex: 1, |
| 135 | + }, |
| 136 | + ], |
| 137 | + "komponenter", |
| 138 | + ), |
| 139 | + ).toEqual([ |
| 140 | + { slug: "/123", tag: "beta", heading: "B" }, |
| 141 | + { slug: "/123", tag: "beta", heading: "A" }, |
| 142 | + ...outputComplete, |
| 143 | + ]); |
| 144 | + }); |
93 | 145 | });
|
0 commit comments