Skip to content

Commit f201e22

Browse files
feat: countdown for your next slot
1 parent b494e37 commit f201e22

23 files changed

+727
-545
lines changed

src/__tests__/utils.test.ts

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import { expect, describe, it } from "vitest";
2+
import { getDurationText } from "../utils";
3+
import { Duration } from "luxon";
4+
5+
describe("getDurationText", () => {
6+
it("shows Never if duration is not defined", () => {
7+
expect(getDurationText(undefined)).toEqual("Never");
8+
});
9+
10+
it("shows 0s if duration is less than a second", () => {
11+
expect(
12+
getDurationText(
13+
Duration.fromObject({
14+
millisecond: 999,
15+
}),
16+
),
17+
).toEqual("0s");
18+
});
19+
20+
it("shows full duration", () => {
21+
expect(
22+
getDurationText(
23+
Duration.fromObject({
24+
years: 1,
25+
months: 2,
26+
weeks: 3,
27+
days: 20,
28+
hours: 13,
29+
minutes: 4,
30+
seconds: 52,
31+
}),
32+
),
33+
).toEqual("1y 2m 3w 20d 13h 4m 52s");
34+
});
35+
36+
it("shows full duration, omitting zero values", () => {
37+
expect(
38+
getDurationText(
39+
Duration.fromObject({
40+
years: 1,
41+
months: 2,
42+
weeks: 0,
43+
days: 20,
44+
hours: 0,
45+
minutes: 4,
46+
seconds: 0,
47+
}),
48+
),
49+
).toEqual("1y 2m 20d 4m");
50+
});
51+
52+
it("shows duration without seconds", () => {
53+
expect(
54+
getDurationText(
55+
Duration.fromObject({
56+
years: 1,
57+
months: 2,
58+
weeks: 3,
59+
days: 20,
60+
hours: 13,
61+
minutes: 4,
62+
seconds: 52,
63+
}),
64+
{
65+
omitSeconds: true,
66+
},
67+
),
68+
).toEqual("1y 2m 3w 20d 13h 4m");
69+
});
70+
71+
describe("showTwoSignificantUnits", () => {
72+
it("shows the two most significant units", () => {
73+
expect(
74+
getDurationText(
75+
Duration.fromObject({
76+
years: 1,
77+
months: 2,
78+
weeks: 3,
79+
days: 20,
80+
hours: 13,
81+
minutes: 4,
82+
seconds: 52,
83+
}),
84+
{
85+
showOnlyTwoSignificantUnits: true,
86+
},
87+
),
88+
).toEqual("1y 2m");
89+
90+
expect(
91+
getDurationText(
92+
Duration.fromObject({
93+
years: 0,
94+
months: 0,
95+
weeks: 3,
96+
days: 20,
97+
hours: 13,
98+
minutes: 4,
99+
seconds: 52,
100+
}),
101+
{
102+
showOnlyTwoSignificantUnits: true,
103+
},
104+
),
105+
).toEqual("3w 20d");
106+
});
107+
108+
it("shows zero second most significant unit value", () => {
109+
expect(
110+
getDurationText(
111+
Duration.fromObject({
112+
years: 0,
113+
months: 2,
114+
weeks: 0,
115+
days: 20,
116+
hours: 13,
117+
minutes: 4,
118+
seconds: 52,
119+
}),
120+
{
121+
showOnlyTwoSignificantUnits: true,
122+
},
123+
),
124+
).toEqual("2m 0w");
125+
});
126+
127+
it("shows only seconds if duration is less than a minute", () => {
128+
expect(
129+
getDurationText(
130+
Duration.fromObject({
131+
years: 0,
132+
months: 0,
133+
weeks: 0,
134+
days: 0,
135+
hours: 0,
136+
minutes: 0,
137+
seconds: 52,
138+
}),
139+
{
140+
showOnlyTwoSignificantUnits: false,
141+
},
142+
),
143+
).toEqual("52s");
144+
});
145+
});
146+
});

src/assets/private.svg

Lines changed: 4 additions & 4 deletions
Loading

0 commit comments

Comments
 (0)