Compare commits

..

6 commits

Author SHA1 Message Date
af8ba14b83
have to fix
Some checks failed
PR Check / lint-and-format (pull_request) Failing after 15s
2024-09-27 13:17:53 +02:00
d9e7543238
time tests 2024-09-27 13:16:17 +02:00
b78ccb801f
fix issue 2024-09-27 13:13:13 +02:00
013dbf4974
Ignore coverage directory 2024-09-27 13:04:37 +02:00
7de418362e
tests 2024-09-27 12:55:06 +02:00
8f06e0221f
now we fixed ts issues 2024-09-27 12:54:51 +02:00
7 changed files with 67 additions and 5 deletions

3
.gitignore vendored
View file

@ -15,3 +15,6 @@ dist/
# Debug file # Debug file
src/events/player/debug.ts src/events/player/debug.ts
# Jest
coverage/

View file

@ -291,8 +291,7 @@ Pour commencer, vous pouvez jeter un œil aux
Il est souhaité d'écrire des tests quand cela est possible. Il est souhaité d'écrire des tests quand cela est possible.
```ts ```ts
// eslint-disable-next-line @typescript-eslint/no-require-imports import { fnReturnsTrue } from "../src/utils/file";
const { fnReturnsTrue } = require("../src/utils/misc");
describe("test name", () => { describe("test name", () => {
{ {

View file

@ -45,7 +45,7 @@ export type dbReminder = {
* @param time raw text from user * @param time raw text from user
* @returns An object with the time and the option * @returns An object with the time and the option
*/ */
const splitTime = (time: string) => { export const splitTime = (time: string) => {
if (time?.endsWith("@")) { if (time?.endsWith("@")) {
return { time: time.slice(0, -1), option: OptionReminder.Mention }; return { time: time.slice(0, -1), option: OptionReminder.Mention };
} else if (time?.toLowerCase().endsWith("p")) { } else if (time?.toLowerCase().endsWith("p")) {

View file

@ -9,8 +9,9 @@ import moment from "moment-timezone";
*/ */
export const showDate = (tz: string, locale: Map<string, unknown>, date: Date) => { export const showDate = (tz: string, locale: Map<string, unknown>, date: Date) => {
const localeInfo = new Intl.Locale(tz); const localeInfo = new Intl.Locale(tz);
const intlTimezone = moment.tz.zonesForCountry(localeInfo.region ?? localeInfo.baseName);
const formattedDate = new Intl.DateTimeFormat(tz, { const formattedDate = new Intl.DateTimeFormat(tz, {
timeZone: moment.tz.zonesForCountry(localeInfo.region ?? localeInfo.baseName)[0], timeZone: intlTimezone ? intlTimezone[0] : "Etc/GMT",
dateStyle: "short", dateStyle: "short",
timeStyle: "medium", timeStyle: "medium",
}) })

View file

@ -4,7 +4,7 @@ import {
isImage, isImage,
removeExtension, removeExtension,
splitFilenameExtensions, splitFilenameExtensions,
} from "../src/utils/misc"; } from "../../src/utils/misc";
describe("Filename splitter", () => { describe("Filename splitter", () => {
{ {

View file

@ -0,0 +1,28 @@
import { OptionReminder, splitTime } from "../../src/utils/reminder";
describe("Time splitter", () => {
{
const name = "";
test(name, () => {
expect(splitTime(name)).toStrictEqual({ option: OptionReminder.Nothing, time: "" });
});
}
{
const name = "2m@p";
test(name, () => {
expect(splitTime(name)).toStrictEqual({ option: OptionReminder.Mention, time: "2m" });
});
}
{
const name = "41@";
test(name, () => {
expect(splitTime(name)).toStrictEqual({ option: OptionReminder.Mention, time: "41" });
});
}
{
const name = "0P";
test(name, () => {
expect(splitTime(name)).toStrictEqual({ option: OptionReminder.DirectMessage, time: "0" });
});
}
});

31
tests/utils/time.test.ts Normal file
View file

@ -0,0 +1,31 @@
import { showDate } from "../../src/utils/time";
describe("Date with correct timezone", () => {
const map: Map<string, unknown> = new Map([["u_time_at", "@"]]);
const date = new Date(1727434767686);
{
const name = "fr";
test(name, () => {
expect(showDate(name, map, date)).toBe("27/09/2024 @ 12:59:27");
});
}
{
const name = "en-US";
test(name, () => {
expect(showDate(name, map, date)).toBe("9/27/24, @ 1:59:27");
});
}
{
const name = "unknown";
test(name, () => {
expect(showDate(name, map, date)).toBe("27/09/2024 @ 10:59:27");
});
}
{
const name = "zh-CN";
test(name, () => {
expect(showDate(name, map, date)).toBe("2024/9/27 @ 18:59:27");
});
}
});