* close Language and ArticleVersion pickers after click * cleanup ArticleGridLayout due to VersionPicker changes * fix tsc errors resulting from primer upgrade * fix / update tests * cleanup mobile pickers visual consistency * use btn-sm on VersionPicker * update translation and close on click for enterprise releases Co-authored-by: Kevin Heis <heiskr@users.noreply.github.com>
79 lines
2.7 KiB
JavaScript
79 lines
2.7 KiB
JavaScript
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')
|
|
})
|
|
})
|