Files
ksef-pdf-generator/src/lib-public/generators/FA1/Adnotacje2.spec.ts
Michał Chudy b9972746aa add source code
2025-11-21 10:22:39 +01:00

44 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { generateDostawy } from './Adnotacje';
import { Adnotacje } from '../../types/fa1.types';
vi.mock('../../../shared/PDF-functions', () => ({
formatText: vi.fn((text, format) => ({ text, format })),
hasValue: vi.fn((val) => Boolean(val && val._text)),
}));
const formatText = vi.fn((text, format) => ({ text, format }));
const hasValue = vi.fn((val) => Boolean(val && val._text));
describe(generateDostawy.name, () => {
beforeEach(() => {
vi.clearAllMocks();
hasValue.mockImplementation((val) => Boolean(val && val._text));
});
it('returns empty array when no values', () => {
const adnotacje: Adnotacje = {};
const result = generateDostawy(adnotacje);
expect(result).toEqual([]);
});
it('creates table for P_22AP_22BRP fields', () => {
const adnotacje: Adnotacje = {
P_22A: { _text: '2024-01-01' },
P_22BMK: { _text: 'Ford' },
P_22BMD: { _text: 'Focus' },
P_22BK: { _text: 'Red' },
P_22BNR: { _text: 'ABC123' },
P_22BRP: { _text: '2023' },
};
const result = generateDostawy(adnotacje);
expect(result).toHaveLength(1);
});
it('does not create table when no valid values found', () => {
const adnotacje: Adnotacje = { P_22D: { _text: '' } };
hasValue.mockReturnValue(false);
const result = generateDostawy(adnotacje);
expect(result).toEqual([]);
});
});