Skip to content

Commit 37387c4

Browse files
authored
Merge pull request #2270 from input-output-hk/djo/2212/explorer/add-cardano-db-v2
explorer: Add cardano db v2 support & rework tabs layout
2 parents 3abeead + 8bdabaf commit 37387c4

File tree

30 files changed

+4096
-2893
lines changed

30 files changed

+4096
-2893
lines changed

mithril-explorer/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ upgrade: clean install
6060
bootstrap-icons@latest \
6161
chart.js@latest \
6262
next@latest \
63-
react@^18.3.1 \
63+
react@latest \
6464
react-bootstrap@latest \
6565
react-chartjs-2@latest \
66-
react-dom@^18.3.1 \
66+
react-dom@latest \
6767
react-redux@latest \
6868
@testing-library/jest-dom@latest \
6969
@testing-library/react@latest \
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { fireEvent, render, screen } from "@testing-library/react";
2+
import "@testing-library/jest-dom";
3+
import { DownloadImmutableFormInput } from "#/Artifacts/CardanoDbV2SnapshotsList/DownloadButton";
4+
5+
const maxImmutable = 100_000;
6+
7+
function setup(max) {
8+
const utils = render(<DownloadImmutableFormInput max={max} />);
9+
return {
10+
input: screen.getByRole("spinbutton"),
11+
...utils,
12+
};
13+
}
14+
15+
describe("DownloadImmutableFormInput", () => {
16+
it("Empty default to invalid", () => {
17+
const { input } = setup(maxImmutable);
18+
expect(input.checkValidity()).toBeFalsy();
19+
expect(input.value).toBe("");
20+
});
21+
22+
it("Setting empty string is invalid", () => {
23+
const { input } = setup(maxImmutable);
24+
fireEvent.change(input, { target: { value: "" } });
25+
expect(input.checkValidity()).toBeFalsy();
26+
expect(input.value).toBe("");
27+
});
28+
29+
it.each([0, 123, 67_782, maxImmutable])(
30+
"Immutable below or equal to max allowed: %d",
31+
(immutable_file_number) => {
32+
const { input } = setup(maxImmutable);
33+
fireEvent.change(input, {
34+
target: { value: immutable_file_number },
35+
});
36+
37+
expect(input.checkValidity()).toBeTruthy();
38+
expect(input.value).toBe(`${immutable_file_number}`);
39+
},
40+
);
41+
42+
it.each([-4328, -1, maxImmutable + 1, 528_432])(
43+
"Immutable above max or below 0 is invalid: %d",
44+
(immutable_file_number) => {
45+
const { input } = setup(maxImmutable);
46+
fireEvent.change(input, {
47+
target: { value: immutable_file_number },
48+
});
49+
50+
expect(input.checkValidity()).toBeFalsy();
51+
},
52+
);
53+
54+
it.each(["@124", "⚠️", "text"])("Non-number is invalid: %s", (immutable_file_number) => {
55+
const { input } = setup({ maxImmutable });
56+
fireEvent.change(input, {
57+
target: { value: immutable_file_number },
58+
});
59+
60+
expect(input.checkValidity()).toBeFalsy();
61+
});
62+
63+
it.each([0.1, 1.432, 67_782.32])("Float is invalid: %f", ({ immutable_file_number }) => {
64+
const { input } = setup({ maxImmutable });
65+
fireEvent.change(input, {
66+
target: { value: immutable_file_number },
67+
});
68+
69+
expect(input.checkValidity()).toBeFalsy();
70+
});
71+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { getImmutableUrlFromTemplate } from "@/utils";
2+
3+
const urlTemplate = "https://example.com/{immutable_file_number}.tar.zst";
4+
5+
describe("Get Immutable Url from template", () => {
6+
it.each([
7+
[0, "https://example.com/00000.tar.zst"],
8+
[1, "https://example.com/00001.tar.zst"],
9+
[23, "https://example.com/00023.tar.zst"],
10+
[437, "https://example.com/00437.tar.zst"],
11+
[9428, "https://example.com/09428.tar.zst"],
12+
[52983, "https://example.com/52983.tar.zst"],
13+
[103202, "https://example.com/103202.tar.zst"],
14+
])("padding immutable file number with zeros to 5 digits", (immutableFileNumber, expected) => {
15+
expect(getImmutableUrlFromTemplate(urlTemplate, immutableFileNumber)).toEqual(expected);
16+
});
17+
18+
it("numbers with more than 5 digits are not cut", () => {
19+
expect(getImmutableUrlFromTemplate(urlTemplate, 103202)).toEqual(
20+
"https://example.com/103202.tar.zst",
21+
);
22+
});
23+
});

0 commit comments

Comments
 (0)