|
| 1 | +jest.mock("@tiptap/extension-placeholder", () => ({ |
| 2 | + configure: jest.fn(() => ({})) |
| 3 | +})); |
| 4 | +jest.mock("@tiptap/extension-horizontal-rule", () => ({ |
| 5 | + configure: jest.fn(() => ({})), |
| 6 | + extend: jest.fn(() => ({ configure: jest.fn(() => ({})) })) |
| 7 | +})); |
| 8 | +jest.mock("@tiptap/extension-link", () => ({ |
| 9 | + configure: jest.fn(() => ({})), |
| 10 | + extend: jest.fn(() => ({})) |
| 11 | +})); |
| 12 | + |
| 13 | +jest.mock("@tiptap/starter-kit", () => ({ |
| 14 | + configure: jest.fn(() => ({})) |
| 15 | +})); |
| 16 | + |
| 17 | +jest.mock("@tiptap/extension-ordered-list", () => ({ |
| 18 | + configure: jest.fn(() => ({})) |
| 19 | +})); |
| 20 | + |
| 21 | +jest.mock("@tiptap/extension-bullet-list", () => ({ |
| 22 | + configure: jest.fn(() => ({})) |
| 23 | +})); |
| 24 | + |
| 25 | +jest.mock("@tiptap/extension-list-item", () => ({ |
| 26 | + configure: jest.fn(() => ({})) |
| 27 | +})); |
| 28 | + |
| 29 | +jest.mock("@tiptap/extension-code-block", () => ({ |
| 30 | + configure: jest.fn(() => ({})) |
| 31 | +})); |
| 32 | + |
| 33 | +jest.mock("@tiptap/extension-blockquote", () => ({ |
| 34 | + configure: jest.fn(() => ({})) |
| 35 | +})); |
| 36 | + |
| 37 | +jest.mock("@tiptap/extension-code", () => ({ |
| 38 | + configure: jest.fn(() => ({})) |
| 39 | +})); |
| 40 | + |
1 | 41 | import { expect, it } from "@jest/globals";
|
2 | 42 | import { siteConfig } from "./test_site_config";
|
3 | 43 | import { EntityCollection } from "../src/types";
|
4 |
| -import { getCollectionByPathOrId, resolveCollectionPathIds } from "../src"; |
| 44 | +import { getCollectionByPathOrId, resolveCollectionPathIds, buildCollection, buildProperty } from "../src"; |
5 | 45 | import { getNavigationEntriesFromPath } from "../src/util/navigation_from_path";
|
6 | 46 |
|
7 | 47 | const collections = siteConfig.collections as EntityCollection[];
|
8 | 48 |
|
9 |
| -it("collection view matches ok", () => { |
| 49 | +describe("Resolving paths test", () => { |
| 50 | + it("collection view matches ok", () => { |
10 | 51 |
|
11 |
| - const collectionViewFromPath = getCollectionByPathOrId("products", collections); |
12 |
| - expect( |
13 |
| - collectionViewFromPath && collectionViewFromPath.path |
14 |
| - ).toEqual("products"); |
| 52 | + const collectionViewFromPath = getCollectionByPathOrId("products", collections); |
| 53 | + expect( |
| 54 | + collectionViewFromPath && collectionViewFromPath.path |
| 55 | + ).toEqual("products"); |
15 | 56 |
|
16 |
| - const collectionViewFromPath1 = getCollectionByPathOrId("products/pid/locales", collections); |
17 |
| - expect( |
18 |
| - collectionViewFromPath1 && collectionViewFromPath1.path |
19 |
| - ).toEqual("locales"); |
| 57 | + const collectionViewFromPath1 = getCollectionByPathOrId("products/pid/locales", collections); |
| 58 | + expect( |
| 59 | + collectionViewFromPath1 && collectionViewFromPath1.path |
| 60 | + ).toEqual("locales"); |
20 | 61 |
|
21 |
| - const collectionViewFromPath2 = getCollectionByPathOrId("sites/es/products", collections); |
22 |
| - expect( |
23 |
| - collectionViewFromPath2 && collectionViewFromPath2.path |
24 |
| - ).toEqual("sites/es/products"); |
| 62 | + const collectionViewFromPath2 = getCollectionByPathOrId("sites/es/products", collections); |
| 63 | + expect( |
| 64 | + collectionViewFromPath2 && collectionViewFromPath2.path |
| 65 | + ).toEqual("sites/es/products"); |
25 | 66 |
|
26 |
| - const collectionViewFromPath3 = getCollectionByPathOrId("sites/es/products/pid/locales", collections); |
27 |
| - expect( |
28 |
| - collectionViewFromPath3 && collectionViewFromPath3.path |
29 |
| - ).toEqual("locales"); |
| 67 | + const collectionViewFromPath3 = getCollectionByPathOrId("sites/es/products/pid/locales", collections); |
| 68 | + expect( |
| 69 | + collectionViewFromPath3 && collectionViewFromPath3.path |
| 70 | + ).toEqual("locales"); |
30 | 71 |
|
31 |
| - expect( |
32 |
| - () => getCollectionByPathOrId("products/pid", collections) |
33 |
| - ).toThrow( |
34 |
| - "Collection paths must have an odd number of segments: products/pid" |
35 |
| - ); |
| 72 | + expect( |
| 73 | + () => getCollectionByPathOrId("products/pid", collections) |
| 74 | + ).toThrow( |
| 75 | + "Collection paths must have an odd number of segments: products/pid" |
| 76 | + ); |
36 | 77 |
|
37 |
| - expect( |
38 |
| - getCollectionByPathOrId("products", []) |
39 |
| - ).toEqual(undefined); |
| 78 | + expect( |
| 79 | + getCollectionByPathOrId("products", []) |
| 80 | + ).toEqual(undefined); |
40 | 81 |
|
41 |
| - const collectionViewFromPath10 = getCollectionByPathOrId("products/id/subcollection_inline", collections); |
42 |
| - expect( |
43 |
| - collectionViewFromPath10 && collectionViewFromPath10.path |
44 |
| - ).toEqual("products/id/subcollection_inline"); |
| 82 | + const collectionViewFromPath10 = getCollectionByPathOrId("products/id/subcollection_inline", collections); |
| 83 | + expect( |
| 84 | + collectionViewFromPath10 && collectionViewFromPath10.path |
| 85 | + ).toEqual("products/id/subcollection_inline"); |
45 | 86 |
|
46 |
| -}); |
| 87 | + }); |
47 | 88 |
|
48 |
| -it("build entity collection array", () => { |
| 89 | + it("build entity collection array", () => { |
49 | 90 |
|
50 |
| - const navigationEntries = getNavigationEntriesFromPath({ |
51 |
| - path: "products/pid", |
52 |
| - collections: collections, |
| 91 | + const navigationEntries = getNavigationEntriesFromPath({ |
| 92 | + path: "products/pid", |
| 93 | + collections: collections |
| 94 | + }); |
| 95 | + console.log(navigationEntries); |
| 96 | + // expect( |
| 97 | + // navigationEntries.map((collection) => collection.relativePath) |
| 98 | + // ).toEqual(["products", "locales"]); |
53 | 99 | });
|
54 |
| - console.log(navigationEntries); |
55 |
| - // expect( |
56 |
| - // navigationEntries.map((collection) => collection.relativePath) |
57 |
| - // ).toEqual(["products", "locales"]); |
58 |
| -}); |
59 |
| - |
60 | 100 |
|
61 |
| -it("Custom view internal", () => { |
| 101 | + it("Custom view internal", () => { |
62 | 102 |
|
63 |
| - const navigationEntries = getNavigationEntriesFromPath({ |
64 |
| - path: "products/pid/custom_view", |
65 |
| - collections: collections, |
| 103 | + const navigationEntries = getNavigationEntriesFromPath({ |
| 104 | + path: "products/pid/custom_view", |
| 105 | + collections: collections |
| 106 | + }); |
| 107 | + console.log(navigationEntries); |
| 108 | + expect(navigationEntries.length).toEqual(3); |
66 | 109 | });
|
67 |
| - console.log(navigationEntries); |
68 |
| - expect(navigationEntries.length).toEqual(3); |
69 |
| -}); |
70 | 110 |
|
71 |
| -it("build entity collection array 2", () => { |
| 111 | + it("build entity collection array 2", () => { |
72 | 112 |
|
73 |
| - const navigationEntries = getNavigationEntriesFromPath({ |
74 |
| - path: "products/pid/locales/yep", |
75 |
| - collections: collections, |
| 113 | + const navigationEntries = getNavigationEntriesFromPath({ |
| 114 | + path: "products/pid/locales/yep", |
| 115 | + collections: collections |
| 116 | + }); |
| 117 | + console.log(navigationEntries); |
| 118 | + expect(navigationEntries.length).toEqual(4); |
76 | 119 | });
|
77 |
| - console.log(navigationEntries); |
78 |
| - expect(navigationEntries.length).toEqual(4); |
79 |
| -}); |
80 | 120 |
|
81 |
| -it("Test aliases", () => { |
| 121 | + it("Test aliases", () => { |
| 122 | + |
| 123 | + const resolvedPath = resolveCollectionPathIds("u", collections); |
| 124 | + expect(resolvedPath).toEqual("users"); |
82 | 125 |
|
83 |
| - const resolvedPath = resolveCollectionPathIds("u", collections); |
84 |
| - expect(resolvedPath).toEqual("users"); |
| 126 | + const resolvedPath2 = resolveCollectionPathIds("u/123/products", collections); |
| 127 | + expect(resolvedPath2).toEqual("users/123/products"); |
85 | 128 |
|
86 |
| - const resolvedPath2 = resolveCollectionPathIds("u/123/products", collections); |
87 |
| - expect(resolvedPath2).toEqual("users/123/products"); |
| 129 | + const resolvedPath3 = resolveCollectionPathIds("u/123/p", collections); |
| 130 | + expect(resolvedPath3).toEqual("users/123/products"); |
88 | 131 |
|
89 |
| - const resolvedPath3 = resolveCollectionPathIds("u/123/p", collections); |
90 |
| - expect(resolvedPath3).toEqual("users/123/products"); |
| 132 | + const resolvedPath4 = resolveCollectionPathIds("users/123/p", collections); |
| 133 | + expect(resolvedPath4).toEqual("users/123/products"); |
91 | 134 |
|
92 |
| - const resolvedPath4 = resolveCollectionPathIds("users/123/p", collections); |
93 |
| - expect(resolvedPath4).toEqual("users/123/products"); |
| 135 | + const resolvedPath5 = resolveCollectionPathIds("products/id/subcollection_inline", collections); |
| 136 | + expect(resolvedPath5).toEqual("products/id/subcollection_inline"); |
| 137 | + }); |
94 | 138 |
|
95 |
| - const resolvedPath5 = resolveCollectionPathIds("products/id/subcollection_inline", collections); |
96 |
| - expect(resolvedPath5).toEqual("products/id/subcollection_inline"); |
| 139 | + |
| 140 | + it("should correctly resolve subcollection with different id and path", () => { |
| 141 | + // Simplified locale collection |
| 142 | + const jointLocaleCollection = buildCollection({ |
| 143 | + id: "medico_v2_0_0_joint_locales", |
| 144 | + path: "locales", |
| 145 | + name: "Translations", |
| 146 | + properties: { |
| 147 | + name: buildProperty({ |
| 148 | + dataType: "string", |
| 149 | + name: "Name" |
| 150 | + }) |
| 151 | + } |
| 152 | + }); |
| 153 | + |
| 154 | + // Simplified joint movements collection |
| 155 | + const jointMovementsCollection = buildCollection({ |
| 156 | + id: "medico_v2_0_0_joint_movements", |
| 157 | + path: "movements", |
| 158 | + name: "Joint movements", |
| 159 | + properties: { |
| 160 | + reference_value_min: buildProperty({ |
| 161 | + name: "Reference value min", |
| 162 | + dataType: "number" |
| 163 | + }) |
| 164 | + }, |
| 165 | + subcollections: [jointLocaleCollection] |
| 166 | + }); |
| 167 | + |
| 168 | + // Simplified joints collection |
| 169 | + const jointsCollection = buildCollection({ |
| 170 | + id: "medico_v2_0_0_joints", |
| 171 | + path: "medico/v2.0.0/joints", |
| 172 | + name: "Joint", |
| 173 | + properties: { |
| 174 | + latin_name: buildProperty({ |
| 175 | + name: "Latin name", |
| 176 | + dataType: "string" |
| 177 | + }) |
| 178 | + }, |
| 179 | + subcollections: [jointMovementsCollection, jointLocaleCollection] |
| 180 | + }); |
| 181 | + |
| 182 | + const collections = [jointsCollection]; |
| 183 | + |
| 184 | + // Test path resolution for joint movements subcollection |
| 185 | + const result = resolveCollectionPathIds( |
| 186 | + "medico_v2_0_0_joints/cervical_spine/medico_v2_0_0_joint_movements", |
| 187 | + collections |
| 188 | + ); |
| 189 | + |
| 190 | + expect(result).toEqual("medico/v2.0.0/joints/cervical_spine/movements"); |
| 191 | + |
| 192 | + // Alternative test using path instead of ID for the parent collection |
| 193 | + const result2 = resolveCollectionPathIds( |
| 194 | + "medico/v2.0.0/joints/cervical_spine/medico_v2_0_0_joint_movements", |
| 195 | + collections |
| 196 | + ); |
| 197 | + |
| 198 | + expect(result2).toEqual("medico/v2.0.0/joints/cervical_spine/movements"); |
| 199 | + }); |
97 | 200 | });
|
0 commit comments