mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Grafana live: Add tests and missing code to amendTable (#89031)
* Grafana live: Add tests and missing code to amendTable * Betterer
This commit is contained in:
parent
89dd710ca9
commit
45c601acc4
@ -4653,7 +4653,8 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "3"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "4"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "4"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "5"]
|
||||
],
|
||||
"public/app/features/logs/components/InfiniteScroll.tsx:5381": [
|
||||
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"]
|
||||
|
123
public/app/features/live/data/amendTimeSeries.test.ts
Normal file
123
public/app/features/live/data/amendTimeSeries.test.ts
Normal file
@ -0,0 +1,123 @@
|
||||
import { Table, amendTable } from "./amendTimeSeries";
|
||||
|
||||
describe('amendTable', () => {
|
||||
it('should append nextTable when there is no overlap (nextTable after prevTable)', () => {
|
||||
const prevTable: Table = [
|
||||
[1, 2, 5],
|
||||
['a', 'b', 'e'],
|
||||
];
|
||||
const nextTable: Table = [
|
||||
[6, 7, 8],
|
||||
['f', 'g', 'h'],
|
||||
];
|
||||
const result = amendTable(prevTable, nextTable);
|
||||
expect(result).toEqual([
|
||||
[1, 2, 5, 6, 7, 8],
|
||||
['a', 'b', 'e', 'f', 'g', 'h'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('should prepend nextTable when there is no overlap (nextTable before prevTable)', () => {
|
||||
const prevTable: Table = [
|
||||
[3, 4, 5],
|
||||
['c', 'd', 'e'],
|
||||
];
|
||||
const nextTable: Table = [
|
||||
[1, 2],
|
||||
['a', 'b'],
|
||||
];
|
||||
const result = amendTable(prevTable, nextTable);
|
||||
expect(result).toEqual([
|
||||
[1, 2, 3, 4, 5],
|
||||
['a', 'b', 'c', 'd', 'e'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('should fully replace prevTable when nextTable covers entire range', () => {
|
||||
const prevTable: Table = [
|
||||
[3, 4, 5],
|
||||
['c', 'd', 'e'],
|
||||
];
|
||||
const nextTable: Table = [
|
||||
[1, 2, 3, 4, 5, 6],
|
||||
['a', 'b', 'c', 'd', 'e', 'f'],
|
||||
];
|
||||
const result = amendTable(prevTable, nextTable);
|
||||
expect(result).toEqual(nextTable);
|
||||
});
|
||||
|
||||
it('should partially replace prevTable when nextTable is within range', () => {
|
||||
const prevTable: Table = [
|
||||
[1, 2, 3, 4, 5],
|
||||
['a', 'b', 'c', 'd', 'e'],
|
||||
];
|
||||
const nextTable: Table = [
|
||||
[3, 4],
|
||||
['x', 'y'],
|
||||
];
|
||||
const result = amendTable(prevTable, nextTable);
|
||||
expect(result).toEqual([
|
||||
[1, 2, 3, 4, 5],
|
||||
['a', 'b', 'x', 'y', 'e'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('should append nextTable with overlap', () => {
|
||||
const prevTable: Table = [
|
||||
[1, 2, 5],
|
||||
['a', 'b', 'e'],
|
||||
];
|
||||
const nextTable: Table = [
|
||||
[2, 3, 6],
|
||||
['b', 'c', 'f'],
|
||||
];
|
||||
const result = amendTable(prevTable, nextTable);
|
||||
expect(result).toEqual([
|
||||
[1, 2, 3, 6],
|
||||
['a', 'b', 'c', 'f'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('should prepend nextTable with overlap', () => {
|
||||
const prevTable: Table = [
|
||||
[3, 4, 5],
|
||||
['c', 'd', 'e'],
|
||||
];
|
||||
const nextTable: Table = [
|
||||
[1, 4],
|
||||
['a', 'd'],
|
||||
];
|
||||
const result = amendTable(prevTable, nextTable);
|
||||
expect(result).toEqual([
|
||||
[1, 4, 5],
|
||||
['a', 'd', 'e'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle empty prevTable', () => {
|
||||
const prevTable: Table = [[]];
|
||||
const nextTable: Table = [
|
||||
[1, 2, 3],
|
||||
['a', 'b', 'c'],
|
||||
];
|
||||
const result = amendTable(prevTable, nextTable);
|
||||
expect(result).toEqual(nextTable);
|
||||
});
|
||||
|
||||
it('should handle empty nextTable', () => {
|
||||
const prevTable: Table = [
|
||||
[1, 2, 3],
|
||||
['a', 'b', 'c'],
|
||||
];
|
||||
const nextTable: Table = [[]];
|
||||
const result = amendTable(prevTable, nextTable);
|
||||
expect(result).toEqual(prevTable);
|
||||
});
|
||||
|
||||
it('should handle both tables being empty', () => {
|
||||
const prevTable: Table = [[]];
|
||||
const nextTable: Table = [[]];
|
||||
const result = amendTable(prevTable, nextTable);
|
||||
expect(result).toEqual([[]]);
|
||||
});
|
||||
});
|
@ -35,6 +35,18 @@ export function amendTable(prevTable: Table, nextTable: Table): Table {
|
||||
}
|
||||
// partial replace
|
||||
else if (nStart > pStart && nEnd < pEnd) {
|
||||
// partial replace
|
||||
let startIdx = closestIdx(nStart, prevTimes);
|
||||
startIdx = prevTimes[startIdx] < nStart ? startIdx + 1 : startIdx;
|
||||
let endIdx = closestIdx(nEnd, prevTimes);
|
||||
endIdx = prevTimes[endIdx] > nEnd ? endIdx - 1 : endIdx;
|
||||
|
||||
outTable = prevTable.map((_, i) =>
|
||||
prevTable[i]
|
||||
.slice(0, startIdx)
|
||||
.concat(nextTable[i])
|
||||
.concat(prevTable[i].slice(endIdx + 1))
|
||||
) as Table;
|
||||
}
|
||||
// append, with overlap
|
||||
else if (nStart >= pStart) {
|
||||
|
Loading…
Reference in New Issue
Block a user