import { describe, expect, it } from 'vitest';
import type { ComparisonRow } from '@tool.io/tools/compare';
import { filterComparisonRows } from './comparison-filter';
const row = (
attributeId: string,
hasDifference: boolean,
missing: boolean
): ComparisonRow => ({
attributeId,
cells: [
{
comparison: missing ? 'missing' : 'equal',
display: missing ? '—' : 'Value',
itemId: 'first',
missingReason: missing ? 'unknown' : null,
normalizedValue: missing ? null : 'Value',
status: missing ? null : 'known'
},
{
comparison: hasDifference ? 'different' : 'equal',
display: 'Value',
itemId: 'second',
missingReason: null,
normalizedValue: 'Value',
status: 'known'
}
],
description: '',
hasDifference,
label: attributeId,
preference: 'none'
});
const rows = [
row('equal', false, false),
row('different', true, false),
row('missing', true, true)
];
describe('comparison row filters', () => {
it('shows the complete union in all mode', () => {
expect(filterComparisonRows(rows, 'all')).toHaveLength(3);
});
it('shows changed and missing rows in differences mode', () => {
expect(
filterComparisonRows(rows, 'different').map(
(entry) => entry.attributeId
)
).toEqual(['different', 'missing']);
});
it('shows only attributes present on every item in shared mode', () => {
expect(
filterComparisonRows(rows, 'shared').map(
(entry) => entry.attributeId
)
).toEqual(['equal', 'different']);
});
});
Browse the implementation files for Food Comparison.