You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-30 02:21:17 +03:00
Apply prettier formatting
This commit is contained in:
@ -26,17 +26,17 @@ import { REPEATABLE_DATE } from "../test-utils";
|
||||
|
||||
describe("formatSeconds", () => {
|
||||
it("correctly formats time with hours", () => {
|
||||
expect(formatSeconds((60 * 60 * 3) + (60 * 31) + (55))).toBe("03:31:55");
|
||||
expect(formatSeconds((60 * 60 * 3) + (60 * 0) + (55))).toBe("03:00:55");
|
||||
expect(formatSeconds((60 * 60 * 3) + (60 * 31) + (0))).toBe("03:31:00");
|
||||
expect(formatSeconds(-((60 * 60 * 3) + (60 * 31) + (0)))).toBe("-03:31:00");
|
||||
expect(formatSeconds(60 * 60 * 3 + 60 * 31 + 55)).toBe("03:31:55");
|
||||
expect(formatSeconds(60 * 60 * 3 + 60 * 0 + 55)).toBe("03:00:55");
|
||||
expect(formatSeconds(60 * 60 * 3 + 60 * 31 + 0)).toBe("03:31:00");
|
||||
expect(formatSeconds(-(60 * 60 * 3 + 60 * 31 + 0))).toBe("-03:31:00");
|
||||
});
|
||||
|
||||
it("correctly formats time without hours", () => {
|
||||
expect(formatSeconds((60 * 60 * 0) + (60 * 31) + (55))).toBe("31:55");
|
||||
expect(formatSeconds((60 * 60 * 0) + (60 * 0) + (55))).toBe("00:55");
|
||||
expect(formatSeconds((60 * 60 * 0) + (60 * 31) + (0))).toBe("31:00");
|
||||
expect(formatSeconds(-((60 * 60 * 0) + (60 * 31) + (0)))).toBe("-31:00");
|
||||
expect(formatSeconds(60 * 60 * 0 + 60 * 31 + 55)).toBe("31:55");
|
||||
expect(formatSeconds(60 * 60 * 0 + 60 * 0 + 55)).toBe("00:55");
|
||||
expect(formatSeconds(60 * 60 * 0 + 60 * 31 + 0)).toBe("31:00");
|
||||
expect(formatSeconds(-(60 * 60 * 0 + 60 * 31 + 0))).toBe("-31:00");
|
||||
});
|
||||
});
|
||||
|
||||
@ -44,7 +44,7 @@ describe("formatRelativeTime", () => {
|
||||
let dateSpy;
|
||||
beforeAll(() => {
|
||||
dateSpy = jest
|
||||
.spyOn(global.Date, 'now')
|
||||
.spyOn(global.Date, "now")
|
||||
// Tuesday, 2 November 2021 11:18:03 UTC
|
||||
.mockImplementation(() => 1635851883000);
|
||||
});
|
||||
@ -81,24 +81,24 @@ describe("formatRelativeTime", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatDuration()', () => {
|
||||
describe("formatDuration()", () => {
|
||||
type TestCase = [string, string, number];
|
||||
|
||||
const MINUTE_MS = 60000;
|
||||
const HOUR_MS = MINUTE_MS * 60;
|
||||
|
||||
it.each<TestCase>([
|
||||
['rounds up to nearest day when more than 24h - 40 hours', '2d', 40 * HOUR_MS],
|
||||
['rounds down to nearest day when more than 24h - 26 hours', '1d', 26 * HOUR_MS],
|
||||
['24 hours', '1d', 24 * HOUR_MS],
|
||||
['rounds to nearest hour when less than 24h - 23h', '23h', 23 * HOUR_MS],
|
||||
['rounds to nearest hour when less than 24h - 6h and 10min', '6h', 6 * HOUR_MS + 10 * MINUTE_MS],
|
||||
['rounds to nearest hours when less than 24h', '2h', 2 * HOUR_MS + 124234],
|
||||
['rounds to nearest minute when less than 1h - 59 minutes', '59m', 59 * MINUTE_MS],
|
||||
['rounds to nearest minute when less than 1h - 1 minute', '1m', MINUTE_MS],
|
||||
['rounds to nearest second when less than 1min - 59 seconds', '59s', 59000],
|
||||
['rounds to 0 seconds when less than a second - 123ms', '0s', 123],
|
||||
])('%s formats to %s', (_description, expectedResult, input) => {
|
||||
["rounds up to nearest day when more than 24h - 40 hours", "2d", 40 * HOUR_MS],
|
||||
["rounds down to nearest day when more than 24h - 26 hours", "1d", 26 * HOUR_MS],
|
||||
["24 hours", "1d", 24 * HOUR_MS],
|
||||
["rounds to nearest hour when less than 24h - 23h", "23h", 23 * HOUR_MS],
|
||||
["rounds to nearest hour when less than 24h - 6h and 10min", "6h", 6 * HOUR_MS + 10 * MINUTE_MS],
|
||||
["rounds to nearest hours when less than 24h", "2h", 2 * HOUR_MS + 124234],
|
||||
["rounds to nearest minute when less than 1h - 59 minutes", "59m", 59 * MINUTE_MS],
|
||||
["rounds to nearest minute when less than 1h - 1 minute", "1m", MINUTE_MS],
|
||||
["rounds to nearest second when less than 1min - 59 seconds", "59s", 59000],
|
||||
["rounds to 0 seconds when less than a second - 123ms", "0s", 123],
|
||||
])("%s formats to %s", (_description, expectedResult, input) => {
|
||||
expect(formatDuration(input)).toEqual(expectedResult);
|
||||
});
|
||||
});
|
||||
@ -109,12 +109,12 @@ describe("formatPreciseDuration", () => {
|
||||
const DAY_MS = HOUR_MS * 24;
|
||||
|
||||
it.each<[string, string, number]>([
|
||||
['3 days, 6 hours, 48 minutes, 59 seconds', '3d 6h 48m 59s', 3 * DAY_MS + 6 * HOUR_MS + 48 * MINUTE_MS + 59000],
|
||||
['6 hours, 48 minutes, 59 seconds', '6h 48m 59s', 6 * HOUR_MS + 48 * MINUTE_MS + 59000],
|
||||
['48 minutes, 59 seconds', '48m 59s', 48 * MINUTE_MS + 59000],
|
||||
['59 seconds', '59s', 59000],
|
||||
['0 seconds', '0s', 0],
|
||||
])('%s formats to %s', (_description, expectedResult, input) => {
|
||||
["3 days, 6 hours, 48 minutes, 59 seconds", "3d 6h 48m 59s", 3 * DAY_MS + 6 * HOUR_MS + 48 * MINUTE_MS + 59000],
|
||||
["6 hours, 48 minutes, 59 seconds", "6h 48m 59s", 6 * HOUR_MS + 48 * MINUTE_MS + 59000],
|
||||
["48 minutes, 59 seconds", "48m 59s", 48 * MINUTE_MS + 59000],
|
||||
["59 seconds", "59s", 59000],
|
||||
["0 seconds", "0s", 0],
|
||||
])("%s formats to %s", (_description, expectedResult, input) => {
|
||||
expect(formatPreciseDuration(input)).toEqual(expectedResult);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user