forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermalink.js
52 lines (45 loc) · 2.66 KB
/
permalink.js
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
48
49
50
51
52
const Permalink = require('../../lib/permalink')
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
// Permalink constructor requires: languageCode, pageVersion, relativePath, title
// Permalink.derive requires: languageCode, relativePath, title, versions (<- FM prop)
describe('Permalink class', () => {
// We can only use Permalink.derive to get the special 'homepage' permalink
test('derives info for unversioned homepage', () => {
const versions = {
'free-pro-team': '*',
'enterprise-server': '*'
}
const permalinks = Permalink.derive('en', 'index.md', 'Hello World', versions)
expect(permalinks.length).toBeGreaterThan(1)
const homepagePermalink = permalinks.find(permalink => permalink.pageVersion === 'homepage')
expect(homepagePermalink.href).toBe('/en')
})
test('derives info for non-enterprise versioned homepage', () => {
const permalink = new Permalink('en', nonEnterpriseDefaultVersion, 'index.md', 'Hello World')
expect(permalink.pageVersionTitle).toBe('Free, Pro, and Team')
expect(permalink.href).toBe(`/en/${nonEnterpriseDefaultVersion}`)
})
test('derives info for enterprise server versioned homepage', () => {
const permalink = new Permalink('en', `enterprise-server@${enterpriseServerReleases.latest}`, 'index.md', 'Hello World')
expect(permalink.pageVersionTitle).toBe(`Enterprise Server ${enterpriseServerReleases.latest}`)
expect(permalink.href).toBe(`/en/enterprise-server@${enterpriseServerReleases.latest}`)
})
test('derives info for GitHub.com homepage', () => {
const permalink = new Permalink('en', nonEnterpriseDefaultVersion, 'github/index.md', 'Hello World')
expect(permalink.pageVersionTitle).toBe('Free, Pro, and Team')
expect(permalink.href).toBe(`/en/${nonEnterpriseDefaultVersion}/github`)
})
test('derives info for enterprise version of GitHub.com homepage', () => {
const permalink = new Permalink('en', `enterprise-server@${enterpriseServerReleases.latest}`, 'github/index.md', 'Hello World')
expect(permalink.pageVersionTitle).toBe(`Enterprise Server ${enterpriseServerReleases.latest}`)
expect(permalink.href).toBe(`/en/enterprise-server@${enterpriseServerReleases.latest}/github`)
})
test('preserves input properties', () => {
const permalink = new Permalink('en', nonEnterpriseDefaultVersion, 'index.md', 'Hello World')
expect(permalink.languageCode).toBe('en')
expect(permalink.pageVersion).toBe(nonEnterpriseDefaultVersion)
expect(permalink.relativePath).toBe('index.md')
expect(permalink.title).toBe('Hello World')
})
})