frequi_origin/tests/unit/objectArray.spec.ts

22 lines
725 B
TypeScript
Raw Permalink Normal View History

import { describe, it, expect } from 'vitest';
2024-07-05 12:34:17 +00:00
import { formatObjectForTable } from '@/utils/objectToTableItems';
describe('objectArray.ts', () => {
it('converts object array', () => {
const originalObj = {
XXX1: [{ Profit: 20 }, { Loss: 50 }],
XXX2: [{ Profit: 50 }, { Loss: 21 }],
};
const expected = [
{ metric: 'Profit', XXX1: 20, XXX2: 50 },
{ metric: 'Loss', XXX1: 50, XXX2: 21 },
];
const expected2 = [
{ settings: 'Profit', XXX1: 20, XXX2: 50 },
{ settings: 'Loss', XXX1: 50, XXX2: 21 },
];
expect(formatObjectForTable(originalObj, 'metric')).toEqual(expected);
expect(formatObjectForTable(originalObj, 'settings')).toEqual(expected2);
});
});