Open source personal finance application
fix(types): resolve TypeScript errors in Form, trns types and tests
Ilya Komichev354cda0e585a
diff --git a/app/app/components/categories/Form.vue b/app/app/components/categories/Form.vueindex 0bfe8614..3a89bb8a 100644--- a/app/app/components/categories/Form.vue+++ b/app/app/components/categories/Form.vue@@ -60,7 +60,7 @@ const rootsWithOwnChildren = computed<Set<CategoryId>>(() => {const out = new Set<CategoryId>()for (const cid of Object.keys(items)) {const pid = items[cid]?.parentId- if (pid && pid !== 0 && typeof pid === 'string')+ if (pid && typeof pid === 'string')out.add(pid)}return outdiff --git a/app/app/components/trns/types.ts b/app/app/components/trns/types.tsindex 2f7fec6b..7a305a6e 100644--- a/app/app/components/trns/types.ts+++ b/app/app/components/trns/types.ts@@ -66,6 +66,10 @@ export type TransferFull = Transfer & TrnItemFullBase & {export type TrnItemFull = TransactionFull | TransferFull+export function isTransfer(trn: TrnItem | TrnItemFull | undefined): trn is Transfer | TransferFull {+ return trn?.type === TrnType.Transfer+}+export type Trns = Record<TrnId, TrnItem>export type TrnsGetterProps = {diff --git a/app/app/components/trns/useTrnsStore.test.ts b/app/app/components/trns/useTrnsStore.test.tsindex 2855fb67..a72e0e1e 100644--- a/app/app/components/trns/useTrnsStore.test.ts+++ b/app/app/components/trns/useTrnsStore.test.ts@@ -4,6 +4,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import type { Transaction, Transfer } from '~/components/trns/types'+import { isTransfer } from '~/components/trns/types'+// --- Entity-specific mocks ---vi.mock('~~/services/convex/api', () => ({@@ -520,7 +522,8 @@ describe('useTrnsStore', () => {truncated: false,})- expect(store.items?.t1?.amount).toBe(200)+ const t1 = store.items?.t1+ expect(isTransfer(t1) ? undefined : t1?.amount).toBe(200)})it('removes docs in deletedIds', async () => {diff --git a/app/app/composables/useNavigationHistory.test.ts b/app/app/composables/useNavigationHistory.test.tsindex b33b7ca3..f9e6c3fd 100644--- a/app/app/composables/useNavigationHistory.test.ts+++ b/app/app/composables/useNavigationHistory.test.ts@@ -34,6 +34,10 @@ function stubNoNavigation() {vi.resetModules()}+function createRouterMock() {+ return { back: vi.fn(), push: vi.fn(), replace: vi.fn() }+}+const defaultEntries: Entry[] = [{ index: 0, key: 'k0', url: 'http://localhost/categories' },{ index: 1, key: 'k1', url: 'http://localhost/categories/abc' },@@ -62,7 +66,7 @@ describe('useNavigationHistory', () => {it('navigateAfterSave calls router.back when previous entry equals target', async () => {const { navigateAfterSave } = await import('~/composables/useNavigationHistory')- const router = { back: vi.fn(), replace: vi.fn() }+ const router = createRouterMock()navigateAfterSave(router, '/categories/abc')expect(router.back).toHaveBeenCalledOnce()expect(router.replace).not.toHaveBeenCalled()@@ -70,7 +74,7 @@ describe('useNavigationHistory', () => {it('navigateAfterSave calls router.replace when previous entry differs', async () => {const { navigateAfterSave } = await import('~/composables/useNavigationHistory')- const router = { back: vi.fn(), replace: vi.fn() }+ const router = createRouterMock()navigateAfterSave(router, '/somewhere/else')expect(router.replace).toHaveBeenCalledWith('/somewhere/else')expect(router.back).not.toHaveBeenCalled()@@ -79,7 +83,7 @@ describe('useNavigationHistory', () => {it('navigateAfterSave calls router.replace at the first entry (no prev)', async () => {stubNavigation([{ index: 0, key: 'k0', url: 'http://localhost/edit' }], 0)const { navigateAfterSave } = await import('~/composables/useNavigationHistory')- const router = { back: vi.fn(), replace: vi.fn() }+ const router = createRouterMock()navigateAfterSave(router, '/detail')expect(router.replace).toHaveBeenCalledWith('/detail')})@@ -158,7 +162,7 @@ describe('useNavigationHistory', () => {stubNoNavigation()const { canGoBack, navigateAfterSave } = await import('~/composables/useNavigationHistory')expect(canGoBack.value).toBe(false)- const router = { back: vi.fn(), replace: vi.fn() }+ const router = createRouterMock()navigateAfterSave(router, '/anywhere')expect(router.replace).toHaveBeenCalledWith('/anywhere')expect(router.back).not.toHaveBeenCalled()