2021-02-28 02:07:45 +01:00
|
|
|
import Item from 'src/Item';
|
|
|
|
import Page, { asPages } from 'src/debug/Page';
|
|
|
|
import ItemGroup from 'src/debug/ItemGroup';
|
|
|
|
import ItemMerger from 'src/debug/ItemMerger';
|
|
|
|
import { items } from 'test/testItems';
|
2021-03-31 10:00:21 +02:00
|
|
|
import EvaluationTracker from 'src/debug/EvaluationTracker';
|
2021-02-28 02:07:45 +01:00
|
|
|
import ChangeTracker from 'src/debug/ChangeTracker';
|
|
|
|
|
|
|
|
test('empty', async () => {
|
2021-03-23 08:46:14 +01:00
|
|
|
const evaluationTracker = new EvaluationTracker();
|
|
|
|
const changeTracker = new ChangeTracker();
|
2021-04-25 08:28:48 +02:00
|
|
|
expect(asPages(evaluationTracker, changeTracker, [], [])).toEqual([]);
|
2021-02-28 02:07:45 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('no merger', async () => {
|
|
|
|
const pageItems = [
|
|
|
|
items(0, [{ id: 1, line: 1 }]),
|
|
|
|
items(1, [
|
|
|
|
{ id: 2, line: 1 },
|
|
|
|
{ id: 3, line: 1 },
|
|
|
|
{ id: 4, line: 1 },
|
|
|
|
]),
|
|
|
|
items(2, [{ id: 5, line: 1 }]),
|
|
|
|
];
|
|
|
|
const flattenedItems = new Array<Item>().concat(...pageItems);
|
2021-03-23 08:46:14 +01:00
|
|
|
const evaluationTracker = new EvaluationTracker();
|
|
|
|
const changeTracker = new ChangeTracker();
|
2021-04-25 08:28:48 +02:00
|
|
|
const pages = asPages(evaluationTracker, changeTracker, ['id', 'line'], flattenedItems);
|
2021-02-28 02:07:45 +01:00
|
|
|
expect(pages).toEqual([
|
|
|
|
{ index: 0, itemGroups: pageItems[0].map((item) => new ItemGroup(item)) },
|
|
|
|
{ index: 1, itemGroups: pageItems[1].map((item) => new ItemGroup(item)) },
|
|
|
|
{ index: 2, itemGroups: pageItems[2].map((item) => new ItemGroup(item)) },
|
|
|
|
] as Page[]);
|
2021-03-23 08:46:14 +01:00
|
|
|
expect(changeTracker.changeCount()).toEqual(0);
|
2021-02-28 02:07:45 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('merger', async () => {
|
|
|
|
const pageItems = [
|
|
|
|
items(0, [{ id: 1, line: 1 }]),
|
|
|
|
items(1, [
|
|
|
|
{ id: 2, line: 1 },
|
|
|
|
{ id: 3, line: 1 },
|
|
|
|
{ id: 4, line: 2 },
|
|
|
|
]),
|
|
|
|
items(2, [{ id: 5, line: 1 }]),
|
|
|
|
];
|
|
|
|
const flattenedItems = new Array<Item>().concat(...pageItems);
|
|
|
|
const merger: ItemMerger = { groupKey: 'line', merge: (items) => items[0] };
|
2021-03-23 08:46:14 +01:00
|
|
|
const evaluationTracker = new EvaluationTracker();
|
|
|
|
const changeTracker = new ChangeTracker();
|
2021-04-25 08:28:48 +02:00
|
|
|
const pages = asPages(evaluationTracker, changeTracker, ['id', 'line'], flattenedItems, merger);
|
2021-02-28 02:07:45 +01:00
|
|
|
|
|
|
|
expect(pages).toEqual([
|
|
|
|
{ index: 0, itemGroups: pageItems[0].map((item) => new ItemGroup(item)) },
|
|
|
|
{
|
|
|
|
index: 1,
|
|
|
|
itemGroups: [
|
2021-03-23 08:46:14 +01:00
|
|
|
new ItemGroup(
|
2021-04-25 08:28:48 +02:00
|
|
|
merger.merge(evaluationTracker, changeTracker, ['id', 'line'], pageItems[1].slice(0, 2)),
|
2021-03-23 08:46:14 +01:00
|
|
|
pageItems[1].slice(0, 2),
|
|
|
|
),
|
2021-02-28 02:07:45 +01:00
|
|
|
new ItemGroup(pageItems[1][2]),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{ index: 2, itemGroups: pageItems[2].map((item) => new ItemGroup(item)) },
|
|
|
|
] as Page[]);
|
|
|
|
});
|