|
| 1 | +import type { PackageMetadata } from '../../lib/parse/PackageMetadataLoader'; |
1 | 2 | import { ContextConstructor } from '../../lib/serialize/ContextConstructor'; |
2 | 3 |
|
3 | 4 | describe('ContextConstructor', () => { |
4 | 5 | let ctor: ContextConstructor; |
| 6 | + let packageMetadata: PackageMetadata; |
5 | 7 |
|
6 | 8 | beforeEach(async() => { |
| 9 | + packageMetadata = { |
| 10 | + name: 'my-package', |
| 11 | + version: '2.3.4', |
| 12 | + moduleIri: 'https://linkedsoftwaredependencies.org/bundles/npm/my-package/', |
| 13 | + componentsPath: 'components', |
| 14 | + contexts: {}, |
| 15 | + importPaths: {}, |
| 16 | + typesPath: '', |
| 17 | + }; |
7 | 18 | ctor = new ContextConstructor({ |
8 | | - packageMetadata: { |
9 | | - name: 'my-package', |
10 | | - version: '2.3.4', |
11 | | - moduleIri: 'https://linkedsoftwaredependencies.org/bundles/npm/my-package/', |
12 | | - componentsPath: 'components', |
13 | | - contexts: {}, |
14 | | - importPaths: {}, |
15 | | - typesPath: '', |
16 | | - }, |
| 19 | + packageMetadata, |
| 20 | + typeScopedContexts: false, |
17 | 21 | }); |
18 | 22 | }); |
19 | 23 |
|
@@ -150,5 +154,65 @@ describe('ContextConstructor', () => { |
150 | 154 | }, |
151 | 155 | }); |
152 | 156 | }); |
| 157 | + |
| 158 | + it('should handle non-empty component definitions when typeScopedContexts is true', () => { |
| 159 | + ctor = new ContextConstructor({ |
| 160 | + packageMetadata, |
| 161 | + typeScopedContexts: true, |
| 162 | + }); |
| 163 | + expect(ctor.constructComponentShortcuts({ |
| 164 | + '/docs/package/components/file1': { |
| 165 | + '@context': [ |
| 166 | + 'https://linkedsoftwaredependencies.org/bundles/npm/my-package/context.jsonld', |
| 167 | + ], |
| 168 | + '@id': 'npmd:my-package', |
| 169 | + components: [ |
| 170 | + { |
| 171 | + '@id': 'mp:file1#MyClass1', |
| 172 | + '@type': 'Class', |
| 173 | + constructorArguments: [], |
| 174 | + parameters: [ |
| 175 | + { |
| 176 | + '@id': 'mp:file1#MyClass1_param1', |
| 177 | + }, |
| 178 | + { |
| 179 | + '@id': 'mp:file1#MyClass1_param2', |
| 180 | + }, |
| 181 | + ], |
| 182 | + requireElement: 'MyClass1', |
| 183 | + }, |
| 184 | + ], |
| 185 | + }, |
| 186 | + '/docs/package/components/b/file2': { |
| 187 | + '@context': [ |
| 188 | + 'https://linkedsoftwaredependencies.org/bundles/npm/my-package/context.jsonld', |
| 189 | + ], |
| 190 | + '@id': 'npmd:my-package', |
| 191 | + components: [ |
| 192 | + { |
| 193 | + '@id': 'mp:b/file2#MyClass2', |
| 194 | + '@type': 'Class', |
| 195 | + requireElement: 'MyClass2', |
| 196 | + constructorArguments: [], |
| 197 | + parameters: [], |
| 198 | + }, |
| 199 | + ], |
| 200 | + }, |
| 201 | + })).toEqual({ |
| 202 | + MyClass1: { |
| 203 | + '@id': 'mp:file1#MyClass1', |
| 204 | + '@prefix': true, |
| 205 | + '@context': { |
| 206 | + param1: 'mp:file1#MyClass1_param1', |
| 207 | + param2: 'mp:file1#MyClass1_param2', |
| 208 | + }, |
| 209 | + }, |
| 210 | + MyClass2: { |
| 211 | + '@id': 'mp:b/file2#MyClass2', |
| 212 | + '@prefix': true, |
| 213 | + '@context': {}, |
| 214 | + }, |
| 215 | + }); |
| 216 | + }); |
153 | 217 | }); |
154 | 218 | }); |
0 commit comments