Skip to content

Commit 960599a

Browse files
committed
update
1 parent 1b103d7 commit 960599a

File tree

3 files changed

+224
-0
lines changed

3 files changed

+224
-0
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import { describe, expect, it } from "vitest";
2+
import type { BuyWithCryptoStatus } from "../../../../../../../pay/buyWithCrypto/getStatus.js";
3+
import type { BuyWithFiatStatus } from "../../../../../../../pay/buyWithFiat/getStatus.js";
4+
import {
5+
getBuyWithCryptoStatusMeta,
6+
getBuyWithFiatStatusMeta,
7+
} from "./statusMeta.js";
8+
9+
describe("getBuyWithCryptoStatusMeta", () => {
10+
it('returns "Unknown" for NOT_FOUND status', () => {
11+
const result = getBuyWithCryptoStatusMeta({
12+
status: "NOT_FOUND",
13+
} as BuyWithCryptoStatus);
14+
expect(result).toEqual({
15+
status: "Unknown",
16+
color: "secondaryText",
17+
});
18+
});
19+
20+
it('returns "Bridging" for WAITING_BRIDGE subStatus', () => {
21+
const result = getBuyWithCryptoStatusMeta({
22+
status: "PENDING",
23+
subStatus: "WAITING_BRIDGE",
24+
} as BuyWithCryptoStatus);
25+
expect(result).toEqual({
26+
status: "Bridging",
27+
color: "accentText",
28+
loading: true,
29+
});
30+
});
31+
32+
it('returns "Incomplete" for PARTIAL_SUCCESS subStatus', () => {
33+
const result = getBuyWithCryptoStatusMeta({
34+
status: "COMPLETED",
35+
subStatus: "PARTIAL_SUCCESS",
36+
} as BuyWithCryptoStatus);
37+
expect(result).toEqual({
38+
status: "Incomplete",
39+
color: "secondaryText",
40+
});
41+
});
42+
43+
it('returns "Pending" for PENDING status', () => {
44+
const result = getBuyWithCryptoStatusMeta({
45+
status: "PENDING",
46+
} as BuyWithCryptoStatus);
47+
expect(result).toEqual({
48+
status: "Pending",
49+
color: "accentText",
50+
loading: true,
51+
});
52+
});
53+
54+
it('returns "Failed" for FAILED status', () => {
55+
const result = getBuyWithCryptoStatusMeta({
56+
status: "FAILED",
57+
} as BuyWithCryptoStatus);
58+
expect(result).toEqual({
59+
status: "Failed",
60+
color: "danger",
61+
});
62+
});
63+
64+
it('returns "Completed" for COMPLETED status', () => {
65+
const result = getBuyWithCryptoStatusMeta({
66+
status: "COMPLETED",
67+
} as BuyWithCryptoStatus);
68+
expect(result).toEqual({
69+
status: "Completed",
70+
color: "success",
71+
});
72+
});
73+
74+
it('returns "Unknown" for unhandled status', () => {
75+
const result = getBuyWithCryptoStatusMeta({
76+
// @ts-ignore Test purpose
77+
status: "Unknown",
78+
});
79+
expect(result).toEqual({
80+
status: "Unknown",
81+
color: "secondaryText",
82+
});
83+
});
84+
});
85+
86+
describe("getBuyWithFiatStatusMeta", () => {
87+
it('returns "Incomplete" for CRYPTO_SWAP_FALLBACK status', () => {
88+
const result = getBuyWithFiatStatusMeta({
89+
status: "CRYPTO_SWAP_FALLBACK",
90+
} as BuyWithFiatStatus);
91+
expect(result).toEqual({
92+
status: "Incomplete",
93+
color: "danger",
94+
step: 2,
95+
progressStatus: "partialSuccess",
96+
});
97+
});
98+
99+
it('returns "Pending" for CRYPTO_SWAP_IN_PROGRESS status', () => {
100+
const result = getBuyWithFiatStatusMeta({
101+
status: "CRYPTO_SWAP_IN_PROGRESS",
102+
} as BuyWithFiatStatus);
103+
expect(result).toEqual({
104+
status: "Pending",
105+
color: "accentText",
106+
loading: true,
107+
step: 2,
108+
progressStatus: "pending",
109+
});
110+
});
111+
112+
it('returns "Pending" for PENDING_ON_RAMP_TRANSFER status', () => {
113+
const result = getBuyWithFiatStatusMeta({
114+
status: "PENDING_ON_RAMP_TRANSFER",
115+
} as BuyWithFiatStatus);
116+
expect(result).toEqual({
117+
status: "Pending",
118+
color: "accentText",
119+
loading: true,
120+
step: 1,
121+
progressStatus: "pending",
122+
});
123+
});
124+
125+
it('returns "Completed" for ON_RAMP_TRANSFER_COMPLETED status', () => {
126+
const result = getBuyWithFiatStatusMeta({
127+
status: "ON_RAMP_TRANSFER_COMPLETED",
128+
} as BuyWithFiatStatus);
129+
expect(result).toEqual({
130+
status: "Completed",
131+
color: "success",
132+
loading: true,
133+
step: 1,
134+
progressStatus: "completed",
135+
});
136+
});
137+
138+
it('returns "Action Required" for CRYPTO_SWAP_REQUIRED status', () => {
139+
const result = getBuyWithFiatStatusMeta({
140+
status: "CRYPTO_SWAP_REQUIRED",
141+
} as BuyWithFiatStatus);
142+
expect(result).toEqual({
143+
status: "Action Required",
144+
color: "accentText",
145+
step: 2,
146+
progressStatus: "actionRequired",
147+
});
148+
});
149+
150+
it('returns "Failed" for PAYMENT_FAILED status', () => {
151+
const result = getBuyWithFiatStatusMeta({
152+
status: "PAYMENT_FAILED",
153+
} as BuyWithFiatStatus);
154+
expect(result).toEqual({
155+
status: "Failed",
156+
color: "danger",
157+
step: 1,
158+
progressStatus: "failed",
159+
});
160+
});
161+
162+
it('returns "Unknown" for unhandled status', () => {
163+
const result = getBuyWithFiatStatusMeta({
164+
// @ts-ignore
165+
status: "UNKNOWN_STATUS",
166+
});
167+
expect(result).toEqual({
168+
status: "Unknown",
169+
color: "secondaryText",
170+
step: 1,
171+
progressStatus: "unknown",
172+
});
173+
});
174+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { describe, expect, it } from "vitest";
2+
import { formatSeconds } from "./formatSeconds.js";
3+
4+
describe("formatSeconds", () => {
5+
it("formats seconds to hours and minutes when over 3600 seconds", () => {
6+
expect(formatSeconds(3601)).toBe("1 Hours 0 Minutes");
7+
expect(formatSeconds(7200)).toBe("2 Hours 0 Minutes");
8+
expect(formatSeconds(5400)).toBe("1 Hours 30 Minutes");
9+
expect(formatSeconds(12345)).toBe("3 Hours 25 Minutes");
10+
});
11+
12+
it("formats seconds to minutes when between 61 and 3600 seconds", () => {
13+
expect(formatSeconds(61)).toBe("2 Minutes");
14+
expect(formatSeconds(120)).toBe("2 Minutes");
15+
expect(formatSeconds(3599)).toBe("60 Minutes");
16+
expect(formatSeconds(1800)).toBe("30 Minutes");
17+
});
18+
19+
it('formats seconds to "Xs" when 60 seconds or less', () => {
20+
expect(formatSeconds(60)).toBe("60s");
21+
expect(formatSeconds(59)).toBe("59s");
22+
expect(formatSeconds(1)).toBe("1s");
23+
expect(formatSeconds(0)).toBe("0s");
24+
});
25+
26+
it("handles decimal inputs by rounding down for hours/minutes and up for minutes only", () => {
27+
expect(formatSeconds(3661.5)).toBe("1 Hours 1 Minutes");
28+
expect(formatSeconds(119.9)).toBe("2 Minutes");
29+
});
30+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, it } from "vitest";
2+
import { getBuyTokenAmountFontSize } from "./utils.js";
3+
4+
describe("getBuyTokenAmountFontSize", () => {
5+
it("returns 26px for strings longer than 10 characters", () => {
6+
expect(getBuyTokenAmountFontSize("12345678901")).toBe("26px");
7+
expect(getBuyTokenAmountFontSize("1234567890123")).toBe("26px");
8+
});
9+
10+
it("returns 34px for strings longer than 6 characters but not more than 10", () => {
11+
expect(getBuyTokenAmountFontSize("1234567")).toBe("34px");
12+
expect(getBuyTokenAmountFontSize("1234567890")).toBe("34px");
13+
});
14+
15+
it("returns 50px for strings 6 characters or shorter", () => {
16+
expect(getBuyTokenAmountFontSize("123456")).toBe("50px");
17+
expect(getBuyTokenAmountFontSize("12345")).toBe("50px");
18+
expect(getBuyTokenAmountFontSize("")).toBe("50px");
19+
});
20+
});

0 commit comments

Comments
 (0)