-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathproducts.js
More file actions
78 lines (66 loc) · 2.65 KB
/
products.js
File metadata and controls
78 lines (66 loc) · 2.65 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { jest } from '@jest/globals'
import revalidator from 'revalidator'
import { productMap } from '../../lib/all-products.js'
import schema from '../helpers/schemas/products-schema.js'
import { getDOM, getJSON } from '../helpers/supertest.js'
import nonEnterpriseDefaultVersion from '../../lib/non-enterprise-default-version.js'
jest.useFakeTimers()
describe('products module', () => {
test('is an object with product ids as keys', () => {
expect('github' in productMap).toBe(true)
expect('desktop' in productMap).toBe(true)
})
test('every product is valid', () => {
Object.values(productMap).forEach((product) => {
const { valid, errors } = revalidator.validate(product, schema)
const expectation = JSON.stringify({ product, errors }, null, 2)
expect(valid, expectation).toBe(true)
})
})
})
describe('mobile-only products nav', () => {
test('renders current product on various product pages for each product', async () => {
// Note the unversioned homepage at `/` does not have a product selected in the mobile dropdown
expect((await getDOM('/github'))('[data-testid=current-product]').text().trim()).toBe('GitHub')
// Enterprise server
expect(
(await getDOM('/en/enterprise/admin'))('[data-testid=current-product]').text().trim()
).toBe('Enterprise administrators')
expect(
(
await getDOM(
'/en/enterprise/user/github/importing-your-projects-to-github/importing-source-code-to-github/importing-a-git-repository-using-the-command-line'
)
)('[data-testid=current-product]')
.text()
.trim()
).toBe('GitHub')
expect((await getDOM('/desktop'))('[data-testid=current-product]').text().trim()).toBe(
'GitHub Desktop'
)
expect((await getDOM('/actions'))('[data-testid=current-product]').text().trim()).toBe(
'GitHub Actions'
)
// localized
expect((await getDOM('/ja/desktop'))('[data-testid=current-product]').text().trim()).toBe(
'GitHub Desktop'
)
})
})
describe('products middleware', () => {
jest.setTimeout(5 * 60 * 1000)
test('adds res.context.activeProducts array', async () => {
const products = await getJSON('/en?json=activeProducts')
expect(Array.isArray(products)).toBe(true)
})
test('adds res.context.currentProduct string on homepage', async () => {
const currentProduct = await getJSON('/en?json=currentProduct')
expect(currentProduct).toBe('homepage')
})
test('adds res.context.currentProduct object', async () => {
const currentProduct = await getJSON(
`/en/${nonEnterpriseDefaultVersion}/github?json=currentProduct`
)
expect(currentProduct).toBe('github')
})
})