From 00beb6054771071fd5ae64a941c4275dfb865d51 Mon Sep 17 00:00:00 2001 From: letwebdev Date: Wed, 28 Feb 2024 18:58:47 +0800 Subject: [PATCH] test: supplement --- src/libs/__test__/formatter.spec.ts | 7 +++++++ src/libs/__test__/math.spec.ts | 11 +++++++++++ src/stores/__test__/settings.spec.ts | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/libs/__test__/formatter.spec.ts create mode 100644 src/libs/__test__/math.spec.ts create mode 100644 src/stores/__test__/settings.spec.ts diff --git a/src/libs/__test__/formatter.spec.ts b/src/libs/__test__/formatter.spec.ts new file mode 100644 index 0000000..0932aa5 --- /dev/null +++ b/src/libs/__test__/formatter.spec.ts @@ -0,0 +1,7 @@ +import { test, expect } from "vitest" +import { convertUnixTimeStampToReadableTime } from "../formatter" + +test("test", () => { + const time = convertUnixTimeStampToReadableTime(1709112255) + expect(time).toBe("2024-02-28 17:24") +}) diff --git a/src/libs/__test__/math.spec.ts b/src/libs/__test__/math.spec.ts new file mode 100644 index 0000000..492dcd7 --- /dev/null +++ b/src/libs/__test__/math.spec.ts @@ -0,0 +1,11 @@ +import { generateRandomInteger } from "../math" + +for (let i = 0; i < 5; i++) { + test("generate random integer", () => { + expect(generateRandomInteger(5, 1)).toBeLessThanOrEqual(5) + expect(generateRandomInteger(5, 1)).toBeGreaterThanOrEqual(1) + + expect(generateRandomInteger(7, 2)).toBeLessThanOrEqual(7) + expect(generateRandomInteger(5, 2)).toBeGreaterThanOrEqual(2) + }) +} diff --git a/src/stores/__test__/settings.spec.ts b/src/stores/__test__/settings.spec.ts new file mode 100644 index 0000000..4a8ea6a --- /dev/null +++ b/src/stores/__test__/settings.spec.ts @@ -0,0 +1,17 @@ +import { useSettingsStore } from "../settings" + +describe("Settings Store", () => { + beforeEach(() => { + // creates a fresh pinia and makes it active + // so it's automatically picked up by any useStore() call + // without having to pass it to it: `useStore(pinia)` + setActivePinia(createPinia()) + }) + + it("reset setting", () => { + const store = useSettingsStore() + store.settings.displayingItemId.value = false + store.settingOperations.reset() + expect(store.settings.displayingItemId.value).toBeTruthy() + }) +})