-
Notifications
You must be signed in to change notification settings - Fork 68.3k
Expand file tree
/
Copy pathpath-utils.ts
More file actions
47 lines (40 loc) · 2.33 KB
/
Copy pathpath-utils.ts
File metadata and controls
47 lines (40 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { describe, expect, test } from 'vitest'
import { getProductStringFromPath } from '@/frame/lib/path-utils'
describe('getProductStringFromPath', () => {
test('returns "homepage" for root paths', () => {
expect(getProductStringFromPath('/')).toBe('homepage')
expect(getProductStringFromPath('/en')).toBe('homepage')
expect(getProductStringFromPath(undefined)).toBe('homepage')
})
test('handles early-access product', () => {
expect(getProductStringFromPath('/en/early-access/github/overview')).toBe('early-access')
expect(getProductStringFromPath('/early-access/admin/guides')).toBe('early-access')
})
test('handles special products (rest, copilot, get-started)', () => {
expect(getProductStringFromPath('/en/rest/overview')).toBe('rest')
expect(getProductStringFromPath('/rest/reference/repos')).toBe('rest')
expect(getProductStringFromPath('/en/copilot/using-copilot')).toBe('copilot')
expect(getProductStringFromPath('/copilot/features')).toBe('copilot')
expect(getProductStringFromPath('/en/get-started/quickstart')).toBe('get-started')
expect(getProductStringFromPath('/get-started/onboarding')).toBe('get-started')
})
test('extracts product from non-versioned paths', () => {
expect(getProductStringFromPath('/en/github/getting-started')).toBe('github')
expect(getProductStringFromPath('/actions/quickstart')).toBe('actions')
expect(getProductStringFromPath('/en/admin/installation')).toBe('admin')
expect(getProductStringFromPath('/code-security/overview')).toBe('code-security')
})
test('extracts product from versioned paths', () => {
// Note: These tests use free-pro-team which is a supported version
expect(getProductStringFromPath('/en/free-pro-team@latest/admin/installation')).toBe('admin')
expect(getProductStringFromPath('/free-pro-team@latest/actions/quickstart')).toBe('actions')
expect(getProductStringFromPath('/en/free-pro-team@latest/github/getting-started')).toBe(
'github',
)
})
test('handles enterprise landing pages (version without product)', () => {
// When a version is present but no product segment follows, return the version string
expect(getProductStringFromPath('/en/free-pro-team@latest')).toBe('free-pro-team@latest')
expect(getProductStringFromPath('/enterprise-server@latest')).toBe('enterprise-server@latest')
})
})