import { describe, expect, it } from 'vitest';
import {
	getTariffFractionDisplayFraction,
	getTariffFractionDisplayKey
} from './tariff-fraction-display';
import type { TariffFraction } from '$lib/api/dashboard/a76/general_catalogs/tariff-fractions';

function buildFraction(partial: Partial<TariffFraction>): TariffFraction {
	return {
		id: 1,
		code: '',
		fraction: '',
		description: null,
		nico: null,
		umt: null,
		adv_impo: null,
		adv_expo: null,
		updated_at: null,
		dof: null,
		aplica_ieps: null,
		um_code: null,
		...partial
	};
}

describe('tariff-fraction-display', () => {
	it('uses technical code for key column', () => {
		const row = buildFraction({
			code: '01012101',
			fraction: '0101.21.01',
			um_code: '06'
		});
		expect(getTariffFractionDisplayKey(row)).toBe('01012101');
	});

	it('uses formatted fraction for fraction column', () => {
		const row = buildFraction({
			code: '1234567890',
			fraction: '1234.56.78.90'
		});
		expect(getTariffFractionDisplayFraction(row)).toBe('1234.56.78.90');
	});
});
