aboutsummaryrefslogtreecommitdiff
path: root/website/src/docs-path.test.ts
blob: 0fadb26e752d3969d680cf8b42b493c06462766f (plain)
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
import { describe, expect, test } from 'bun:test';
import { docsPath, docsRoute, docsTargetHref, docsVersion } from './docs-path';

const scopes = {
  stable: { locales: { root: ['', 'install'], ja: ['', 'install'] } },
  preview: { locales: { root: ['', 'install', 'new-page'], ja: ['', 'install'] } },
  '0.7.4': { locales: { root: ['', 'install'], ja: [''] } },
};

describe('docsRoute', () => {
  test.each([
    ['/docs/', { isDocs: true, locale: undefined, target: 'stable', page: '' }],
    ['/ja/docs/install/', { isDocs: true, locale: 'ja', target: 'stable', page: 'install' }],
    ['/docs/preview/new-page/', { isDocs: true, locale: undefined, target: 'preview', page: 'new-page' }],
    ['/zh-cn/docs/preview/', { isDocs: true, locale: 'zh-cn', target: 'preview', page: '' }],
    ['/docs/0.7.4/install/', { isDocs: true, locale: undefined, target: '0.7.4', page: 'install' }],
    ['/ja/docs/0.7.4/', { isDocs: true, locale: 'ja', target: '0.7.4', page: '' }],
    ['/blog/', { isDocs: false, locale: undefined, target: 'stable', page: '' }],
  ])('parses %s', (pathname, expected) => {
    expect(docsRoute(pathname)).toEqual(expected);
  });
});

describe('docsVersion', () => {
  test.each([
    ['/docs/', 'stable'],
    ['/ja/docs/preview/install/', 'preview'],
    ['/zh-cn/docs/0.7.4/', '0.7.4'],
  ])('maps %s', (pathname, version) => {
    expect(docsVersion(pathname)).toBe(version);
  });
});

describe('docsTargetHref', () => {
  test.each([
    ['/docs/install/', 'preview', '/docs/preview/install/'],
    ['/ja/docs/install/', '0.7.4', '/ja/docs/0.7.4/'],
    ['/docs/0.7.4/install/', 'stable', '/docs/install/'],
    ['/docs/preview/new-page/', '0.7.4', '/docs/0.7.4/'],
  ])('maps %s to %s', (pathname, target, expected) => {
    expect(docsTargetHref(docsRoute(pathname), target, scopes)).toBe(expected);
  });
});

describe('docsPath', () => {
  test.each([
    ['index.mdx', 'docs'],
    ['install.mdx', 'docs/install'],
    ['ja/index.mdx', 'ja/docs'],
    ['ja/install.mdx', 'ja/docs/install'],
    ['zh-cn/install.mdx', 'zh-cn/docs/install'],
    ['preview/index.mdx', 'docs/preview'],
    ['preview/install.mdx', 'docs/preview/install'],
    ['preview/ja/index.mdx', 'ja/docs/preview'],
    ['preview/ja/install.mdx', 'ja/docs/preview/install'],
    ['_versions/0.7.4/index.mdx', 'docs/0.7.4'],
    ['_versions/0.7.4/install.mdx', 'docs/0.7.4/install'],
    ['_versions/0.7.4/ja/index.mdx', 'ja/docs/0.7.4'],
    ['_versions/0.7.4/zh-cn/install.mdx', 'zh-cn/docs/0.7.4/install'],
  ])('maps %s to %s', (entry, expected) => {
    expect(docsPath({ entry })).toBe(expected);
  });
});