Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/apps/web/tests/sites.test.mjs
blob: c366c11c6762133b301b699797d55741fd6b10a8 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SPDX-FileCopyrightText: 2026 Progmasoft <support@progmasoft.com>
// SPDX-License-Identifier: AGPL-3.0-or-later WITH AdditionRef-Progmasoft-Patent-Grant-1.1

import assert from "node:assert/strict";
import { test } from "node:test";
import { homeMessages } from "../lib/home-messages.ts";
import { supportedLocales } from "../lib/localization.ts";
import { sitesMessages } from "../lib/product-sites.ts";
import {
  catalogMessages,
  isProductSlug,
  productSlugs,
  products,
} from "../lib/products.ts";
import { catch3Route, productRoute } from "../lib/sites.ts";

function shape(value) {
  if (Array.isArray(value)) {
    return ["array", value.length];
  }
  if (typeof value !== "object" || value === null) {
    return typeof value;
  }
  return Object.fromEntries(
    Object.keys(value)
      .sort()
      .map((key) => [key, shape(value[key])]),
  );
}

test("every language has the same home, catalog and product-site text", () => {
  for (const messages of [homeMessages, catalogMessages, sitesMessages]) {
    const english = shape(messages["en-US"]);
    for (const locale of supportedLocales) {
      assert.deepEqual(shape(messages[locale]), english, locale);
    }
  }
});

test("the catalog lists the products the user named, each with a site", () => {
  assert.deepEqual(
    [...productSlugs],
    ["tala-lang", "talac", "talafmt", "talalint", "tazel", "catch3"],
  );
  for (const slug of productSlugs) {
    assert.match(products[slug].site, /^https:\/\//, slug);
    assert.match(
      products[slug].source,
      /^https:\/\/github\.com\/Progmasoft\//,
      slug,
    );
  }
  assert.equal(products.catch3.site, "https://catch3.progmasoft.com/");
  assert.equal(isProductSlug("viget"), false);
  assert.equal(isProductSlug("xide"), false);
});

test("the home page names areas, not products", () => {
  const productNames = Object.values(products).map((product) => product.name);
  for (const locale of supportedLocales) {
    for (const [title, description] of homeMessages[locale].pool.areas) {
      for (const name of productNames) {
        assert.ok(!title.includes(name), `${locale}: ${title}`);
        assert.ok(!description.includes(name), `${locale}: ${description}`);
      }
    }
  }
});

test("the product hosts map to their internal routes", () => {
  assert.equal(productRoute("/"), "/products");
  assert.equal(productRoute("/talac"), "/products/talac");
  assert.equal(productRoute("/tala-lang/"), "/products/tala-lang");
  assert.equal(productRoute("/talac/extra"), null);
  assert.equal(productRoute("/../x"), null);
  assert.equal(catch3Route("/"), "/catch3");
  assert.equal(catch3Route("/docs"), null);
});