|
| 1 | +import{afterEach,describe,expect,it,vi}from'vitest'; |
| 2 | + |
| 3 | +interfaceExample{ |
| 4 | +elementName?: string; |
| 5 | +entrypoint?: string; |
| 6 | +} |
| 7 | + |
| 8 | +asyncfunctionimportExamplePage(){ |
| 9 | +vi.resetModules(); |
| 10 | +vi.stubEnv('ELEMENTS_SITE_URL','https://nvidia.github.io'); |
| 11 | +vi.stubEnv('PAGES_BASE_URL','/elements/'); |
| 12 | +vi.doMock('../index.11tydata.js',()=>({ |
| 13 | +siteData: { |
| 14 | +BASE_URL: '/elements/', |
| 15 | +examples: [] |
| 16 | +} |
| 17 | +})); |
| 18 | +vi.doMock('@internals/tools/playground',()=>({ |
| 19 | +PlaygroundService: { |
| 20 | +create: vi.fn().mockResolvedValue('') |
| 21 | +} |
| 22 | +})); |
| 23 | + |
| 24 | +returnimport('./index.11ty.js'); |
| 25 | +} |
| 26 | + |
| 27 | +afterEach(()=>{ |
| 28 | +vi.unstubAllEnvs(); |
| 29 | +vi.doUnmock('../index.11tydata.js'); |
| 30 | +vi.doUnmock('@internals/tools/playground'); |
| 31 | +}); |
| 32 | + |
| 33 | +describe('example page urls',()=>{ |
| 34 | +it('should point pattern examples at pattern documentation',async()=>{ |
| 35 | +const{ getCanonicalPath, getCanonicalUrl, getDocumentationPath }=awaitimportExamplePage(); |
| 36 | +constexample: Example={ |
| 37 | +elementName: 'patterns', |
| 38 | +entrypoint: '@internals/patterns/subheader.examples.json' |
| 39 | +}; |
| 40 | + |
| 41 | +expect(getCanonicalPath(example)).toBe('/docs/patterns/subheader/'); |
| 42 | +expect(getDocumentationPath(example)).toBe('/docs/patterns/subheader/'); |
| 43 | +expect(getCanonicalUrl(example)).toBe('https://nvidia.github.io/elements/docs/patterns/subheader/'); |
| 44 | +}); |
| 45 | + |
| 46 | +it('should keep component examples pointed at component documentation',async()=>{ |
| 47 | +const{ getCanonicalPath, getDocumentationPath }=awaitimportExamplePage(); |
| 48 | +constexample: Example={ |
| 49 | +elementName: 'button', |
| 50 | +entrypoint: '@nvidia-elements/core/button/button.examples.json' |
| 51 | +}; |
| 52 | + |
| 53 | +expect(getCanonicalPath(example)).toBe('/docs/elements/button/examples/'); |
| 54 | +expect(getDocumentationPath(example)).toBe('/docs/elements/button/'); |
| 55 | +}); |
| 56 | +}); |
0 commit comments