Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"test:core": "bun packages/scripts/src/testing/run.ts core",
"test:web": "bun packages/scripts/src/testing/run.ts web",
"test:scripts": "bun packages/scripts/src/testing/run.ts scripts",
"type-check": "bunx typescript@6.0.3 --noEmit && bunx typescript@6.0.3 -p packages/web/tsconfig.app.json --noEmit",
"type-check": "bunx typescript@6.0.3 --noEmit && bunx typescript@6.0.3 -p packages/web/tsconfig.app.json --noEmit && bun run type-check:web-tests",
"type-check:web-tests": "bunx typescript@6.0.3 -p packages/web/tsconfig.test.json --noEmit",
"verify": "bun packages/scripts/src/testing/verify.ts",
"build:backend": "bun packages/scripts/src/commands/build.backend.ts",
"build:web": "cd packages/web && bun --env-file=../backend/.env.local run build.ts"
Expand Down
6 changes: 6 additions & 0 deletions packages/web/src/__tests__/patched-jest.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import type { jest as JestNamespace } from "bun:test";
import type { TestingLibraryMatchers } from "@types/testing-library__jest-dom/matchers";

export declare const jest: typeof JestNamespace;

declare module "bun:test" {
interface Matchers<T = unknown>
extends TestingLibraryMatchers<unknown, void> {}
}
4 changes: 2 additions & 2 deletions packages/web/src/common/apis/base/base.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("BaseApi backend availability", () => {
it("marks the backend unavailable when fetch cannot reach it", async () => {
globalThis.fetch = mock(() =>
Promise.reject(new TypeError("Failed to fetch")),
) as typeof fetch;
) as unknown as typeof fetch;

await expect(BaseApi.get("/event")).rejects.toMatchObject({
name: "ApiError",
Expand All @@ -36,7 +36,7 @@ describe("BaseApi backend availability", () => {
markBackendUnavailable();
globalThis.fetch = mock(() =>
Promise.resolve(new Response("{}", { status: 200 })),
) as typeof fetch;
) as unknown as typeof fetch;

await BaseApi.get("/config");

Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/common/apis/util/api.util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
ApiErrorResponseSchema,
GoogleConnectErrorResponseSchema,
} from "@core/types/auth.types";
import { type ApiError } from "../api.types";
import { type ApiError, type ApiResponse } from "../api.types";
import {
getApiErrorCode,
parseApiError,
Expand Down
9 changes: 6 additions & 3 deletions packages/web/src/common/hooks/useBufferedVisibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ describe("useBufferedVisibility", () => {
) => {
const id = ++currentTimeoutId;
if (typeof callback === "function") {
activeTimeouts.set(id, { callback, delay: delay ?? 0 });
activeTimeouts.set(id, {
callback: () => callback(),
delay: delay ?? 0,
});
}
return id;
}) as typeof setTimeout);
}) as unknown as typeof setTimeout);

clearTimeoutSpy = spyOn(globalThis, "clearTimeout").mockImplementation(((
id?: number,
) => {
if (id !== undefined) {
activeTimeouts.delete(id);
}
}) as typeof clearTimeout);
}) as unknown as typeof clearTimeout);
});

afterEach(() => {
Expand Down
24 changes: 13 additions & 11 deletions packages/web/src/common/hooks/useEventDNDActions.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type DragEndEvent } from "@dnd-kit/core";
import { renderHook } from "@testing-library/react";
import { BehaviorSubject } from "rxjs";
import { Categories_Event } from "@core/types/event.types";
import dayjs from "@core/util/date/dayjs";
import { Categories_Event, type Schema_Event } from "@core/types/event.types";
import dayjs, { type Dayjs } from "@core/util/date/dayjs";
import {
ID_GRID_ALLDAY_ROW,
ID_GRID_MAIN,
Expand Down Expand Up @@ -41,16 +41,18 @@ mock.module("@web/views/Day/util/agenda/agenda.util", () => ({
// Provide a focused mock that includes the named export consumers expect.
// Keep a safe default for other exports so concurrent tests won't break imports.
getSnappedMinutes: mockGetSnappedMinutes,
getAgendaEventTitle: (event) => `${event?.title || ""} -`,
getAgendaEventTime: (d) => (d ? new Date(d).toISOString() : ""),
getAgendaEventPosition: (_date) => 0,
getNowLinePosition: (_date) => 0,
getEventTimeFromPosition: (_y, dateInView) =>
dateInView.startOf ? dateInView.startOf("day") : new Date(),
roundMinutesToNearestFifteen: (minutes) => Math.round(minutes / 15) * 15,
roundToNearestFifteenWithinHour: (minutes) =>
getAgendaEventTitle: (event: Schema_Event) => `${event.title ?? ""} -`,
getAgendaEventTime: (date: Date | string) =>
date ? new Date(date).toISOString() : "",
getAgendaEventPosition: (_date: Date) => 0,
getNowLinePosition: (_date: Date) => 0,
getEventTimeFromPosition: (_y: number, dateInView: Dayjs) =>
dateInView.startOf("day"),
roundMinutesToNearestFifteen: (minutes: number) =>
Math.round(minutes / 15) * 15,
roundToNearestFifteenWithinHour: (minutes: number) =>
Math.min(45, Math.round(minutes / 15) * 15),
getEventHeight: (_event) => 4,
getEventHeight: (_event: Pick<Schema_Event, "startDate" | "endDate">) => 4,
}));

mock.module("@web/ducks/events/selectors/event.selectors", () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ describe("useMainGridSelectionState", () => {
callback: TimerHandler,
) => {
if (typeof callback === "function") {
timeoutCallback = callback;
timeoutCallback = () => callback();
}
return 1;
}) as typeof setTimeout);
}) as unknown as typeof setTimeout);

