Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
105 lines
3.2 KiB
TypeScript
105 lines
3.2 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import React from 'react';
|
|
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import DraftInvoiceDetailsCard from '../src/components/billing-dashboard/invoicing/DraftInvoiceDetailsCard';
|
|
|
|
const updateDraftInvoicePropertiesMock = vi.fn();
|
|
|
|
vi.mock('@alga-psa/billing/actions/invoiceModification', () => ({
|
|
updateDraftInvoiceProperties: (...args: unknown[]) => updateDraftInvoicePropertiesMock(...args),
|
|
}));
|
|
|
|
const draftInvoice = {
|
|
invoice_id: 'inv-1',
|
|
invoice_number: 'INV-1001',
|
|
invoice_date: '2026-04-01',
|
|
due_date: '2026-04-15',
|
|
status: 'draft',
|
|
total_amount: 10500,
|
|
currencyCode: 'USD',
|
|
client: {
|
|
name: 'Acme Co.',
|
|
logo: '',
|
|
address: '',
|
|
},
|
|
};
|
|
|
|
describe('DraftInvoiceDetailsCard', () => {
|
|
beforeEach(() => {
|
|
cleanup();
|
|
updateDraftInvoicePropertiesMock.mockReset();
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
});
|
|
|
|
it('saves updated invoice properties and clears the dirty state', async () => {
|
|
const onSaved = vi.fn();
|
|
updateDraftInvoicePropertiesMock.mockResolvedValue({
|
|
invoiceId: 'inv-1',
|
|
invoiceNumber: 'INV-2001',
|
|
invoiceDate: '2026-04-02',
|
|
dueDate: '2026-04-20',
|
|
});
|
|
|
|
render(<DraftInvoiceDetailsCard invoice={draftInvoice as any} onSaved={onSaved} />);
|
|
|
|
const saveButton = screen.getByRole('button', { name: 'Save' }) as HTMLButtonElement;
|
|
const cancelButton = screen.getByRole('button', { name: 'Cancel' }) as HTMLButtonElement;
|
|
const numberInput = screen.getByDisplayValue('INV-1001') as HTMLInputElement;
|
|
const invoiceDateInput = screen.getByDisplayValue('2026-04-01') as HTMLInputElement;
|
|
|
|
expect(saveButton.disabled).toBe(true);
|
|
expect(cancelButton.disabled).toBe(true);
|
|
|
|
fireEvent.change(numberInput, { target: { value: 'INV-2001' } });
|
|
fireEvent.change(invoiceDateInput, { target: { value: '2026-04-02' } });
|
|
|
|
expect(saveButton.disabled).toBe(false);
|
|
expect(cancelButton.disabled).toBe(false);
|
|
|
|
fireEvent.click(saveButton);
|
|
|
|
await waitFor(() => {
|
|
expect(updateDraftInvoicePropertiesMock).toHaveBeenCalledWith('inv-1', {
|
|
invoiceNumber: 'INV-2001',
|
|
invoiceDate: '2026-04-02',
|
|
dueDate: '2026-04-15',
|
|
});
|
|
});
|
|
|
|
await waitFor(() => {
|
|
expect(onSaved).toHaveBeenCalledWith({
|
|
invoiceId: 'inv-1',
|
|
invoiceNumber: 'INV-2001',
|
|
invoiceDate: '2026-04-02',
|
|
dueDate: '2026-04-20',
|
|
});
|
|
});
|
|
|
|
expect(saveButton.disabled).toBe(true);
|
|
expect(cancelButton.disabled).toBe(true);
|
|
expect(numberInput.value).toBe('INV-2001');
|
|
});
|
|
|
|
it('surfaces duplicate invoice number errors inline', async () => {
|
|
updateDraftInvoicePropertiesMock.mockRejectedValue(
|
|
new Error('Invoice number already exists. Choose a different number.')
|
|
);
|
|
|
|
render(<DraftInvoiceDetailsCard invoice={draftInvoice as any} />);
|
|
|
|
fireEvent.change(screen.getByDisplayValue('INV-1001'), {
|
|
target: { value: 'INV-0001' },
|
|
});
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
|
|
|
expect(await screen.findByText('Invoice number already exists. Choose a different number.')).toBeTruthy();
|
|
});
|
|
});
|