|
1 | | -import { vi } from 'vitest' |
| 1 | +import { vi } from "vitest"; |
2 | 2 | import { createBranch, createBranches, createRoutes } from "../src/routing.js"; |
3 | 3 | import type { RouteDefinition } from "../src/index.js"; |
4 | 4 |
|
@@ -174,7 +174,6 @@ describe("createRoutes should", () => { |
174 | 174 | expect(match).not.toBeNull(); |
175 | 175 | expect(match.path).toBe("/foo/123/bar/solid.html"); |
176 | 176 | }); |
177 | | - |
178 | 177 | }); |
179 | 178 |
|
180 | 179 | describe(`expand optional parameters`, () => { |
@@ -564,4 +563,53 @@ describe("createBranches should", () => { |
564 | 563 |
|
565 | 564 | expect(branchPaths).toEqual(["/root/%E3%81%BB%E3%81%92/:ふが/*ぴよ"]); |
566 | 565 | }); |
| 566 | + |
| 567 | + describe(`traverse slots`, () => { |
| 568 | + test("with no children", () => { |
| 569 | + const branches = createBranches({ |
| 570 | + path: "root", |
| 571 | + children: { |
| 572 | + path: "nested", |
| 573 | + slots: { nestedSlot: {} } |
| 574 | + }, |
| 575 | + slots: { rootSlot: {} } |
| 576 | + }); |
| 577 | + |
| 578 | + const root = branches[0].routes.find(r => r.originalPath === "root")!; |
| 579 | + expect(root.slots).toHaveProperty("rootSlot"); |
| 580 | + const rootSlot = root.slots!.rootSlot; |
| 581 | + expect(rootSlot.length).toBe(1); |
| 582 | + expect(rootSlot[0].routes.length).toBe(1); |
| 583 | + expect(rootSlot[0].routes[0].pattern).toEqual("/root"); |
| 584 | + |
| 585 | + const nested = branches[0].routes.find(r => r.originalPath === "nested")!; |
| 586 | + expect(nested.slots).toHaveProperty("nestedSlot"); |
| 587 | + const nestedSlot = nested.slots!.nestedSlot; |
| 588 | + expect(nestedSlot.length).toBe(1); |
| 589 | + expect(nestedSlot[0].routes.length).toBe(1); |
| 590 | + expect(nestedSlot[0].routes[0].pattern).toEqual("/root/nested"); |
| 591 | + }); |
| 592 | + |
| 593 | + test("with children", () => { |
| 594 | + const branches = createBranches({ |
| 595 | + path: "root", |
| 596 | + children: { |
| 597 | + path: "nested", |
| 598 | + slots: { nestedSlot: { children: [{ path: "one" }, { path: "two" }] } } |
| 599 | + }, |
| 600 | + slots: { rootSlot: { children: [{ path: "one" }, { path: "two" }] } } |
| 601 | + }); |
| 602 | + |
| 603 | + const rootSlot = branches[0].routes.find(r => r.originalPath === "root")!.slots!.rootSlot; |
| 604 | + expect(rootSlot.length).toBe(2); |
| 605 | + expect(rootSlot[1].routes.length).toBe(2); |
| 606 | + expect(rootSlot[1].routes[1].pattern).toEqual("/root/two"); |
| 607 | + |
| 608 | + const nestedSlot = branches[0].routes.find(r => r.originalPath === "nested")!.slots! |
| 609 | + .nestedSlot; |
| 610 | + expect(nestedSlot.length).toBe(2); |
| 611 | + expect(nestedSlot[1].routes.length).toBe(2); |
| 612 | + expect(nestedSlot[1].routes[1].pattern).toEqual("/root/nested/two"); |
| 613 | + }); |
| 614 | + }); |
567 | 615 | }); |
0 commit comments