@davoodmehraban89 / Aram-1 / commits / fa64baf
Fork 0

feat(ui): Phase 5 RTL workbench — setup/import/mapping/statements/drill-down/approval

- Vite dev proxy forwards relative /api to FastAPI (no browser localhost calls); allowedHosts for the Arena live preview. - Typed API client + types; Persian-locale rial formatting. - Components: CompanySetup, LedgerUpload, MappingPanel (unknown-account queue, note creation, mapping import/export), StatementView (BS/IS/CF/EQ tabs, build, per-line drill-down), DrillDown (source file/sheet/row lineage), ApprovalPanel (controls + hard approval gate). - Unit tests (11): format, api client, CompanySetup, DrillDown, App shell. Playwright e2e: app smoke + full workflow (backend-gated via ARAM_E2E_BACKEND). - Gates: eslint/tsc/vitest/build pass; mypy services clean. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>

davoodmehraban89 committed Dec 3, 2026 at 11:12 UTC fa64baff38d2ea831123a51a7441c02646595f80
21 files changed +1160 -25
frontend/e2e/workflow.spec.ts new
+41
@@ -0,0 +1,41 @@
1 +import { expect, test } from '@playwright/test'
2 +
3 +// The full workflow runs against the live FastAPI backend proxied at /api.
4 +// It is skipped when the backend is not reachable so the frontend-only CI job
5 +// stays green; set ARAM_E2E_BACKEND=1 (with the backend running) to enable it.
6 +const backendEnabled = process.env.ARAM_E2E_BACKEND === '1'
7 +
8 +test.describe('full workbench workflow', () => {
9 + test.skip(!backendEnabled, 'requires the backend (ARAM_E2E_BACKEND=1)')
10 +
11 + test('company -> ledger -> mapping -> statement -> drill-down -> approval', async ({ page }) => {
12 + await page.goto('/')
13 +
14 + // 1. Company + fiscal year
15 + await page.getByLabel('کد شرکت').fill('E2E')
16 + await page.getByLabel('نام شرکت').fill('شرکت آزمون')
17 + await page.getByLabel('سال مالی').fill('1404')
18 + await page.getByRole('button', { name: 'ایجاد' }).click()
19 + await expect(page.getByText('بارگذاری دفتر کل')).toBeVisible()
20 +
21 + // 2. Ledger import (real source workbook)
22 + const ledger = page.locator('input[type="file"]').first()
23 + await ledger.setInputFiles('../data/source_ledgers/source_1404.xlsx')
24 + await page.getByRole('button', { name: 'درون‌ریزی' }).click()
25 + await expect(page.getByText(/درون‌ریزی شد/)).toBeVisible({ timeout: 120000 })
26 +
27 + // 3. Build statements
28 + await page.getByRole('button', { name: 'ساخت صورت‌های مالی' }).click()
29 + await expect(page.getByRole('button', { name: 'مشاهدهٔ منبع' }).first()).toBeVisible({
30 + timeout: 60000,
31 + })
32 +
33 + // 4. Drill-down to a source row
34 + await page.getByRole('button', { name: 'مشاهدهٔ منبع' }).first().click()
35 + await expect(page.getByText('ریشه‌یابی:')).toBeVisible()
36 +
37 + // 5. Controls + approval gate
38 + await page.getByRole('button', { name: 'اجرای کنترل‌ها' }).click()
39 + await expect(page.getByText(/کنترل‌های حیاتی/)).toBeVisible()
40 + })
41 +})
frontend/package-lock.json
+18
@@ -16,6 +16,7 @@
16 "@playwright/test": "^1.48.2",
17 "@testing-library/jest-dom": "^6.6.2",
18 "@testing-library/react": "^16.0.1",
19 + "@types/node": "^22.20.7",
20 "@types/react": "^18.3.12",
21 "@types/react-dom": "^18.3.1",
22 "@vitejs/plugin-react": "^4.3.3",
@@ -1665,6 +1666,16 @@
1666 "dev": true,
1667 "license": "MIT"
1668 },
1669 + "node_modules/@types/node": {
1670 + "version": "22.20.7",
1671 + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.7.tgz",
1672 + "integrity": "sha512-F/Mcc4pD3YwXQCG50hb8BjB5RmrOere6hge7n2XHf0V8tpkZOVEjwYv9Ql7n0MpMn8Bv7+q12P9w6UHsBm0Sfw==",
1673 + "dev": true,
1674 + "license": "MIT",
1675 + "dependencies": {
1676 + "undici-types": "~6.21.0"
1677 + }
1678 + },
1679 "node_modules/@types/prop-types": {
1680 "version": "15.7.15",
1681 "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.15.tgz",
@@ -4327,6 +4338,13 @@
4338 "typescript": ">=4.8.4 <6.1.0"
4339 }
4340 },
4341 + "node_modules/undici-types": {
4342 + "version": "6.21.0",
4343 + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
4344 + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
4345 + "dev": true,
4346 + "license": "MIT"
4347 + },
4348 "node_modules/update-browserslist-db": {
4349 "version": "1.4.0",
4350 "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.4.0.tgz",
frontend/package.json
+1 -1
@@ -1 +1 @@
1 -{"name": "aram-frontend", "private": true, "version": "0.1.0", "type": "module", "scripts": {"dev": "vite", "build": "tsc --noEmit && vite build", "preview": "vite preview", "lint": "eslint .", "typecheck": "tsc --noEmit", "test": "vitest run", "test:watch": "vitest", "test:e2e": "playwright test"}, "dependencies": {"react": "^18.3.1", "react-dom": "^18.3.1"}, "devDependencies": {"@eslint/js": "^9.13.0", "@playwright/test": "^1.48.2", "@testing-library/jest-dom": "^6.6.2", "@testing-library/react": "^16.0.1", "@types/react": "^18.3.12", "@types/react-dom": "^18.3.1", "@vitejs/plugin-react": "^4.3.3", "eslint": "^9.13.0", "eslint-plugin-react-hooks": "^5.0.0", "globals": "^15.11.0", "jsdom": "^25.0.1", "typescript": "^5.6.3", "typescript-eslint": "^8.11.0", "vite": "^5.4.10", "vitest": "^2.1.4"}}
\ No newline at end of file
1 +{"name":"aram-frontend","private":true,"version":"0.1.0","type":"module","scripts":{"dev":"vite","build":"tsc --noEmit && vite build","preview":"vite preview","lint":"eslint .","typecheck":"tsc --noEmit","test":"vitest run","test:watch":"vitest","test:e2e":"playwright test"},"dependencies":{"react":"^18.3.1","react-dom":"^18.3.1"},"devDependencies":{"@eslint/js":"^9.13.0","@playwright/test":"^1.48.2","@testing-library/jest-dom":"^6.6.2","@testing-library/react":"^16.0.1","@types/node":"^22.20.7","@types/react":"^18.3.12","@types/react-dom":"^18.3.1","@vitejs/plugin-react":"^4.3.3","eslint":"^9.13.0","eslint-plugin-react-hooks":"^5.0.0","globals":"^15.11.0","jsdom":"^25.0.1","typescript":"^5.6.3","typescript-eslint":"^8.11.0","vite":"^5.4.10","vitest":"^2.1.4"}}
\ No newline at end of file
frontend/src/App.test.tsx
+28 -8
@@ -1,17 +1,37 @@
1 -import { fireEvent, render, screen } from '@testing-library/react'
2 -import { describe, expect, it } from 'vitest'
1 +import { render, screen } from '@testing-library/react'
2 +import { describe, expect, it, vi } from 'vitest'
3 import App from './App'
4
5 +vi.mock('./api/client', async () => {
6 + const actual = await vi.importActual<typeof import('./api/client')>('./api/client')
7 + return {
8 + ...actual,
9 + api: {
10 + createCompany: vi.fn(),
11 + uploadLedger: vi.fn(),
12 + unknownAccounts: vi.fn().mockResolvedValue({ count: 0, accounts: [] }),
13 + listStatements: vi.fn().mockResolvedValue({ statements: [], section_labels_fa: {} }),
14 + buildStatements: vi.fn(),
15 + drillDown: vi.fn(),
16 + preflight: vi.fn(),
17 + approve: vi.fn(),
18 + createNote: vi.fn(),
19 + createMapping: vi.fn(),
20 + importMappings: vi.fn(),
21 + exportMappingsUrl: (id: number) => `/api/v1/years/${id}/mappings/export`,
22 + },
23 + }
24 +})
25 +
26 describe('App', () => {
6 - it('renders the Persian RTL heading', () => {
27 + it('renders the Persian RTL workbench heading', () => {
28 render(<App />)
8 - expect(screen.getByRole('heading', { name: /آرام/ })).toBeInTheDocument()
29 + expect(screen.getByRole('heading', { name: /آرام — میز کار/ })).toBeInTheDocument()
30 })
31
11 - it('increments the counter on click', () => {
32 + it('shows the company setup form before a year exists', () => {
33 render(<App />)
13 - const button = screen.getByRole('button')
14 - fireEvent.click(button)
15 - expect(button).toHaveTextContent('شمارش: 1')
34 + expect(screen.getByRole('button', { name: 'ایجاد' })).toBeInTheDocument()
35 + expect(screen.queryByText('بارگذاری دفتر کل')).not.toBeInTheDocument()
36 })
37 })
frontend/src/App.tsx
+32 -8
@@ -1,18 +1,42 @@
1 import { useState } from 'react'
2 +import type { CompanyResult } from './api/types'
3 +import ApprovalPanel from './components/ApprovalPanel'
4 +import CompanySetup from './components/CompanySetup'
5 +import LedgerUpload from './components/LedgerUpload'
6 +import MappingPanel from './components/MappingPanel'
7 +import StatementView from './components/StatementView'
8 +import { faNumber } from './lib/format'
9
10 /**
4 - * Aram workbench shell (Phase 5 foundation). RTL Persian UI; the full
5 - * statement/mapping/drill-down screens are built on this scaffold in Phase 5.
11 + * Aram workbench (Phase 5): company/year setup -> ledger import -> mapping ->
12 + * statements with source drill-down -> controls and approval. RTL Persian UI;
13 + * all data flows through the relative /api/v1 backend (no runtime network).
14 */
15 export default function App() {
8 - const [count, setCount] = useState(0)
16 + const [company, setCompany] = useState<CompanyResult | null>(null)
17 + const [statementRefresh, setStatementRefresh] = useState(0)
18 +
19 return (
20 <main dir="rtl" lang="fa" className="app">
11 - <h1>آرام — میز کار صورت‌های مالی</h1>
12 - <p>نسخهٔ پایهٔ رابط کاربری (فاز ۵)</p>
13 - <button type="button" onClick={() => setCount((c) => c + 1)}>
14 - شمارش: {count}
15 - </button>
21 + <header className="app-header">
22 + <h1>آرام — میز کار صورت‌های مالی</h1>
23 + {company && (
24 + <p className="muted">
25 + سال مالی {faNumber(company.year)} · وضعیت {company.status}
26 + </p>
27 + )}
28 + </header>
29 +
30 + <CompanySetup onCreated={setCompany} />
31 +
32 + {company && (
33 + <>
34 + <LedgerUpload yearId={company.year_id} onImported={() => setStatementRefresh((k) => k + 1)} />
35 + <MappingPanel yearId={company.year_id} />
36 + <StatementView yearId={company.year_id} refreshKey={statementRefresh} />
37 + <ApprovalPanel yearId={company.year_id} />
38 + </>
39 + )}
40 </main>
41 )
42 }
frontend/src/api/client.test.ts new
+37
@@ -0,0 +1,37 @@
1 +import { afterEach, describe, expect, it, vi } from 'vitest'
2 +import { api, ApiError } from './client'
3 +
4 +afterEach(() => {
5 + vi.restoreAllMocks()
6 +})
7 +
8 +describe('api client', () => {
9 + it('posts company creation as JSON and returns the parsed result', async () => {
10 + const fetchMock = vi.fn().mockResolvedValue({
11 + ok: true,
12 + json: async () => ({ company_id: 1, year_id: 2, year: 1404, status: 'Draft' }),
13 + })
14 + vi.stubGlobal('fetch', fetchMock)
15 +
16 + const result = await api.createCompany('C1', 'شرکت نمونه', 1404)
17 +
18 + expect(result.year_id).toBe(2)
19 + const [url, init] = fetchMock.mock.calls[0]
20 + expect(url).toBe('/api/v1/companies')
21 + expect(init.method).toBe('POST')
22 + expect(JSON.parse(init.body)).toEqual({ code: 'C1', name: 'شرکت نمونه', year: 1404 })
23 + })
24 +
25 + it('throws ApiError with the backend detail on failure', async () => {
26 + vi.stubGlobal(
27 + 'fetch',
28 + vi.fn().mockResolvedValue({ ok: false, status: 422, json: async () => ({ detail: 'سال یافت نشد' }) }),
29 + )
30 + await expect(api.preflight(999)).rejects.toMatchObject({ status: 422, message: 'سال یافت نشد' })
31 + await expect(api.preflight(999)).rejects.toBeInstanceOf(ApiError)
32 + })
33 +
34 + it('builds the relative export URL', () => {
35 + expect(api.exportMappingsUrl(7)).toBe('/api/v1/years/7/mappings/export')
36 + })
37 +})
frontend/src/api/client.ts new
+86
@@ -0,0 +1,86 @@
1 +import type {
2 + ApproveResult,
3 + BuildResult,
4 + CompanyResult,
5 + DrillDownResult,
6 + LedgerImportResult,
7 + MappingImportResult,
8 + MappingResult,
9 + NoteResult,
10 + PreflightResult,
11 + StatementsResult,
12 + UnknownAccountsResult,
13 +} from './types'
14 +
15 +const BASE = '/api/v1'
16 +
17 +export class ApiError extends Error {
18 + status: number
19 + constructor(status: number, message: string) {
20 + super(message)
21 + this.status = status
22 + this.name = 'ApiError'
23 + }
24 +}
25 +
26 +async function request<T>(path: string, init?: RequestInit): Promise<T> {
27 + const res = await fetch(`${BASE}${path}`, init)
28 + if (!res.ok) {
29 + let detail = `HTTP ${res.status}`
30 + try {
31 + const body = (await res.json()) as { detail?: unknown }
32 + if (body.detail !== undefined) {
33 + detail = typeof body.detail === 'string' ? body.detail : JSON.stringify(body.detail)
34 + }
35 + } catch {
36 + /* keep default detail */
37 + }
38 + throw new ApiError(res.status, detail)
39 + }
40 + return (await res.json()) as T
41 +}
42 +
43 +function json(body: unknown): RequestInit {
44 + return {
45 + method: 'POST',
46 + headers: { 'Content-Type': 'application/json' },
47 + body: JSON.stringify(body),
48 + }
49 +}
50 +
51 +function multipart(file: File): RequestInit {
52 + const form = new FormData()
53 + form.append('file', file)
54 + return { method: 'POST', body: form }
55 +}
56 +
57 +export const api = {
58 + createCompany: (code: string, name: string, year: number) =>
59 + request<CompanyResult>('/companies', json({ code, name, year })),
60 +
61 + uploadLedger: (yearId: number, file: File) =>
62 + request<LedgerImportResult>(`/years/${yearId}/ledger`, multipart(file)),
63 +
64 + createNote: (yearId: number, noteNumber: string, title: string, statement: string, section: string) =>
65 + request<NoteResult>(`/years/${yearId}/notes`, json({ note_number: noteNumber, title, statement, section })),
66 +
67 + createMapping: (yearId: number, accountCode: string, targetNoteId: number) =>
68 + request<MappingResult>(`/years/${yearId}/mappings`, json({ account_code: accountCode, target_note_id: targetNoteId })),
69 +
70 + buildStatements: (yearId: number) => request<BuildResult>(`/years/${yearId}/statements/build`, { method: 'POST' }),
71 +
72 + listStatements: (yearId: number) => request<StatementsResult>(`/years/${yearId}/statements`),
73 +
74 + drillDown: (lineId: number) => request<DrillDownResult>(`/statement-lines/${lineId}/drilldown`),
75 +
76 + preflight: (yearId: number) => request<PreflightResult>(`/years/${yearId}/preflight`),
77 +
78 + approve: (yearId: number, actor: string) => request<ApproveResult>(`/years/${yearId}/approve`, json({ actor })),
79 +
80 + unknownAccounts: (yearId: number) => request<UnknownAccountsResult>(`/years/${yearId}/unknown-accounts`),
81 +
82 + importMappings: (yearId: number, file: File) =>
83 + request<MappingImportResult>(`/years/${yearId}/mappings/import`, multipart(file)),
84 +
85 + exportMappingsUrl: (yearId: number) => `${BASE}/years/${yearId}/mappings/export`,
86 +}
frontend/src/api/types.ts new
+109
@@ -0,0 +1,109 @@
1 +export interface CompanyResult {
2 + company_id: number
3 + year_id: number
4 + year: number
5 + status: string
6 +}
7 +
8 +export interface LedgerImportResult {
9 + source_document_id: number
10 + file_hash: string
11 + import_version: number
12 + accounts_imported: number
13 + rows_for_year: number
14 +}
15 +
16 +export interface StatementLine {
17 + id: number
18 + line_order: number
19 + label: string
20 + mapped_total: string | null
21 + target_note_id: number | null
22 +}
23 +
24 +export interface Statement {
25 + id: number
26 + type: string
27 + label_fa: string
28 + version: number
29 + lines: StatementLine[]
30 +}
31 +
32 +export interface StatementsResult {
33 + statements: Statement[]
34 + section_labels_fa: Record<string, string>
35 +}
36 +
37 +export interface BuildResult {
38 + statements: { id: number; type: string; version: number }[]
39 + unmapped_accounts: string[]
40 +}
41 +
42 +export interface DrillDownAccount {
43 + account_full_code: string
44 + account_name: string
45 + closing: string
46 + statement_balance: string | null
47 + effective_balance: string
48 + source: {
49 + filename: string | null
50 + file_hash: string | null
51 + sheet: string | null
52 + row: number
53 + }
54 +}
55 +
56 +export interface DrillDownResult {
57 + line_id: number
58 + line_label: string
59 + mapped_total: string | null
60 + note: { id: number; note_number: string; title: string } | null
61 + accounts: DrillDownAccount[]
62 +}
63 +
64 +export interface ControlResult {
65 + code: string
66 + severity: string
67 + passed: boolean
68 + message_fa: string
69 +}
70 +
71 +export interface PreflightResult {
72 + year: number
73 + can_approve: boolean
74 + controls: ControlResult[]
75 +}
76 +
77 +export interface ApproveResult {
78 + approved: boolean
79 + status?: string
80 + blocking?: { code: string; message_fa: string }[]
81 +}
82 +
83 +export interface UnknownAccount {
84 + account_full_code: string
85 + account_name: string
86 + closing: string
87 + row_count: number
88 +}
89 +
90 +export interface UnknownAccountsResult {
91 + count: number
92 + accounts: UnknownAccount[]
93 +}
94 +
95 +export interface NoteResult {
96 + note_id: number
97 + note_number: string
98 +}
99 +
100 +export interface MappingResult {
101 + mapping_id: number
102 + account_code: string
103 +}
104 +
105 +export interface MappingImportResult {
106 + created: number
107 + notes_created: number
108 + errors: string[]
109 +}
frontend/src/components/ApprovalPanel.tsx new
+106
@@ -0,0 +1,106 @@
1 +import { useState } from 'react'
2 +import { api, ApiError } from '../api/client'
3 +import type { ApproveResult, PreflightResult } from '../api/types'
4 +
5 +interface Props {
6 + yearId: number
7 +}
8 +
9 +export default function ApprovalPanel({ yearId }: Props) {
10 + const [preflight, setPreflight] = useState<PreflightResult | null>(null)
11 + const [approveResult, setApproveResult] = useState<ApproveResult | null>(null)
12 + const [actor, setActor] = useState('')
13 + const [busy, setBusy] = useState(false)
14 + const [error, setError] = useState<string | null>(null)
15 +
16 + async function runPreflight() {
17 + setBusy(true)
18 + setError(null)
19 + try {
20 + setPreflight(await api.preflight(yearId))
21 + } catch (err) {
22 + setError(err instanceof ApiError ? err.message : String(err))
23 + } finally {
24 + setBusy(false)
25 + }
26 + }
27 +
28 + async function approve() {
29 + setBusy(true)
30 + setError(null)
31 + try {
32 + setApproveResult(await api.approve(yearId, actor.trim()))
33 + } catch (err) {
34 + setError(err instanceof ApiError ? err.message : String(err))
35 + } finally {
36 + setBusy(false)
37 + }
38 + }
39 +
40 + return (
41 + <section className="card">
42 + <h2>کنترل‌ها و تصویب</h2>
43 + <div className="row">
44 + <button type="button" onClick={runPreflight} disabled={busy}>
45 + اجرای کنترل‌ها
46 + </button>
47 + <label>
48 + تصویب‌کننده
49 + <input value={actor} onChange={(e) => setActor(e.target.value)} maxLength={128} />
50 + </label>
51 + <button type="button" onClick={approve} disabled={busy}>
52 + تصویب سال
53 + </button>
54 + </div>
55 +
56 + {preflight && (
57 + <div>
58 + <p className={preflight.can_approve ? 'ok' : 'error'}>
59 + {preflight.can_approve ? 'همهٔ کنترل‌های حیاتی قبول شدند.' : 'کنترل‌های حیاتی رد شدند — تصویب مسدود است.'}
60 + </p>
61 + <table>
62 + <thead>
63 + <tr>
64 + <th>کد</th>
65 + <th>شدت</th>
66 + <th>وضعیت</th>
67 + <th>پیام</th>
68 + </tr>
69 + </thead>
70 + <tbody>
71 + {preflight.controls.map((c) => (
72 + <tr key={c.code}>
73 + <td className="mono">{c.code}</td>
74 + <td>{c.severity}</td>
75 + <td className={c.passed ? 'ok' : 'error'}>{c.passed ? 'قبول' : 'رد'}</td>
76 + <td>{c.message_fa}</td>
77 + </tr>
78 + ))}
79 + </tbody>
80 + </table>
81 + </div>
82 + )}
83 +
84 + {approveResult && (
85 + <div>
86 + {approveResult.approved ? (
87 + <p className="ok">سال تصویب شد.</p>
88 + ) : (
89 + <div className="error">
90 + <p>تصویب مسدود شد:</p>
91 + <ul>
92 + {approveResult.blocking?.map((b) => (
93 + <li key={b.code}>
94 + {b.code}: {b.message_fa}
95 + </li>
96 + ))}
97 + </ul>
98 + </div>
99 + )}
100 + </div>
101 + )}
102 +
103 + {error && <p className="error">{error}</p>}
104 + </section>
105 + )
106 +}
frontend/src/components/CompanySetup.test.tsx new
+29
@@ -0,0 +1,29 @@
1 +import { fireEvent, render, screen, waitFor } from '@testing-library/react'
2 +import { describe, expect, it, vi } from 'vitest'
3 +import { api } from '../api/client'
4 +import CompanySetup from './CompanySetup'
5 +
6 +vi.mock('../api/client', async () => {
7 + const actual = await vi.importActual<typeof import('../api/client')>('../api/client')
8 + return { ...actual, api: { createCompany: vi.fn() } }
9 +})
10 +
11 +describe('CompanySetup', () => {
12 + it('creates a company and reports the result', async () => {
13 + vi.mocked(api.createCompany).mockResolvedValue({
14 + company_id: 1,
15 + year_id: 2,
16 + year: 1404,
17 + status: 'Draft',
18 + })
19 + const onCreated = vi.fn()
20 + render(<CompanySetup onCreated={onCreated} />)
21 +
22 + fireEvent.change(screen.getByLabelText('کد شرکت'), { target: { value: 'C1' } })
23 + fireEvent.change(screen.getByLabelText('نام شرکت'), { target: { value: 'شرکت نمونه' } })
24 + fireEvent.click(screen.getByRole('button', { name: 'ایجاد' }))
25 +
26 + await waitFor(() => expect(onCreated).toHaveBeenCalledWith(expect.objectContaining({ year_id: 2 })))
27 + expect(api.createCompany).toHaveBeenCalledWith('C1', 'شرکت نمونه', 1404)
28 + })
29 +})
frontend/src/components/CompanySetup.tsx new
+59
@@ -0,0 +1,59 @@
1 +import { useState } from 'react'
2 +import { api, ApiError } from '../api/client'
3 +import type { CompanyResult } from '../api/types'
4 +
5 +interface Props {
6 + onCreated: (result: CompanyResult) => void
7 +}
8 +
9 +export default function CompanySetup({ onCreated }: Props) {
10 + const [code, setCode] = useState('')
11 + const [name, setName] = useState('')
12 + const [year, setYear] = useState('1404')
13 + const [busy, setBusy] = useState(false)
14 + const [error, setError] = useState<string | null>(null)
15 +
16 + async function submit(e: React.FormEvent) {
17 + e.preventDefault()
18 + setBusy(true)
19 + setError(null)
20 + try {
21 + const result = await api.createCompany(code.trim(), name.trim(), Number(year))
22 + onCreated(result)
23 + } catch (err) {
24 + setError(err instanceof ApiError ? err.message : String(err))
25 + } finally {
26 + setBusy(false)
27 + }
28 + }
29 +
30 + return (
31 + <form className="card" onSubmit={submit}>
32 + <h2>شرکت و سال مالی</h2>
33 + <div className="row">
34 + <label>
35 + کد شرکت
36 + <input value={code} onChange={(e) => setCode(e.target.value)} required maxLength={64} />
37 + </label>
38 + <label>
39 + نام شرکت
40 + <input value={name} onChange={(e) => setName(e.target.value)} required maxLength={256} />
41 + </label>
42 + <label>
43 + سال مالی
44 + <input
45 + value={year}
46 + onChange={(e) => setYear(e.target.value)}
47 + required
48 + inputMode="numeric"
49 + pattern="[0-9]+"
50 + />
51 + </label>
52 + <button type="submit" disabled={busy}>
53 + {busy ? 'در حال ایجاد…' : 'ایجاد'}
54 + </button>
55 + </div>
56 + {error && <p className="error">{error}</p>}
57 + </form>
58 + )
59 +}
frontend/src/components/DrillDown.test.tsx new
+30
@@ -0,0 +1,30 @@
1 +import { render, screen } from '@testing-library/react'
2 +import { describe, expect, it, vi } from 'vitest'
3 +import type { DrillDownResult } from '../api/types'
4 +import DrillDown from './DrillDown'
5 +
6 +const result: DrillDownResult = {
7 + line_id: 1,
8 + line_label: '۱۰ — دارایی‌های جاری',
9 + mapped_total: '673740637',
10 + note: { id: 5, note_number: '10', title: 'دارایی‌های جاری' },
11 + accounts: [
12 + {
13 + account_full_code: '1101',
14 + account_name: 'نقد و بانک',
15 + closing: '0',
16 + statement_balance: '673740637',
17 + effective_balance: '673740637',
18 + source: { filename: 'source_1404.xlsx', file_hash: 'abc', sheet: 'Sheet1', row: 42 },
19 + },
20 + ],
21 +}
22 +
23 +describe('DrillDown', () => {
24 + it('renders the source file and row for traceability', () => {
25 + render(<DrillDown result={result} onClose={vi.fn()} />)
26 + expect(screen.getByText('source_1404.xlsx')).toBeInTheDocument()
27 + expect(screen.getByText('42')).toBeInTheDocument()
28 + expect(screen.getByText('نقد و بانک')).toBeInTheDocument()
29 + })
30 +})
frontend/src/components/DrillDown.tsx new
+55
@@ -0,0 +1,55 @@
1 +import type { DrillDownResult } from '../api/types'
2 +import { formatRial } from '../lib/format'
3 +
4 +interface Props {
5 + result: DrillDownResult
6 + onClose: () => void
7 +}
8 +
9 +export default function DrillDown({ result, onClose }: Props) {
10 + return (
11 + <div className="drilldown">
12 + <div className="row spread">
13 + <h3>
14 + ریشه‌یابی: {result.line_label}
15 + {result.note && <span className="muted"> — یادداشت {result.note.note_number}</span>}
16 + </h3>
17 + <button type="button" onClick={onClose}>
18 + بستن
19 + </button>
20 + </div>
21 + <p className="muted">مبلغ نگاشت‌شده: {formatRial(result.mapped_total)} ریال</p>
22 + <table>
23 + <thead>
24 + <tr>
25 + <th>کد حساب</th>
26 + <th>نام حساب</th>
27 + <th>مبلغ مؤثر (ریال)</th>
28 + <th>فایل منبع</th>
29 + <th>برگه</th>
30 + <th>ردیف</th>
31 + </tr>
32 + </thead>
33 + <tbody>
34 + {result.accounts.map((acc, i) => (
35 + <tr key={`${acc.account_full_code}-${acc.source.row}-${i}`}>
36 + <td className="mono">{acc.account_full_code}</td>
37 + <td>{acc.account_name}</td>
38 + <td className="num">{formatRial(acc.effective_balance)}</td>
39 + <td className="mono">{acc.source.filename ?? '—'}</td>
40 + <td>{acc.source.sheet ?? '—'}</td>
41 + <td className="num">{acc.source.row}</td>
42 + </tr>
43 + ))}
44 + {result.accounts.length === 0 && (
45 + <tr>
46 + <td colSpan={6} className="muted">
47 + حساب منبعی برای این خط یافت نشد.
48 + </td>
49 + </tr>
50 + )}
51 + </tbody>
52 + </table>
53 + </div>
54 + )
55 +}
frontend/src/components/LedgerUpload.tsx new
+51
@@ -0,0 +1,51 @@
1 +import { useRef, useState } from 'react'
2 +import { api, ApiError } from '../api/client'
3 +import type { LedgerImportResult } from '../api/types'
4 +import { faNumber } from '../lib/format'
5 +
6 +interface Props {
7 + yearId: number
8 + onImported: (result: LedgerImportResult) => void
9 +}
10 +
11 +export default function LedgerUpload({ yearId, onImported }: Props) {
12 + const inputRef = useRef<HTMLInputElement>(null)
13 + const [busy, setBusy] = useState(false)
14 + const [error, setError] = useState<string | null>(null)
15 + const [result, setResult] = useState<LedgerImportResult | null>(null)
16 +
17 + async function upload() {
18 + const file = inputRef.current?.files?.[0]
19 + if (!file) return
20 + setBusy(true)
21 + setError(null)
22 + try {
23 + const res = await api.uploadLedger(yearId, file)
24 + setResult(res)
25 + onImported(res)
26 + } catch (err) {
27 + setError(err instanceof ApiError ? err.message : String(err))
28 + } finally {
29 + setBusy(false)
30 + }
31 + }
32 +
33 + return (
34 + <section className="card">
35 + <h2>بارگذاری دفتر کل</h2>
36 + <div className="row">
37 + <input ref={inputRef} type="file" accept=".xlsx,.xls,.csv" />
38 + <button type="button" onClick={upload} disabled={busy}>
39 + {busy ? 'در حال درون‌ریزی…' : 'درون‌ریزی'}
40 + </button>
41 + </div>
42 + {result && (
43 + <p className="ok">
44 + {faNumber(result.rows_for_year)} ردیف سال جاری از {faNumber(result.accounts_imported)} حساب
45 + درون‌ریزی شد (نسخهٔ {faNumber(result.import_version)}).
46 + </p>
47 + )}
48 + {error && <p className="error">{error}</p>}
49 + </section>
50 + )
51 +}
frontend/src/components/MappingPanel.tsx new
+153
@@ -0,0 +1,153 @@
1 +import { useCallback, useEffect, useRef, useState } from 'react'
2 +import { api, ApiError } from '../api/client'
3 +import type { UnknownAccount } from '../api/types'
4 +import { faNumber, formatRial } from '../lib/format'
5 +
6 +interface Props {
7 + yearId: number
8 +}
9 +
10 +export default function MappingPanel({ yearId }: Props) {
11 + const [queue, setQueue] = useState<UnknownAccount[]>([])
12 + const [noteNumber, setNoteNumber] = useState('')
13 + const [noteTitle, setNoteTitle] = useState('')
14 + const [statement, setStatement] = useState('BS')
15 + const [section, setSection] = useState('Assets')
16 + const [targetCode, setTargetCode] = useState('')
17 + const [busy, setBusy] = useState(false)
18 + const [message, setMessage] = useState<string | null>(null)
19 + const [error, setError] = useState<string | null>(null)
20 + const importRef = useRef<HTMLInputElement>(null)
21 +
22 + const refresh = useCallback(async () => {
23 + try {
24 + const res = await api.unknownAccounts(yearId)
25 + setQueue(res.accounts)
26 + } catch (err) {
27 + setError(err instanceof ApiError ? err.message : String(err))
28 + }
29 + }, [yearId])
30 +
31 + useEffect(() => {
32 + void refresh()
33 + }, [refresh])
34 +
35 + async function mapAccount(code: string) {
36 + setBusy(true)
37 + setError(null)
38 + setMessage(null)
39 + try {
40 + const note = await api.createNote(yearId, noteNumber.trim(), noteTitle.trim(), statement, section)
41 + await api.createMapping(yearId, code, note.note_id)
42 + setMessage(`حساب ${code} به یادداشت ${noteNumber} نگاشت شد.`)
43 + await refresh()
44 + } catch (err) {
45 + setError(err instanceof ApiError ? err.message : String(err))
46 + } finally {
47 + setBusy(false)
48 + }
49 + }
50 +
51 + async function importMappings() {
52 + const file = importRef.current?.files?.[0]
53 + if (!file) return
54 + setBusy(true)
55 + setError(null)
56 + try {
57 + const res = await api.importMappings(yearId, file)
58 + setMessage(`${faNumber(res.created)} نگاشت و ${faNumber(res.notes_created)} یادداشت ایجاد شد.`)
59 + if (res.errors.length) setError(res.errors.join('؛ '))
60 + await refresh()
61 + } catch (err) {
62 + setError(err instanceof ApiError ? err.message : String(err))
63 + } finally {
64 + setBusy(false)
65 + }
66 + }
67 +
68 + return (
69 + <section className="card">
70 + <h2>نگاشت حساب‌ها به یادداشت‌ها</h2>
71 +
72 + <div className="row">
73 + <label>
74 + شمارهٔ یادداشت
75 + <input value={noteNumber} onChange={(e) => setNoteNumber(e.target.value)} />
76 + </label>
77 + <label>
78 + عنوان یادداشت
79 + <input value={noteTitle} onChange={(e) => setNoteTitle(e.target.value)} />
80 + </label>
81 + <label>
82 + صورت مالی
83 + <select value={statement} onChange={(e) => setStatement(e.target.value)}>
84 + <option value="BS">ترازنامه</option>
85 + <option value="IS">سود و زیان</option>
86 + <option value="CF">جریان‌های نقدی</option>
87 + <option value="EQ">حقوق مالکانه</option>
88 + </select>
89 + </label>
90 + <label>
91 + بخش
92 + <input value={section} onChange={(e) => setSection(e.target.value)} />
93 + </label>
94 + </div>
95 +
96 + <div className="row">
97 + <input ref={importRef} type="file" accept=".xlsx" />
98 + <button type="button" onClick={importMappings} disabled={busy}>
99 + درون‌ریزی نگاشت‌ها
100 + </button>
101 + <a className="button" href={api.exportMappingsUrl(yearId)} download>
102 + برون‌بری نگاشت‌ها
103 + </a>
104 + </div>
105 +
106 + {message && <p className="ok">{message}</p>}
107 + {error && <p className="error">{error}</p>}
108 +
109 + <h3>صف حساب‌های نگاشت‌نشده ({faNumber(queue.length)})</h3>
110 + <table>
111 + <thead>
112 + <tr>
113 + <th>کد حساب</th>
114 + <th>نام حساب</th>
115 + <th>مانده (ریال)</th>
116 + <th>ردیف‌ها</th>
117 + <th>عملیات</th>
118 + </tr>
119 + </thead>
120 + <tbody>
121 + {queue.map((acc) => (
122 + <tr key={acc.account_full_code}>
123 + <td className="mono">{acc.account_full_code}</td>
124 + <td>{acc.account_name}</td>
125 + <td className="num">{formatRial(acc.closing)}</td>
126 + <td className="num">{faNumber(acc.row_count)}</td>
127 + <td>
128 + <button
129 + type="button"
130 + disabled={busy || !noteNumber || !noteTitle}
131 + onClick={() => {
132 + setTargetCode(acc.account_full_code)
133 + void mapAccount(acc.account_full_code)
134 + }}
135 + >
136 + نگاشت به یادداشت بالا
137 + </button>
138 + {targetCode === acc.account_full_code && <span className="muted"> ✓</span>}
139 + </td>
140 + </tr>
141 + ))}
142 + {queue.length === 0 && (
143 + <tr>
144 + <td colSpan={5} className="muted">
145 + حساب نگاشت‌نشده‌ای وجود ندارد.
146 + </td>
147 + </tr>
148 + )}
149 + </tbody>
150 + </table>
151 + </section>
152 + )
153 +}
frontend/src/components/StatementView.tsx new
+123
@@ -0,0 +1,123 @@
1 +import { useCallback, useEffect, useState } from 'react'
2 +import { api, ApiError } from '../api/client'
3 +import type { DrillDownResult, Statement } from '../api/types'
4 +import { faNumber, formatRial } from '../lib/format'
5 +import DrillDown from './DrillDown'
6 +
7 +interface Props {
8 + yearId: number
9 + refreshKey: number
10 +}
11 +
12 +export default function StatementView({ yearId, refreshKey }: Props) {
13 + const [statements, setStatements] = useState<Statement[]>([])
14 + const [active, setActive] = useState<string>('BS')
15 + const [busy, setBusy] = useState(false)
16 + const [error, setError] = useState<string | null>(null)
17 + const [unmapped, setUnmapped] = useState<string[]>([])
18 + const [drill, setDrill] = useState<DrillDownResult | null>(null)
19 +
20 + const load = useCallback(async () => {
21 + try {
22 + const res = await api.listStatements(yearId)
23 + setStatements(res.statements)
24 + } catch (err) {
25 + setError(err instanceof ApiError ? err.message : String(err))
26 + }
27 + }, [yearId])
28 +
29 + useEffect(() => {
30 + void load()
31 + }, [load, refreshKey])
32 +
33 + async function build() {
34 + setBusy(true)
35 + setError(null)
36 + try {
37 + const res = await api.buildStatements(yearId)
38 + setUnmapped(res.unmapped_accounts)
39 + await load()
40 + } catch (err) {
41 + setError(err instanceof ApiError ? err.message : String(err))
42 + } finally {
43 + setBusy(false)
44 + }
45 + }
46 +
47 + async function openDrill(lineId: number) {
48 + setError(null)
49 + try {
50 + setDrill(await api.drillDown(lineId))
51 + } catch (err) {
52 + setError(err instanceof ApiError ? err.message : String(err))
53 + }
54 + }
55 +
56 + const current = statements.find((s) => s.type === active)
57 +
58 + return (
59 + <section className="card">
60 + <h2>صورت‌های مالی</h2>
61 + <div className="row">
62 + <button type="button" onClick={build} disabled={busy}>
63 + {busy ? 'در حال ساخت…' : 'ساخت صورت‌های مالی'}
64 + </button>
65 + <div className="tabs">
66 + {['BS', 'IS', 'CF', 'EQ'].map((t) => (
67 + <button
68 + key={t}
69 + type="button"
70 + className={active === t ? 'tab active' : 'tab'}
71 + onClick={() => setActive(t)}
72 + >
73 + {t}
74 + </button>
75 + ))}
76 + </div>
77 + </div>
78 +
79 + {unmapped.length > 0 && (
80 + <p className="error">حساب‌های نگاشت‌نشده: {unmapped.join('، ')}</p>
81 + )}
82 + {error && <p className="error">{error}</p>}
83 +
84 + {current ? (
85 + <table>
86 + <thead>
87 + <tr>
88 + <th>ردیف</th>
89 + <th>شرح</th>
90 + <th>مبلغ (ریال)</th>
91 + <th>ریشه‌یابی</th>
92 + </tr>
93 + </thead>
94 + <tbody>
95 + {current.lines.map((line) => (
96 + <tr key={line.id}>
97 + <td className="num">{faNumber(line.line_order)}</td>
98 + <td>{line.label}</td>
99 + <td className="num">{formatRial(line.mapped_total)}</td>
100 + <td>
101 + <button type="button" onClick={() => void openDrill(line.id)}>
102 + مشاهدهٔ منبع
103 + </button>
104 + </td>
105 + </tr>
106 + ))}
107 + {current.lines.length === 0 && (
108 + <tr>
109 + <td colSpan={4} className="muted">
110 + این صورت هنوز ساخته نشده است.
111 + </td>
112 + </tr>
113 + )}
114 + </tbody>
115 + </table>
116 + ) : (
117 + <p className="muted">صورتی برای نمایش وجود ندارد؛ ابتدا «ساخت صورت‌های مالی» را بزنید.</p>
118 + )}
119 +
120 + {drill && <DrillDown result={drill} onClose={() => setDrill(null)} />}
121 + </section>
122 + )
123 +}
frontend/src/index.css
+149 -6
@@ -2,25 +2,168 @@
2 font-family: Vazirmatn, system-ui, -apple-system, sans-serif;
3 direction: rtl;
4 color-scheme: light;
5 + --border: #d4dae2;
6 + --muted: #6b7684;
7 + --ok: #1a7f4b;
8 + --error: #b3261e;
9 + --accent: #2456a6;
10 +}
11 +
12 +* {
13 + box-sizing: border-box;
14 }
15
16 body {
17 margin: 0;
9 - background: #f6f7f9;
18 + background: #f4f6f8;
19 color: #1c2430;
20 + line-height: 1.7;
21 }
22
23 .app {
14 - max-width: 960px;
24 + max-width: 1080px;
25 margin: 0 auto;
16 - padding: 2rem 1.25rem;
26 + padding: 1.5rem 1.25rem 4rem;
27 +}
28 +
29 +.app-header h1 {
30 + margin: 0 0 0.25rem;
31 + font-size: 1.5rem;
32 +}
33 +
34 +.card {
35 + background: #fff;
36 + border: 1px solid var(--border);
37 + border-radius: 0.75rem;
38 + padding: 1.25rem;
39 + margin: 1rem 0;
40 }
41
19 -button {
42 +.card h2 {
43 + margin: 0 0 0.75rem;
44 + font-size: 1.15rem;
45 +}
46 +
47 +.card h3 {
48 + margin: 1rem 0 0.5rem;
49 + font-size: 1rem;
50 +}
51 +
52 +.row {
53 + display: flex;
54 + flex-wrap: wrap;
55 + gap: 0.75rem;
56 + align-items: flex-end;
57 + margin-bottom: 0.75rem;
58 +}
59 +
60 +.row.spread {
61 + justify-content: space-between;
62 +}
63 +
64 +label {
65 + display: flex;
66 + flex-direction: column;
67 + gap: 0.25rem;
68 + font-size: 0.85rem;
69 + color: var(--muted);
70 +}
71 +
72 +input,
73 +select {
74 font: inherit;
21 - padding: 0.5rem 1rem;
75 + padding: 0.45rem 0.6rem;
76 + border: 1px solid var(--border);
77 border-radius: 0.5rem;
23 - border: 1px solid #c3cad4;
78 background: #fff;
79 + min-width: 8rem;
80 +}
81 +
82 +button,
83 +.button {
84 + font: inherit;
85 + padding: 0.5rem 1rem;
86 + border-radius: 0.5rem;
87 + border: 1px solid var(--accent);
88 + background: var(--accent);
89 + color: #fff;
90 cursor: pointer;
91 + text-decoration: none;
92 + display: inline-block;
93 +}
94 +
95 +button:disabled {
96 + opacity: 0.5;
97 + cursor: not-allowed;
98 +}
99 +
100 +.button {
101 + background: #fff;
102 + color: var(--accent);
103 +}
104 +
105 +.tabs {
106 + display: flex;
107 + gap: 0.25rem;
108 +}
109 +
110 +.tab {
111 + background: #fff;
112 + color: var(--accent);
113 + border: 1px solid var(--border);
114 +}
115 +
116 +.tab.active {
117 + background: var(--accent);
118 + color: #fff;
119 +}
120 +
121 +table {
122 + width: 100%;
123 + border-collapse: collapse;
124 + margin-top: 0.5rem;
125 + font-size: 0.9rem;
126 +}
127 +
128 +th,
129 +td {
130 + border: 1px solid var(--border);
131 + padding: 0.4rem 0.6rem;
132 + text-align: right;
133 +}
134 +
135 +th {
136 + background: #eef1f5;
137 +}
138 +
139 +.num {
140 + text-align: left;
141 + font-variant-numeric: tabular-nums;
142 + direction: ltr;
143 +}
144 +
145 +.mono {
146 + font-family: ui-monospace, monospace;
147 + direction: ltr;
148 + text-align: left;
149 +}
150 +
151 +.muted {
152 + color: var(--muted);
153 +}
154 +
155 +.ok {
156 + color: var(--ok);
157 +}
158 +
159 +.error {
160 + color: var(--error);
161 +}
162 +
163 +.drilldown {
164 + margin-top: 1rem;
165 + border: 1px dashed var(--accent);
166 + border-radius: 0.5rem;
167 + padding: 1rem;
168 + background: #f8faff;
169 }
frontend/src/lib/format.test.ts new
+29
@@ -0,0 +1,29 @@
1 +import { describe, expect, it } from 'vitest'
2 +import { faNumber, formatRial } from './format'
3 +
4 +describe('formatRial', () => {
5 + it('returns a dash for empty values', () => {
6 + expect(formatRial(null)).toBe('—')
7 + expect(formatRial(undefined)).toBe('—')
8 + expect(formatRial('')).toBe('—')
9 + })
10 +
11 + it('groups thousands with Persian digits', () => {
12 + const out = formatRial('1234567')
13 + // fa-IR renders Persian digits (۱۲۳۵۶۷) with the ٬ separator.
14 + expect(out).toContain('۱')
15 + expect(out).toContain('۲۳')
16 + expect(out).toContain('۵۶')
17 + expect(out).not.toContain('1234567')
18 + })
19 +
20 + it('passes through non-numeric strings', () => {
21 + expect(formatRial('abc')).toBe('abc')
22 + })
23 +})
24 +
25 +describe('faNumber', () => {
26 + it('renders an integer without grouping', () => {
27 + expect(faNumber(1404)).toHaveLength(4)
28 + })
29 +})
frontend/src/lib/format.ts new
+12
@@ -0,0 +1,12 @@
1 +/** Format an exact integer-rial string with Persian-locale thousands separators. */
2 +export function formatRial(value: string | null | undefined): string {
3 + if (value === null || value === undefined || value === '') return '—'
4 + const n = Number(value)
5 + if (!Number.isFinite(n)) return value
6 + return n.toLocaleString('fa-IR')
7 +}
8 +
9 +/** Persian digits for a plain integer (counts, years). */
10 +export function faNumber(value: number): string {
11 + return value.toLocaleString('fa-IR', { useGrouping: false })
12 +}
frontend/tsconfig.json
+1 -1
@@ -1 +1 @@
1 -{"compilerOptions": {"target": "ES2022", "useDefineForClassFields": true, "lib": ["ES2022", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true, "moduleResolution": "bundler", "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true, "moduleDetection": "force", "noEmit": true, "jsx": "react-jsx", "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, "types": ["vitest/globals", "@testing-library/jest-dom"]}, "include": ["src", "vite.config.ts", "playwright.config.ts", "e2e"]}
\ No newline at end of file
1 +{"compilerOptions": {"target": "ES2022", "useDefineForClassFields": true, "lib": ["ES2022", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true, "moduleResolution": "bundler", "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true, "moduleDetection": "force", "noEmit": true, "jsx": "react-jsx", "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, "types": ["vitest/globals", "@testing-library/jest-dom", "node"]}, "include": ["src", "vite.config.ts", "playwright.config.ts", "e2e"]}
\ No newline at end of file
frontend/vite.config.ts
+11 -1
@@ -3,7 +3,17 @@ import { defineConfig } from 'vitest/config'
3
4 export default defineConfig({
5 plugins: [react()],
6 - server: { host: '127.0.0.1', port: 5173 },
6 + server: {
7 + host: '127.0.0.1',
8 + port: 5173,
9 + // Allow the Arena live-preview proxy host (and any host in dev).
10 + allowedHosts: true,
11 + proxy: {
12 + // Browser-facing code uses relative /api URLs; the dev server forwards
13 + // them to the FastAPI backend (never localhost from the browser).
14 + '/api': { target: 'http://127.0.0.1:8000', changeOrigin: true },
15 + },
16 + },
17 test: {
18 environment: 'jsdom',
19 globals: true,