act(() => {
selecting$.next(false);
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/common/hooks/useOpenAtCursor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ describe("useOpenAtCursor", () => {
callback: TimerHandler,
) => {
if (typeof callback === "function") {
timeoutCallbacks.push(callback);
timeoutCallbacks.push(() => callback());
}
return timeoutCallbacks.length;
}) as typeof setTimeout);
}) as unknown as typeof setTimeout);

// Reset state before each test
open$.next(false);
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/common/hooks/useVersionCheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("useVersionCheck", () => {
ok: true,
json: async () => ({ version: "dev" }),
});
global.fetch = fetchMock as typeof fetch;
global.fetch = fetchMock as unknown as typeof fetch;
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mock.module("@web/common/storage/adapter/adapter", () => ({

const { RemoteEventRepository } =
require("./remote.event.repository") as typeof import("./remote.event.repository");
type RemoteEventRepositoryInstance = InstanceType<typeof RemoteEventRepository>;

function createBackendUnavailableError(): Error {
const error = new Error("Request failed");
Expand All @@ -45,7 +46,7 @@ function createBackendUnavailableError(): Error {
}

describe("RemoteEventRepository", () => {
let repository: RemoteEventRepository;
let repository: RemoteEventRepositoryInstance;

beforeEach(() => {
mockCreate.mockClear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function createMockAdapter(): MockedStorageAdapter {
clearAllEvents: mock().mockResolvedValue(undefined),
getMigrationRecords: mock().mockResolvedValue([]),
setMigrationRecord: mock().mockResolvedValue(undefined),
close: mock(),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createMockStorageAdapter } from "@web/__tests__/utils/storage/mock-stor
import {
GridEventSchema,
type Schema_GridEvent,
type Schema_WebEvent,
} from "@web/common/types/web.event.types";
import { demoDataSeedMigration } from "./demo-data-seed";
import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test";
Expand Down Expand Up @@ -48,7 +49,7 @@ describe("demoDataSeedMigration", () => {
expect(adapter.putTasks).toHaveBeenCalled();

// Verify events were created (7 total: 5 today + 2 someday)
const eventsCall = adapter.putEvents.mock.calls[0][0];
const eventsCall = adapter.putEvents.mock.calls[0][0] as Schema_WebEvent[];
expect(eventsCall).toHaveLength(7);

// Verify tasks were created for 3 days
Expand Down Expand Up @@ -91,7 +92,7 @@ describe("demoDataSeedMigration", () => {

await demoDataSeedMigration.migrate(adapter);

const eventsCall = adapter.putEvents.mock.calls[0][0];
const eventsCall = adapter.putEvents.mock.calls[0][0] as Schema_WebEvent[];
const today = dayjs().toYearMonthDayString();

// Check that at least one timed event starts today
Expand All @@ -110,7 +111,9 @@ describe("demoDataSeedMigration", () => {
const yesterday = dayjs().subtract(1, "day").toYearMonthDayString();
const tomorrow = dayjs().add(1, "day").toYearMonthDayString();

const putTasksCalls = adapter.putTasks.mock.calls;
const putTasksCalls = adapter.putTasks.mock.calls as Array<
[string, ReturnType<typeof createMockTask>[]]
>;
const dateKeys = putTasksCalls.map((call) => call[0]);

expect(dateKeys).toContain(today);
Expand All @@ -124,11 +127,15 @@ describe("demoDataSeedMigration", () => {
await demoDataSeedMigration.migrate(adapter);

const yesterday = dayjs().subtract(1, "day").toYearMonthDayString();
const putTasksCalls = adapter.putTasks.mock.calls;
const putTasksCalls = adapter.putTasks.mock.calls as Array<
[string, ReturnType<typeof createMockTask>[]]
>;
const yesterdayCall = putTasksCalls.find((call) => call[0] === yesterday);

expect(yesterdayCall).toBeDefined();
const yesterdayTasks = yesterdayCall![1];
if (!yesterdayCall) {
throw new Error("Expected yesterday tasks to be seeded");
}
const yesterdayTasks = yesterdayCall[1];
expect(yesterdayTasks.every((t) => t.status === "completed")).toBe(true);
});

Expand All @@ -137,7 +144,7 @@ describe("demoDataSeedMigration", () => {

await demoDataSeedMigration.migrate(adapter);

const eventsCall = adapter.putEvents.mock.calls[0][0];
const eventsCall = adapter.putEvents.mock.calls[0][0] as Schema_WebEvent[];
const priorities = new Set(eventsCall.map((e) => e.priority));

expect(priorities.has(Priorities.WORK)).toBe(true);
Expand All @@ -151,7 +158,7 @@ describe("demoDataSeedMigration", () => {

await demoDataSeedMigration.migrate(adapter);

const eventsCall = adapter.putEvents.mock.calls[0][0];
const eventsCall = adapter.putEvents.mock.calls[0][0] as Schema_WebEvent[];
const somedayEvents = eventsCall.filter((e) => e.isSomeday);

expect(somedayEvents).toHaveLength(2);
Expand All @@ -162,7 +169,7 @@ describe("demoDataSeedMigration", () => {

await demoDataSeedMigration.migrate(adapter);

const eventsCall = adapter.putEvents.mock.calls[0][0];
const eventsCall = adapter.putEvents.mock.calls[0][0] as Schema_WebEvent[];
const allDayEvents = eventsCall.filter((e) => e.isAllDay);

expect(allDayEvents).toHaveLength(1);
Expand All @@ -174,7 +181,7 @@ describe("demoDataSeedMigration", () => {

await demoDataSeedMigration.migrate(adapter);

const eventsCall = adapter.putEvents.mock.calls[0][0];
const eventsCall = adapter.putEvents.mock.calls[0][0] as Schema_WebEvent[];
const timedEvents = eventsCall.filter((e) => !e.isSomeday && !e.isAllDay);

// RFC3339 offset format: "2026-02-19T16:30:00-08:00" (no milliseconds, offset instead of Z)
Expand All @@ -193,7 +200,7 @@ describe("demoDataSeedMigration", () => {

await demoDataSeedMigration.migrate(adapter);

const eventsCall = adapter.putEvents.mock.calls[0][0];
const eventsCall = adapter.putEvents.mock.calls[0][0] as Schema_WebEvent[];
const timedEvents = eventsCall.filter(
(e) => !e.isSomeday && !e.isAllDay,
) as Schema_GridEvent[];
Expand All @@ -219,7 +226,7 @@ describe("demoDataSeedMigration", () => {

await demoDataSeedMigration.migrate(adapter);

const eventsCall = adapter.putEvents.mock.calls[0][0];
const eventsCall = adapter.putEvents.mock.calls[0][0] as Schema_WebEvent[];

for (const event of eventsCall) {
if (!event.isSomeday && !event.isAllDay) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function createMockAdapter(): MockedStorageAdapter {
clearAllEvents: mock().mockResolvedValue(undefined),
getMigrationRecords: mock().mockResolvedValue([]),
setMigrationRecord: mock().mockResolvedValue(undefined),
close: mock(),
};
}

Expand Down Expand Up @@ -199,6 +198,7 @@ describe("localStorageTasksMigration", () => {

expect(localStorage.getItem(validKey)).toBeNull();
expect(localStorage.getItem(invalidKey)).toBe("invalid json {{{");
consoleErrorSpy.mockRestore();
});

it("skips non-array parsed values and does not remove key", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/common/utils/app-init.util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("app-init.util", () => {
timeoutCallback = () => callback();
}
return timeoutId;
}) as typeof setTimeout);
}) as unknown as typeof setTimeout);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("event-emitter.util", () => {
expect(val.x).toBe(100);
expect(val.y).toBe(100);
expect(val.element).toBe(mockElement);
expect(val.event).toBe(event);
expect(val.event as unknown).toBe(event);
subscription.unsubscribe();
resolve();
});
Expand Down
Loading