|
import { describe, it, expect } from 'vitest'; |
|
|
|
import type { Datom, Field, Attribute } from '.'; |
|
import { FieldType, FieldCardinality, projectData } from '.'; |
|
|
|
export const datoms: Datom[] = [ |
|
{ id: '1', attribute: 'value', stringValue: 'foo' }, |
|
{ id: '4', attribute: 'value', integerValue: 42 }, |
|
{ id: '10', attribute: 'value', integerValue: 1 }, |
|
{ id: '20', attribute: 'rows', stringValue: '1' }, |
|
{ id: '20', attribute: 'rows', stringValue: '2' }, |
|
{ id: '20', attribute: 'rows', stringValue: '3' }, |
|
{ id: '21', row: '1', attribute: 'value', stringValue: 'bar' }, |
|
{ id: '21', row: '3', attribute: 'value', stringValue: 'toto' }, |
|
{ id: '23', row: '3', attribute: 'value', stringValue: 'yolo' }, |
|
]; |
|
|
|
export const revision1: Field[] = [ |
|
{ type: FieldType.TEXT, id: '1' }, |
|
{ type: FieldType.SECTION, id: '2', level: 1 }, |
|
{ type: FieldType.TEXT, id: '3' }, |
|
{ type: FieldType.INTEGER, id: '4' }, |
|
{ type: FieldType.SECTION, id: '5', level: 2 }, |
|
{ type: FieldType.TEXT, id: '6' }, |
|
{ type: FieldType.SECTION, id: '7', level: 2 }, |
|
{ type: FieldType.TEXT, id: '8' }, |
|
{ type: FieldType.END, id: '9' }, |
|
{ type: FieldType.BOOLEAN, id: '10' }, |
|
{ type: FieldType.END, id: '11' }, |
|
{ type: FieldType.TEXT, id: '12' }, |
|
{ type: FieldType.SECTION, id: '13', level: 1 }, |
|
{ type: FieldType.TEXT, id: '14' }, |
|
{ type: FieldType.SECTION, id: '15', level: 1 }, |
|
{ type: FieldType.SECTION, id: '16', level: 2 }, |
|
{ type: FieldType.SECTION, id: '17', level: 3 }, |
|
{ type: FieldType.SECTION, id: '18', level: 1 }, |
|
{ type: FieldType.TEXT, id: '19' }, |
|
{ |
|
type: FieldType.SECTION, |
|
id: '20', |
|
level: 2, |
|
cardinality: FieldCardinality.MANY, |
|
}, |
|
{ type: FieldType.TEXT, id: '21' }, |
|
{ type: FieldType.SECTION, id: '22', level: 3 }, |
|
{ type: FieldType.TEXT, id: '23' }, |
|
{ type: FieldType.SECTION, id: '24', level: 1 }, |
|
{ type: FieldType.TEXT, id: '25' }, |
|
]; |
|
|
|
export const data1: Attribute[] = [ |
|
{ id: '1', type: FieldType.TEXT, value: 'foo' }, |
|
{ |
|
id: '2', |
|
type: FieldType.SECTION, |
|
level: 1, |
|
children: [ |
|
{ id: '3', type: FieldType.TEXT }, |
|
{ id: '4', type: FieldType.INTEGER, value: 42 }, |
|
{ |
|
id: '5', |
|
type: FieldType.SECTION, |
|
level: 2, |
|
children: [{ id: '6', type: FieldType.TEXT }], |
|
}, |
|
{ |
|
id: '7', |
|
type: FieldType.SECTION, |
|
level: 2, |
|
children: [{ id: '8', type: FieldType.TEXT }], |
|
}, |
|
{ id: '10', type: FieldType.BOOLEAN, value: true }, |
|
], |
|
}, |
|
{ id: '12', type: FieldType.TEXT }, |
|
{ |
|
id: '13', |
|
type: FieldType.SECTION, |
|
level: 1, |
|
children: [{ id: '14', type: FieldType.TEXT }], |
|
}, |
|
{ |
|
id: '15', |
|
type: FieldType.SECTION, |
|
level: 1, |
|
children: [ |
|
{ |
|
id: '16', |
|
type: FieldType.SECTION, |
|
level: 2, |
|
children: [ |
|
{ id: '17', type: FieldType.SECTION, level: 3, children: [] }, |
|
], |
|
}, |
|
], |
|
}, |
|
{ |
|
id: '18', |
|
type: FieldType.SECTION, |
|
level: 1, |
|
children: [ |
|
{ id: '19', type: FieldType.TEXT }, |
|
{ |
|
id: '20', |
|
type: FieldType.SECTION, |
|
level: 2, |
|
cardinality: FieldCardinality.MANY, |
|
rows: [ |
|
{ |
|
id: '1', |
|
children: [ |
|
{ id: '21', type: FieldType.TEXT, value: 'bar' }, |
|
{ |
|
id: '22', |
|
type: FieldType.SECTION, |
|
level: 3, |
|
children: [{ id: '23', type: FieldType.TEXT }], |
|
}, |
|
], |
|
}, |
|
{ |
|
id: '2', |
|
children: [ |
|
{ id: '21', type: FieldType.TEXT }, |
|
{ |
|
id: '22', |
|
type: FieldType.SECTION, |
|
level: 3, |
|
children: [{ id: '23', type: FieldType.TEXT }], |
|
}, |
|
], |
|
}, |
|
{ |
|
id: '3', |
|
children: [ |
|
{ id: '21', type: FieldType.TEXT, value: 'toto' }, |
|
{ |
|
id: '22', |
|
type: FieldType.SECTION, |
|
level: 3, |
|
children: [{ id: '23', type: FieldType.TEXT, value: 'yolo' }], |
|
}, |
|
], |
|
}, |
|
], |
|
}, |
|
], |
|
}, |
|
{ |
|
id: '24', |
|
type: FieldType.SECTION, |
|
level: 1, |
|
children: [{ id: '25', type: FieldType.TEXT }], |
|
}, |
|
]; |
|
|
|
export const revision2: Field[] = [ |
|
{ type: FieldType.TEXT, id: '1' }, |
|
{ type: FieldType.SECTION, id: '2', level: 1 }, |
|
{ type: FieldType.TEXT, id: '3' }, |
|
{ type: FieldType.INTEGER, id: '4' }, |
|
{ type: FieldType.END, id: '9' }, |
|
{ type: FieldType.INTEGER, id: '10' }, |
|
]; |
|
|
|
export const data2: Attribute[] = [ |
|
{ id: '1', type: FieldType.TEXT, value: 'foo' }, |
|
{ |
|
id: '2', |
|
type: FieldType.SECTION, |
|
level: 1, |
|
children: [ |
|
{ id: '3', type: FieldType.TEXT }, |
|
{ id: '4', type: FieldType.INTEGER, value: 42 }, |
|
], |
|
}, |
|
{ id: '10', type: FieldType.INTEGER, value: 1 }, |
|
]; |
|
|
|
describe('data', () => { |
|
it('project data1', () => { |
|
expect(projectData(revision1, datoms)).toEqual(data1); |
|
}); |
|
|
|
it('project data2', () => { |
|
expect(projectData(revision2, datoms)).toEqual(data2); |
|
}); |
|
}); |