add tests
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 16s

This commit is contained in:
Mylloon 2024-10-08 20:52:19 +02:00
parent 095aa7f68c
commit bfc3b008cc
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,4 +1,10 @@
import { nextTimeUnit, showDate, strToSeconds, TimeSecond } from "../../utils/time";
import {
nextTimeUnit,
showDate,
strToSeconds,
timeDeltaToString,
TimeSecond,
} from "../../utils/time";
describe("Date with correct timezone", () => {
const map = new Map([["u_time_at", "@"]]);
@ -84,3 +90,25 @@ describe("Next time unit", () => {
});
}
});
describe("Relative time", () => {
// Thoses tests are based on time, we have 10s of acceptance.
{
const name = Date.now() + (10 * TimeSecond.Minute + 30) * 1000;
test(name.toString(), () => {
expect(timeDeltaToString(name)).toMatch(/10m 30s|10m 2\ds/);
});
}
{
const name = Date.now() + (12 * TimeSecond.Hour + 30 * TimeSecond.Minute) * 1000;
test(name.toString(), () => {
expect(timeDeltaToString(name)).toMatch(/12h 30m|12h 29m 5\ds/);
});
}
{
const name = Date.now() + (TimeSecond.Week + TimeSecond.Day + 6 * TimeSecond.Hour) * 1000;
test(name.toString(), () => {
expect(timeDeltaToString(name)).toMatch(/1w 1d 6h|1w 1d 5h 59m 5\ds/);
});
}
});