mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-30 16:50:47 +08:00
This commit removes everything Ethereum related, this includes: - profile pages (which relied on Ethereum information) - testnet faucet - vesting contract lookup - .radicle.eth ENS registrations Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
237 lines
7.0 KiB
TypeScript
237 lines
7.0 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import * as utils from "@app/lib/utils";
|
|
|
|
describe("Format functions", () => {
|
|
test.each([
|
|
{ hash: "#L42", expected: 42 },
|
|
{ hash: "#ETH", expected: null },
|
|
])("formatLocationHash $hash => $expected", ({ hash, expected }) => {
|
|
expect(utils.formatLocationHash(hash)).toEqual(expected);
|
|
});
|
|
|
|
test.each([
|
|
{
|
|
id: "hydkkkf5ksbe5fuszdhpqhytu3q36gwagj874wxwpo5a8ti8coygh1",
|
|
expected: "hydkkk…coygh1",
|
|
},
|
|
])("formatSeedId $id => $expected", ({ id, expected }) => {
|
|
expect(utils.formatSeedId(id)).toEqual(expected);
|
|
});
|
|
|
|
test("formatRadicleId", () => {
|
|
if (process.env.HEARTWOOD) {
|
|
expect(utils.formatRadicleId("rad:zKtT7DmF9H34KkvcKj9PHW19WzjT")).toEqual(
|
|
"rad:zKtT7D…19WzjT",
|
|
);
|
|
} else {
|
|
expect(
|
|
utils.formatRadicleId("rad:git:hnrkemobagsicpf9sr95o3g551otspcd84c9o"),
|
|
).toEqual("rad:git:hnrkem…d84c9o");
|
|
}
|
|
});
|
|
|
|
test("formatRadicleId throw when wrong ID", () => {
|
|
expect(() =>
|
|
utils.formatRadicleId("hnrkemobagsicpf9sr95o3g551otspcd84c9o"),
|
|
).toThrow();
|
|
});
|
|
|
|
test.each([
|
|
{
|
|
input: "seedling",
|
|
expected: "🌱",
|
|
},
|
|
{
|
|
input: "+1",
|
|
expected: "👍",
|
|
},
|
|
{
|
|
input: "radicle",
|
|
expected: "radicle",
|
|
},
|
|
])("parseEmoji $input => $expected", ({ input, expected }) => {
|
|
expect(utils.parseEmoji(input)).toEqual(expected);
|
|
});
|
|
|
|
test.each([
|
|
{ commit: "a8a6a979a6261a2ec1ea85fc9a65a4a30aa22cc8", expected: "a8a6a97" },
|
|
{ commit: "a8a6a97", expected: "a8a6a97" },
|
|
])("formatCommit $commit => $expected", ({ commit, expected }) => {
|
|
expect(utils.formatCommit(commit)).toEqual(expected);
|
|
});
|
|
});
|
|
|
|
describe("String Assertions", () => {
|
|
test.each([
|
|
{ domain: "alt-clients.radicle.xyz", expected: true },
|
|
{ domain: "0.0.0.0", expected: true }, // Pass as true since we are not in production
|
|
{ domain: "", expected: false },
|
|
])("isDomain $domain => $expected", ({ domain, expected }) => {
|
|
expect(utils.isDomain(domain)).toEqual(expected);
|
|
});
|
|
|
|
test.each([
|
|
{ path: "README.md", expected: true },
|
|
{ path: "README.mkd", expected: true },
|
|
{ path: "README.markdown", expected: true },
|
|
{ path: "", expected: false },
|
|
])("isMarkdownPath $path => $expected", ({ path, expected }) => {
|
|
expect(utils.isMarkdownPath(path)).toEqual(expected);
|
|
});
|
|
|
|
test.each([
|
|
process.env.HEARTWOOD
|
|
? { id: "rad:zKtT7DmF9H34KkvcKj9PHW19WzjT", expected: true }
|
|
: { id: "rad:git:hnrkemobagsicpf9sr95o3g551otspcd84c9o", expected: true },
|
|
{ id: "0x1234567890123456789012345678901234567890", expected: false },
|
|
])("isRadicleId $id => $expected", ({ id, expected }) => {
|
|
expect(utils.isRadicleId(id)).toEqual(expected);
|
|
});
|
|
|
|
test.each([
|
|
{ id: "hnrkj4c35uoyceb3d1dsscx8qq55cikrd1aio", expected: true },
|
|
{ id: "0x1234567890123456789012345678901234567890", expected: false },
|
|
])("isPeerId $id => $expected", ({ id, expected }) => {
|
|
expect(utils.isPeerId(id)).toEqual(expected);
|
|
});
|
|
|
|
test.each([
|
|
{ oid: "a64ae9c6d572e0ad906faa9a4a7a8d43f113278c", expected: true },
|
|
{ oid: "a64ae9c", expected: false },
|
|
])("isOid $oid => $expected", ({ oid, expected }) => {
|
|
expect(utils.isOid(oid)).toEqual(expected);
|
|
});
|
|
|
|
test.each([
|
|
{ url: "https://app.radicle.xyz", expected: true },
|
|
{ url: "http://app.radicle.xyz", expected: true },
|
|
{ url: "http://app", expected: true },
|
|
{ url: "://app", expected: false },
|
|
{ url: "//app", expected: false },
|
|
{ url: "app", expected: false },
|
|
])("isUrl $url => $expected", ({ url, expected }) => {
|
|
expect(utils.isUrl(url)).toBe(expected);
|
|
});
|
|
});
|
|
|
|
describe("Parse Strings", () => {
|
|
test.each([
|
|
{ input: "https://twitter.com/cloudhead", expected: "cloudhead" },
|
|
{ input: "sebastinez", expected: "sebastinez" },
|
|
])("parseUsername", ({ input, expected }) => {
|
|
expect(utils.parseUsername(input)).toEqual(expected);
|
|
});
|
|
});
|
|
|
|
describe("Path Manipulation", () => {
|
|
test.each([
|
|
{
|
|
imagePath: "/assets/images/tux.png",
|
|
base: "/",
|
|
origin: "https://app.radicle.xyz",
|
|
expected: "assets/images/tux.png",
|
|
},
|
|
{
|
|
imagePath: "assets/images/tux.png",
|
|
base: "/",
|
|
origin: "https://app.radicle.xyz",
|
|
expected: "assets/images/tux.png",
|
|
},
|
|
{
|
|
imagePath: "assets/images/tux.png",
|
|
base: "/",
|
|
origin: "http://localhost:3000",
|
|
expected: "assets/images/tux.png",
|
|
},
|
|
{
|
|
imagePath: "../tux.png",
|
|
base: "/components/assets/README.md",
|
|
origin: "http://localhost:3000",
|
|
expected: "components/tux.png",
|
|
},
|
|
{
|
|
imagePath: "../tux.png",
|
|
base: "/components/assets/",
|
|
origin: "http://localhost:3000",
|
|
expected: "components/tux.png",
|
|
},
|
|
{
|
|
imagePath: "../../tux.png",
|
|
base: "/components/assets/images/README.md",
|
|
origin: "http://localhost:3000",
|
|
expected: "components/tux.png",
|
|
},
|
|
])(
|
|
"canonicalize origin: $origin base: $base, path: $imagePath => $expected",
|
|
({ imagePath, base, expected, origin }) => {
|
|
expect(utils.canonicalize(imagePath, base, origin)).toEqual(expected);
|
|
},
|
|
);
|
|
});
|
|
|
|
describe("Date Manipulation", () => {
|
|
test.each([
|
|
{ from: new Date("2022-01-01"), to: new Date("2022-02-01"), expected: 31 },
|
|
{ from: new Date("2022-01-01"), to: new Date("2022-01-02"), expected: 1 },
|
|
{ from: new Date("2022-01-01"), to: new Date("2022-01-01"), expected: 0 },
|
|
])("getDaysPassed expected: $expected ", ({ from, to, expected }) => {
|
|
expect(utils.getDaysPassed(from, to)).toEqual(expected);
|
|
});
|
|
test.each([
|
|
{
|
|
from: new Date("2022-01-01 12:00:00"),
|
|
to: new Date("2022-01-01 12:00:00"),
|
|
expected: "now",
|
|
},
|
|
{
|
|
from: new Date("2022-01-01 12:00:00"),
|
|
to: new Date("2022-01-01 12:00:01"),
|
|
expected: "1 second ago",
|
|
},
|
|
{
|
|
from: new Date("2022-01-01 12:00:00"),
|
|
to: new Date("2022-01-01 12:01:01"),
|
|
expected: "1 minute ago",
|
|
},
|
|
{
|
|
from: new Date("2022-01-01 12:00:00"),
|
|
to: new Date("2022-01-01 13:01:01"),
|
|
expected: "1 hour ago",
|
|
},
|
|
{
|
|
from: new Date("2022-01-01 12:00:00"),
|
|
to: new Date("2022-01-02 13:01:01"),
|
|
expected: "yesterday",
|
|
},
|
|
{
|
|
from: new Date("2022-01-01 12:00:00"),
|
|
to: new Date("2022-01-04 13:01:01"),
|
|
expected: "3 days ago",
|
|
},
|
|
{
|
|
from: new Date("2022-01-01 12:00:00"),
|
|
to: new Date("2022-02-02 13:01:01"),
|
|
expected: "last month",
|
|
},
|
|
{
|
|
from: new Date("2022-01-01 12:00:00"),
|
|
to: new Date("2022-04-02 13:01:01"),
|
|
expected: "3 months ago",
|
|
},
|
|
{
|
|
from: new Date("2022-01-01 12:00:00"),
|
|
to: new Date("2023-04-02 12:00:00"),
|
|
expected: "Sat, 01 Jan 2022 12:00:00 GMT",
|
|
},
|
|
{
|
|
from: new Date("2022-03-05 12:00:00"),
|
|
to: new Date("2026-04-02 12:00:00"),
|
|
expected: "Sat, 05 Mar 2022 12:00:00 GMT",
|
|
},
|
|
])("formatTimestamp expected: $expected", ({ from, to, expected }) => {
|
|
expect(utils.formatTimestamp(from.getTime() / 1000, to.getTime())).toEqual(
|
|
expected,
|
|
);
|
|
});
|
|
});
|