Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

products.js 2.4 KB

You have to be logged in to leave a comment. Sign In
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
  1. const revalidator = require('revalidator')
  2. const { productMap } = require('../../lib/all-products')
  3. const schema = require('../../lib/products-schema')
  4. const { getDOM, getJSON } = require('../helpers/supertest')
  5. const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
  6. describe('products module', () => {
  7. test('is an object with product ids as keys', () => {
  8. expect('github' in productMap).toBe(true)
  9. expect('desktop' in productMap).toBe(true)
  10. })
  11. test('every product is valid', () => {
  12. Object.values(productMap).forEach(product => {
  13. const { valid, errors } = revalidator.validate(product, schema)
  14. const expectation = JSON.stringify({ product, errors }, null, 2)
  15. expect(valid, expectation).toBe(true)
  16. })
  17. })
  18. })
  19. describe('mobile-only products nav', () => {
  20. jest.setTimeout(5 * 60 * 1000)
  21. test('renders current product on various product pages for each product', async () => {
  22. // Note the unversioned homepage at `/` does not have a product selected in the mobile dropdown
  23. expect((await getDOM('/github'))('#current-product').text().trim()).toBe('GitHub.com')
  24. // Enterprise server
  25. expect((await getDOM('/en/enterprise/admin'))('#current-product').text().trim()).toBe('Enterprise Administrators')
  26. expect((await getDOM('/en/enterprise/user/github/setting-up-and-managing-your-github-user-account/setting-your-commit-email-address'))('#current-product').text().trim()).toBe('GitHub.com')
  27. expect((await getDOM('/desktop'))('#current-product').text().trim()).toBe('GitHub Desktop')
  28. expect((await getDOM('/actions'))('#current-product').text().trim()).toBe('GitHub Actions')
  29. // localized
  30. expect((await getDOM('/ja/desktop'))('#current-product').text().trim()).toBe('GitHub Desktop')
  31. })
  32. })
  33. describe('products middleware', () => {
  34. jest.setTimeout(5 * 60 * 1000)
  35. test('adds res.context.activeProducts array', async () => {
  36. const products = await getJSON('/en?json=activeProducts')
  37. expect(Array.isArray(products)).toBe(true)
  38. })
  39. test('adds res.context.currentProduct string on homepage', async () => {
  40. const currentProduct = await getJSON('/en?json=currentProduct')
  41. expect(currentProduct).toBe('homepage')
  42. })
  43. test('adds res.context.currentProduct object', async () => {
  44. const currentProduct = await getJSON(`/en/${nonEnterpriseDefaultVersion}/github?json=currentProduct`)
  45. expect(currentProduct).toBe('github')
  46. })
  47. })
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...