* Move shared components to a packages/ directory so they can be publish more sensibly * Iterate towards split out shared-components module * Move shared component source into src/ subdir * Fix up imports * Include shared components in babel-ing (again) * Remove now unused dependencies * Update import in storybook preview * ...except of course they aren't unused if we import the shared components by source * Ignore shared components deps * Add shared-components to i18n paths and upgrade web-i18n to version that supports doing so * Move storybook stuff to shared-components * Seems we don't need this anymore... * Remove unused deps and remove storybook plugin from eslint * Presumably working-directory is only valid on run steps * Ignore dep & run prettier * Prettier on knips.ts * Hopefully run in right dir * Remember how to software write * Okay... how about THIS way? * Oh right, they were git ignored. Sigh. * Add concurrently * Ignore in knip * Better? * Paaaaaaaackageeeeeeees * More packages * Move playwright snapshots * Still need a custom snapshots dir * Add eslint back * Oh, now knip sees them * Fix another import * Don't lint shared-components with everything else Okay, eslint & tsconfig are tied too closely for this to work and running tsc on the shared components will need its deps installing * Maybe lint shared components please? * Not quite * Remove storybook again Re-check if it does work without it * Remove storybook eslint plugin as we're not linting storybook here anymore * Remove this too * We do need it here though
38 lines
1.8 KiB
TypeScript
38 lines
1.8 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 { humanizeTime } from "./humanize";
|
|
|
|
describe("humanizeTime", () => {
|
|
const now = new Date("2025-08-01T12:00:00Z").getTime();
|
|
|
|
beforeAll(() => {
|
|
jest.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);
|
|
});
|
|
});
|