Files
blap/packages/shared-components/src/utils/humanize.test.ts
T
Michael Telatynski 35fca4d339 Switch shared-components from jest & test-runner to vitest (#31800)
* Remove babel

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Remove duplicated patch-package dep

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Switch to @fetch-mock/vitest

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update tests to import & call vitest functions

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update test-utils imports

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update unit test snapshots

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Switch from jest->vitest for unit tests

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update visual test screenshots

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Switch from test-runner->vitest for visual tests

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update README

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update CI for shared-components unit & visual tests

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update yarn.lock

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update README

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Fix storybook trying to import vitest

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Fix css modules leaking between storybook tests

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Tweak screenshot update script to accept args

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
2026-01-22 14:17:36 +00:00

40 lines
1.9 KiB
TypeScript

/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import { describe, it, beforeAll, vi, expect } from "vitest";
import { humanizeTime } from "./humanize";
describe("humanizeTime", () => {
const now = new Date("2025-08-01T12:00:00Z").getTime();
beforeAll(() => {
vi.useFakeTimers().setSystemTime(now);
});
it.each([
// Past
["returns 'a few seconds ago' for <15s ago", now - 5000, "a few seconds ago"],
["returns 'about a minute ago' for <75s ago", now - 60000, "about a minute ago"],
["returns '20 minutes ago' for <45min ago", now - 20 * 60000, "20 minutes ago"],
["returns 'about an hour ago' for <75min ago", now - 70 * 60000, "about an hour ago"],
["returns '5 hours ago' for <23h ago", now - 5 * 3600000, "5 hours ago"],
["returns 'about a day ago' for <26h ago", now - 25 * 3600000, "about a day ago"],
["returns '3 days ago' for >26h ago", now - 3 * 24 * 3600000, "3 days ago"],
// Future
["returns 'a few seconds from now' for <15s ahead", now + 5000, "a few seconds from now"],
["returns 'about a minute from now' for <75s ahead", now + 60000, "about a minute from now"],
["returns '20 minutes from now' for <45min ahead", now + 20 * 60000, "20 minutes from now"],
["returns 'about an hour from now' for <75min ahead", now + 70 * 60000, "about an hour from now"],
["returns '5 hours from now' for <23h ahead", now + 5 * 3600000, "5 hours from now"],
["returns 'about a day from now' for <26h ahead", now + 25 * 3600000, "about a day from now"],
["returns '3 days from now' for >26h ahead", now + 3 * 24 * 3600000, "3 days from now"],
])("%s", (_, date, expected) => {
expect(humanizeTime(date)).toBe(expected);
});
});