50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
|
|
describe('toProductSpecView', () => {
|
|
it('should map translations.key an value corrently', () => {
|
|
const raw: ProductSpec = {
|
|
id: 1,
|
|
value: '100W',
|
|
translations: [
|
|
{
|
|
id: 1,
|
|
key: 'Power',
|
|
},
|
|
],
|
|
};
|
|
|
|
const expected: ProductSpecView = {
|
|
id: 1,
|
|
key: 'Power',
|
|
value: '100W',
|
|
};
|
|
|
|
expect(toProductSpecView(raw)).toEqual(expected);
|
|
});
|
|
|
|
it('should handle missing translations gracefully', () => {
|
|
const raw: ProductSpec = { id: 2, value: '220V', translations: [] };
|
|
const view = toProductSpecView(raw);
|
|
expect(view.key).toBe('');
|
|
});
|
|
});
|
|
|
|
describe('toProductSpecGroupView', () => {
|
|
it('should map translations.name and specs correctly', () => {
|
|
const raw: ProductSpecGroup = {
|
|
id: 1,
|
|
translations: [{ id: 1, name: 'Electrical' }],
|
|
specs: [
|
|
{ id: 1, value: '100W', translations: [{ id: 1, key: 'Power' }] },
|
|
{ id: 2, value: '220V', translations: [{ id: 2, key: 'Voltage' }] },
|
|
],
|
|
};
|
|
const view: ProductSpecGroupView = toProductSpecGroupView(raw);
|
|
|
|
expect(view.name).toBe('Electrical');
|
|
expect(view.specs).toHaveLength(2);
|
|
expect(view.specs[0].key).toBe('Power');
|
|
expect(view.specs[1].value).toBe('220V');
|
|
});
|
|
});
|