From f7cb27e973cfaa9b0bd2fdfa21c26e58899894aa Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Fri, 14 Jul 2023 14:45:40 +0300 Subject: [PATCH 1/2] [Lens] Fixes error on table when there is no data --- .../datatable/transpose_helpers.test.ts | 354 ++++++++++-------- .../datatable/transpose_helpers.ts | 2 +- 2 files changed, 189 insertions(+), 167 deletions(-) diff --git a/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.test.ts b/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.test.ts index 2a7461187c771..7cc17d51bca90 100644 --- a/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.test.ts +++ b/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.test.ts @@ -11,7 +11,7 @@ import { DatatableArgs } from './datatable'; import { transposeTable } from './transpose_helpers'; -describe('transpose_helpes', () => { +describe('transpose_helpers', () => { function buildTable(): Datatable { // 3 buckets, 2 metrics // first bucket goes A/B/C @@ -109,185 +109,207 @@ describe('transpose_helpes', () => { } as unknown as Record; } - it('should transpose table by one column', () => { - const table = buildTable(); - const args = buildArgs(); - args.columns[0].isTransposed = true; - transposeTable(args, table, buildFormatters()); + // it('should transpose table by one column', () => { + // const table = buildTable(); + // const args = buildArgs(); + // args.columns[0].isTransposed = true; + // transposeTable(args, table, buildFormatters()); - // one metric for each unique value of bucket1 - expect(table.columns.map((c) => c.id)).toEqual([ - 'bucket2', - 'bucket3', - 'A---metric1', - 'B---metric1', - 'C---metric1', - 'A---metric2', - 'B---metric2', - 'C---metric2', - ]); + // // one metric for each unique value of bucket1 + // expect(table.columns.map((c) => c.id)).toEqual([ + // 'bucket2', + // 'bucket3', + // 'A---metric1', + // 'B---metric1', + // 'C---metric1', + // 'A---metric2', + // 'B---metric2', + // 'C---metric2', + // ]); - // order is different for args to visually group unique values - const expectedColumns = [ - 'bucket2', - 'bucket3', - 'A---metric1', - 'A---metric2', - 'B---metric1', - 'B---metric2', - 'C---metric1', - 'C---metric2', - ]; + // // order is different for args to visually group unique values + // const expectedColumns = [ + // 'bucket2', + // 'bucket3', + // 'A---metric1', + // 'A---metric2', + // 'B---metric1', + // 'B---metric2', + // 'C---metric1', + // 'C---metric2', + // ]; - // args should be in sync - expect(args.columns.map((c) => c.columnId)).toEqual(expectedColumns); - // original column id should stay preserved - expect(args.columns.slice(2).map((c) => c.originalColumnId)).toEqual([ - 'metric1', - 'metric2', - 'metric1', - 'metric2', - 'metric1', - 'metric2', - ]); + // // args should be in sync + // expect(args.columns.map((c) => c.columnId)).toEqual(expectedColumns); + // // original column id should stay preserved + // expect(args.columns.slice(2).map((c) => c.originalColumnId)).toEqual([ + // 'metric1', + // 'metric2', + // 'metric1', + // 'metric2', + // 'metric1', + // 'metric2', + // ]); - // data should stay consistent - expect(table.rows.length).toEqual(9); - table.rows.forEach((row, index) => { - expect(row['A---metric1']).toEqual(index * 2 + 1); - expect(row['A---metric2']).toEqual(index * 2 + 2); - // B metrics start with offset 18 because there are 18 A metrics (2 metrics * 3 bucket2 metrics * 3 bucket3 metrics) - expect(row['B---metric1']).toEqual(18 + index * 2 + 1); - expect(row['B---metric2']).toEqual(18 + index * 2 + 2); - // B metrics start with offset 36 because there are 18 A metrics and 18 B metrics (2 metrics * 3 bucket2 values * 3 bucket3 values) - expect(row['C---metric1']).toEqual(36 + index * 2 + 1); - expect(row['C---metric2']).toEqual(36 + index * 2 + 2); - }); + // // data should stay consistent + // expect(table.rows.length).toEqual(9); + // table.rows.forEach((row, index) => { + // expect(row['A---metric1']).toEqual(index * 2 + 1); + // expect(row['A---metric2']).toEqual(index * 2 + 2); + // // B metrics start with offset 18 because there are 18 A metrics (2 metrics * 3 bucket2 metrics * 3 bucket3 metrics) + // expect(row['B---metric1']).toEqual(18 + index * 2 + 1); + // expect(row['B---metric2']).toEqual(18 + index * 2 + 2); + // // B metrics start with offset 36 because there are 18 A metrics and 18 B metrics (2 metrics * 3 bucket2 values * 3 bucket3 values) + // expect(row['C---metric1']).toEqual(36 + index * 2 + 1); + // expect(row['C---metric2']).toEqual(36 + index * 2 + 2); + // }); - // visible name should use separator - expect(table.columns[2].name).toEqual(`A › metric1`); - }); + // // visible name should use separator + // expect(table.columns[2].name).toEqual(`A › metric1`); + // }); - it('should transpose table by two columns', () => { - const table = buildTable(); - const args = buildArgs(); - args.columns[0].isTransposed = true; - args.columns[1].isTransposed = true; - transposeTable(args, table, buildFormatters()); + // it('should transpose table by two columns', () => { + // const table = buildTable(); + // const args = buildArgs(); + // args.columns[0].isTransposed = true; + // args.columns[1].isTransposed = true; + // transposeTable(args, table, buildFormatters()); - // one metric for each unique value of bucket1 - expect(table.columns.map((c) => c.id)).toEqual([ - 'bucket3', - 'A---D---metric1', - 'B---D---metric1', - 'C---D---metric1', - 'A---E---metric1', - 'B---E---metric1', - 'C---E---metric1', - 'A---F---metric1', - 'B---F---metric1', - 'C---F---metric1', - 'A---D---metric2', - 'B---D---metric2', - 'C---D---metric2', - 'A---E---metric2', - 'B---E---metric2', - 'C---E---metric2', - 'A---F---metric2', - 'B---F---metric2', - 'C---F---metric2', - ]); + // // one metric for each unique value of bucket1 + // expect(table.columns.map((c) => c.id)).toEqual([ + // 'bucket3', + // 'A---D---metric1', + // 'B---D---metric1', + // 'C---D---metric1', + // 'A---E---metric1', + // 'B---E---metric1', + // 'C---E---metric1', + // 'A---F---metric1', + // 'B---F---metric1', + // 'C---F---metric1', + // 'A---D---metric2', + // 'B---D---metric2', + // 'C---D---metric2', + // 'A---E---metric2', + // 'B---E---metric2', + // 'C---E---metric2', + // 'A---F---metric2', + // 'B---F---metric2', + // 'C---F---metric2', + // ]); - // order is different for args to visually group unique values - const expectedColumns = [ - 'bucket3', - 'A---D---metric1', - 'A---D---metric2', - 'A---E---metric1', - 'A---E---metric2', - 'A---F---metric1', - 'A---F---metric2', - 'B---D---metric1', - 'B---D---metric2', - 'B---E---metric1', - 'B---E---metric2', - 'B---F---metric1', - 'B---F---metric2', - 'C---D---metric1', - 'C---D---metric2', - 'C---E---metric1', - 'C---E---metric2', - 'C---F---metric1', - 'C---F---metric2', - ]; + // // order is different for args to visually group unique values + // const expectedColumns = [ + // 'bucket3', + // 'A---D---metric1', + // 'A---D---metric2', + // 'A---E---metric1', + // 'A---E---metric2', + // 'A---F---metric1', + // 'A---F---metric2', + // 'B---D---metric1', + // 'B---D---metric2', + // 'B---E---metric1', + // 'B---E---metric2', + // 'B---F---metric1', + // 'B---F---metric2', + // 'C---D---metric1', + // 'C---D---metric2', + // 'C---E---metric1', + // 'C---E---metric2', + // 'C---F---metric1', + // 'C---F---metric2', + // ]; - // args should be in sync - expect(args.columns.map((c) => c.columnId)).toEqual(expectedColumns); - // original column id should stay preserved - expect(args.columns.slice(1).map((c) => c.originalColumnId)).toEqual([ - 'metric1', - 'metric2', - 'metric1', - 'metric2', - 'metric1', - 'metric2', - 'metric1', - 'metric2', - 'metric1', - 'metric2', - 'metric1', - 'metric2', - 'metric1', - 'metric2', - 'metric1', - 'metric2', - 'metric1', - 'metric2', - ]); + // // args should be in sync + // expect(args.columns.map((c) => c.columnId)).toEqual(expectedColumns); + // // original column id should stay preserved + // expect(args.columns.slice(1).map((c) => c.originalColumnId)).toEqual([ + // 'metric1', + // 'metric2', + // 'metric1', + // 'metric2', + // 'metric1', + // 'metric2', + // 'metric1', + // 'metric2', + // 'metric1', + // 'metric2', + // 'metric1', + // 'metric2', + // 'metric1', + // 'metric2', + // 'metric1', + // 'metric2', + // 'metric1', + // 'metric2', + // ]); - // data should stay consistent - expect(table.rows.length).toEqual(3); - table.rows.forEach((row, index) => { - // each metric block has an additional offset of 6 because there are 6 metrics for each bucket1/bucket2 combination (2 metrics * 3 bucket3 values) - expect(row['A---D---metric1']).toEqual(index * 2 + 1); - expect(row['A---D---metric2']).toEqual(index * 2 + 2); - expect(row['A---E---metric1']).toEqual(index * 2 + 6 + 1); - expect(row['A---E---metric2']).toEqual(index * 2 + 6 + 2); - expect(row['A---F---metric1']).toEqual(index * 2 + 12 + 1); - expect(row['A---F---metric2']).toEqual(index * 2 + 12 + 2); + // // data should stay consistent + // expect(table.rows.length).toEqual(3); + // table.rows.forEach((row, index) => { + // // each metric block has an additional offset of 6 because there are 6 metrics for each bucket1/bucket2 combination (2 metrics * 3 bucket3 values) + // expect(row['A---D---metric1']).toEqual(index * 2 + 1); + // expect(row['A---D---metric2']).toEqual(index * 2 + 2); + // expect(row['A---E---metric1']).toEqual(index * 2 + 6 + 1); + // expect(row['A---E---metric2']).toEqual(index * 2 + 6 + 2); + // expect(row['A---F---metric1']).toEqual(index * 2 + 12 + 1); + // expect(row['A---F---metric2']).toEqual(index * 2 + 12 + 2); - expect(row['B---D---metric1']).toEqual(index * 2 + 18 + 1); - expect(row['B---D---metric2']).toEqual(index * 2 + 18 + 2); - expect(row['B---E---metric1']).toEqual(index * 2 + 24 + 1); - expect(row['B---E---metric2']).toEqual(index * 2 + 24 + 2); - expect(row['B---F---metric1']).toEqual(index * 2 + 30 + 1); - expect(row['B---F---metric2']).toEqual(index * 2 + 30 + 2); + // expect(row['B---D---metric1']).toEqual(index * 2 + 18 + 1); + // expect(row['B---D---metric2']).toEqual(index * 2 + 18 + 2); + // expect(row['B---E---metric1']).toEqual(index * 2 + 24 + 1); + // expect(row['B---E---metric2']).toEqual(index * 2 + 24 + 2); + // expect(row['B---F---metric1']).toEqual(index * 2 + 30 + 1); + // expect(row['B---F---metric2']).toEqual(index * 2 + 30 + 2); - expect(row['C---D---metric1']).toEqual(index * 2 + 36 + 1); - expect(row['C---D---metric2']).toEqual(index * 2 + 36 + 2); - expect(row['C---E---metric1']).toEqual(index * 2 + 42 + 1); - expect(row['C---E---metric2']).toEqual(index * 2 + 42 + 2); - expect(row['C---F---metric1']).toEqual(index * 2 + 48 + 1); - expect(row['C---F---metric2']).toEqual(index * 2 + 48 + 2); - }); - }); + // expect(row['C---D---metric1']).toEqual(index * 2 + 36 + 1); + // expect(row['C---D---metric2']).toEqual(index * 2 + 36 + 2); + // expect(row['C---E---metric1']).toEqual(index * 2 + 42 + 1); + // expect(row['C---E---metric2']).toEqual(index * 2 + 42 + 2); + // expect(row['C---F---metric1']).toEqual(index * 2 + 48 + 1); + // expect(row['C---F---metric2']).toEqual(index * 2 + 48 + 2); + // }); + // }); - it('should be able to handle missing values', () => { + // it('should be able to handle missing values', () => { + // const table = buildTable(); + // const args = buildArgs(); + // args.columns[0].isTransposed = true; + // args.columns[1].isTransposed = true; + // // delete A-E-Z bucket + // table.rows.splice(5, 1); + // transposeTable(args, table, buildFormatters()); + // expect(args.columns.length).toEqual(19); + // expect(table.columns.length).toEqual(19); + // expect(table.rows.length).toEqual(3); + // expect(table.rows[2]['A---E---metric1']).toEqual(undefined); + // expect(table.rows[2]['A---E---metric2']).toEqual(undefined); + // // 1 bucket column and 2 missing from the regular 18 columns + // expect(Object.values(table.rows[2]).filter((val) => val !== undefined).length).toEqual( + // 1 + 18 - 2 + // ); + // }); + + it('should not fail for no data', () => { const table = buildTable(); + const updatedTable = { + ...table, + rows: [], + }; const args = buildArgs(); - args.columns[0].isTransposed = true; - args.columns[1].isTransposed = true; - // delete A-E-Z bucket - table.rows.splice(5, 1); - transposeTable(args, table, buildFormatters()); - expect(args.columns.length).toEqual(19); - expect(table.columns.length).toEqual(19); - expect(table.rows.length).toEqual(3); - expect(table.rows[2]['A---E---metric1']).toEqual(undefined); - expect(table.rows[2]['A---E---metric2']).toEqual(undefined); - // 1 bucket column and 2 missing from the regular 18 columns - expect(Object.values(table.rows[2]).filter((val) => val !== undefined).length).toEqual( - 1 + 18 - 2 - ); + const updatedArgs = { + ...args, + columns: [ + { + type: 'lens_datatable_column', + columnId: 'bucket1', + isTransposed: true, + transposable: false, + }, + ], + } as DatatableArgs; + transposeTable(updatedArgs, updatedTable, buildFormatters()); + expect(args.columns.length).toEqual(5); }); }); diff --git a/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.ts b/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.ts index 00e0de71395d3..ef07a87cfb9e1 100644 --- a/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.ts +++ b/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.ts @@ -118,7 +118,7 @@ function updateColumnArgs( ) { args.columns = [...bucketsColumnArgs]; // add first column from each group, then add second column for each group, ... - transposedColumnGroups[0].forEach((_, index) => { + transposedColumnGroups[0]?.forEach((_, index) => { transposedColumnGroups.forEach((transposedColumnGroup) => { args.columns.push(transposedColumnGroup[index]); }); From 71788c9e0c55cfe1426db2c168a4b23926820ffd Mon Sep 17 00:00:00 2001 From: Stratoula Kalafateli Date: Fri, 14 Jul 2023 14:56:37 +0300 Subject: [PATCH 2/2] Uncomment --- .../datatable/transpose_helpers.test.ts | 336 +++++++++--------- 1 file changed, 168 insertions(+), 168 deletions(-) diff --git a/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.test.ts b/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.test.ts index 7cc17d51bca90..35a96a5fd1524 100644 --- a/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.test.ts +++ b/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.test.ts @@ -109,187 +109,187 @@ describe('transpose_helpers', () => { } as unknown as Record; } - // it('should transpose table by one column', () => { - // const table = buildTable(); - // const args = buildArgs(); - // args.columns[0].isTransposed = true; - // transposeTable(args, table, buildFormatters()); + it('should transpose table by one column', () => { + const table = buildTable(); + const args = buildArgs(); + args.columns[0].isTransposed = true; + transposeTable(args, table, buildFormatters()); - // // one metric for each unique value of bucket1 - // expect(table.columns.map((c) => c.id)).toEqual([ - // 'bucket2', - // 'bucket3', - // 'A---metric1', - // 'B---metric1', - // 'C---metric1', - // 'A---metric2', - // 'B---metric2', - // 'C---metric2', - // ]); + // one metric for each unique value of bucket1 + expect(table.columns.map((c) => c.id)).toEqual([ + 'bucket2', + 'bucket3', + 'A---metric1', + 'B---metric1', + 'C---metric1', + 'A---metric2', + 'B---metric2', + 'C---metric2', + ]); - // // order is different for args to visually group unique values - // const expectedColumns = [ - // 'bucket2', - // 'bucket3', - // 'A---metric1', - // 'A---metric2', - // 'B---metric1', - // 'B---metric2', - // 'C---metric1', - // 'C---metric2', - // ]; + // order is different for args to visually group unique values + const expectedColumns = [ + 'bucket2', + 'bucket3', + 'A---metric1', + 'A---metric2', + 'B---metric1', + 'B---metric2', + 'C---metric1', + 'C---metric2', + ]; - // // args should be in sync - // expect(args.columns.map((c) => c.columnId)).toEqual(expectedColumns); - // // original column id should stay preserved - // expect(args.columns.slice(2).map((c) => c.originalColumnId)).toEqual([ - // 'metric1', - // 'metric2', - // 'metric1', - // 'metric2', - // 'metric1', - // 'metric2', - // ]); + // args should be in sync + expect(args.columns.map((c) => c.columnId)).toEqual(expectedColumns); + // original column id should stay preserved + expect(args.columns.slice(2).map((c) => c.originalColumnId)).toEqual([ + 'metric1', + 'metric2', + 'metric1', + 'metric2', + 'metric1', + 'metric2', + ]); - // // data should stay consistent - // expect(table.rows.length).toEqual(9); - // table.rows.forEach((row, index) => { - // expect(row['A---metric1']).toEqual(index * 2 + 1); - // expect(row['A---metric2']).toEqual(index * 2 + 2); - // // B metrics start with offset 18 because there are 18 A metrics (2 metrics * 3 bucket2 metrics * 3 bucket3 metrics) - // expect(row['B---metric1']).toEqual(18 + index * 2 + 1); - // expect(row['B---metric2']).toEqual(18 + index * 2 + 2); - // // B metrics start with offset 36 because there are 18 A metrics and 18 B metrics (2 metrics * 3 bucket2 values * 3 bucket3 values) - // expect(row['C---metric1']).toEqual(36 + index * 2 + 1); - // expect(row['C---metric2']).toEqual(36 + index * 2 + 2); - // }); + // data should stay consistent + expect(table.rows.length).toEqual(9); + table.rows.forEach((row, index) => { + expect(row['A---metric1']).toEqual(index * 2 + 1); + expect(row['A---metric2']).toEqual(index * 2 + 2); + // B metrics start with offset 18 because there are 18 A metrics (2 metrics * 3 bucket2 metrics * 3 bucket3 metrics) + expect(row['B---metric1']).toEqual(18 + index * 2 + 1); + expect(row['B---metric2']).toEqual(18 + index * 2 + 2); + // B metrics start with offset 36 because there are 18 A metrics and 18 B metrics (2 metrics * 3 bucket2 values * 3 bucket3 values) + expect(row['C---metric1']).toEqual(36 + index * 2 + 1); + expect(row['C---metric2']).toEqual(36 + index * 2 + 2); + }); - // // visible name should use separator - // expect(table.columns[2].name).toEqual(`A › metric1`); - // }); + // visible name should use separator + expect(table.columns[2].name).toEqual(`A › metric1`); + }); - // it('should transpose table by two columns', () => { - // const table = buildTable(); - // const args = buildArgs(); - // args.columns[0].isTransposed = true; - // args.columns[1].isTransposed = true; - // transposeTable(args, table, buildFormatters()); + it('should transpose table by two columns', () => { + const table = buildTable(); + const args = buildArgs(); + args.columns[0].isTransposed = true; + args.columns[1].isTransposed = true; + transposeTable(args, table, buildFormatters()); - // // one metric for each unique value of bucket1 - // expect(table.columns.map((c) => c.id)).toEqual([ - // 'bucket3', - // 'A---D---metric1', - // 'B---D---metric1', - // 'C---D---metric1', - // 'A---E---metric1', - // 'B---E---metric1', - // 'C---E---metric1', - // 'A---F---metric1', - // 'B---F---metric1', - // 'C---F---metric1', - // 'A---D---metric2', - // 'B---D---metric2', - // 'C---D---metric2', - // 'A---E---metric2', - // 'B---E---metric2', - // 'C---E---metric2', - // 'A---F---metric2', - // 'B---F---metric2', - // 'C---F---metric2', - // ]); + // one metric for each unique value of bucket1 + expect(table.columns.map((c) => c.id)).toEqual([ + 'bucket3', + 'A---D---metric1', + 'B---D---metric1', + 'C---D---metric1', + 'A---E---metric1', + 'B---E---metric1', + 'C---E---metric1', + 'A---F---metric1', + 'B---F---metric1', + 'C---F---metric1', + 'A---D---metric2', + 'B---D---metric2', + 'C---D---metric2', + 'A---E---metric2', + 'B---E---metric2', + 'C---E---metric2', + 'A---F---metric2', + 'B---F---metric2', + 'C---F---metric2', + ]); - // // order is different for args to visually group unique values - // const expectedColumns = [ - // 'bucket3', - // 'A---D---metric1', - // 'A---D---metric2', - // 'A---E---metric1', - // 'A---E---metric2', - // 'A---F---metric1', - // 'A---F---metric2', - // 'B---D---metric1', - // 'B---D---metric2', - // 'B---E---metric1', - // 'B---E---metric2', - // 'B---F---metric1', - // 'B---F---metric2', - // 'C---D---metric1', - // 'C---D---metric2', - // 'C---E---metric1', - // 'C---E---metric2', - // 'C---F---metric1', - // 'C---F---metric2', - // ]; + // order is different for args to visually group unique values + const expectedColumns = [ + 'bucket3', + 'A---D---metric1', + 'A---D---metric2', + 'A---E---metric1', + 'A---E---metric2', + 'A---F---metric1', + 'A---F---metric2', + 'B---D---metric1', + 'B---D---metric2', + 'B---E---metric1', + 'B---E---metric2', + 'B---F---metric1', + 'B---F---metric2', + 'C---D---metric1', + 'C---D---metric2', + 'C---E---metric1', + 'C---E---metric2', + 'C---F---metric1', + 'C---F---metric2', + ]; - // // args should be in sync - // expect(args.columns.map((c) => c.columnId)).toEqual(expectedColumns); - // // original column id should stay preserved - // expect(args.columns.slice(1).map((c) => c.originalColumnId)).toEqual([ - // 'metric1', - // 'metric2', - // 'metric1', - // 'metric2', - // 'metric1', - // 'metric2', - // 'metric1', - // 'metric2', - // 'metric1', - // 'metric2', - // 'metric1', - // 'metric2', - // 'metric1', - // 'metric2', - // 'metric1', - // 'metric2', - // 'metric1', - // 'metric2', - // ]); + // args should be in sync + expect(args.columns.map((c) => c.columnId)).toEqual(expectedColumns); + // original column id should stay preserved + expect(args.columns.slice(1).map((c) => c.originalColumnId)).toEqual([ + 'metric1', + 'metric2', + 'metric1', + 'metric2', + 'metric1', + 'metric2', + 'metric1', + 'metric2', + 'metric1', + 'metric2', + 'metric1', + 'metric2', + 'metric1', + 'metric2', + 'metric1', + 'metric2', + 'metric1', + 'metric2', + ]); - // // data should stay consistent - // expect(table.rows.length).toEqual(3); - // table.rows.forEach((row, index) => { - // // each metric block has an additional offset of 6 because there are 6 metrics for each bucket1/bucket2 combination (2 metrics * 3 bucket3 values) - // expect(row['A---D---metric1']).toEqual(index * 2 + 1); - // expect(row['A---D---metric2']).toEqual(index * 2 + 2); - // expect(row['A---E---metric1']).toEqual(index * 2 + 6 + 1); - // expect(row['A---E---metric2']).toEqual(index * 2 + 6 + 2); - // expect(row['A---F---metric1']).toEqual(index * 2 + 12 + 1); - // expect(row['A---F---metric2']).toEqual(index * 2 + 12 + 2); + // data should stay consistent + expect(table.rows.length).toEqual(3); + table.rows.forEach((row, index) => { + // each metric block has an additional offset of 6 because there are 6 metrics for each bucket1/bucket2 combination (2 metrics * 3 bucket3 values) + expect(row['A---D---metric1']).toEqual(index * 2 + 1); + expect(row['A---D---metric2']).toEqual(index * 2 + 2); + expect(row['A---E---metric1']).toEqual(index * 2 + 6 + 1); + expect(row['A---E---metric2']).toEqual(index * 2 + 6 + 2); + expect(row['A---F---metric1']).toEqual(index * 2 + 12 + 1); + expect(row['A---F---metric2']).toEqual(index * 2 + 12 + 2); - // expect(row['B---D---metric1']).toEqual(index * 2 + 18 + 1); - // expect(row['B---D---metric2']).toEqual(index * 2 + 18 + 2); - // expect(row['B---E---metric1']).toEqual(index * 2 + 24 + 1); - // expect(row['B---E---metric2']).toEqual(index * 2 + 24 + 2); - // expect(row['B---F---metric1']).toEqual(index * 2 + 30 + 1); - // expect(row['B---F---metric2']).toEqual(index * 2 + 30 + 2); + expect(row['B---D---metric1']).toEqual(index * 2 + 18 + 1); + expect(row['B---D---metric2']).toEqual(index * 2 + 18 + 2); + expect(row['B---E---metric1']).toEqual(index * 2 + 24 + 1); + expect(row['B---E---metric2']).toEqual(index * 2 + 24 + 2); + expect(row['B---F---metric1']).toEqual(index * 2 + 30 + 1); + expect(row['B---F---metric2']).toEqual(index * 2 + 30 + 2); - // expect(row['C---D---metric1']).toEqual(index * 2 + 36 + 1); - // expect(row['C---D---metric2']).toEqual(index * 2 + 36 + 2); - // expect(row['C---E---metric1']).toEqual(index * 2 + 42 + 1); - // expect(row['C---E---metric2']).toEqual(index * 2 + 42 + 2); - // expect(row['C---F---metric1']).toEqual(index * 2 + 48 + 1); - // expect(row['C---F---metric2']).toEqual(index * 2 + 48 + 2); - // }); - // }); + expect(row['C---D---metric1']).toEqual(index * 2 + 36 + 1); + expect(row['C---D---metric2']).toEqual(index * 2 + 36 + 2); + expect(row['C---E---metric1']).toEqual(index * 2 + 42 + 1); + expect(row['C---E---metric2']).toEqual(index * 2 + 42 + 2); + expect(row['C---F---metric1']).toEqual(index * 2 + 48 + 1); + expect(row['C---F---metric2']).toEqual(index * 2 + 48 + 2); + }); + }); - // it('should be able to handle missing values', () => { - // const table = buildTable(); - // const args = buildArgs(); - // args.columns[0].isTransposed = true; - // args.columns[1].isTransposed = true; - // // delete A-E-Z bucket - // table.rows.splice(5, 1); - // transposeTable(args, table, buildFormatters()); - // expect(args.columns.length).toEqual(19); - // expect(table.columns.length).toEqual(19); - // expect(table.rows.length).toEqual(3); - // expect(table.rows[2]['A---E---metric1']).toEqual(undefined); - // expect(table.rows[2]['A---E---metric2']).toEqual(undefined); - // // 1 bucket column and 2 missing from the regular 18 columns - // expect(Object.values(table.rows[2]).filter((val) => val !== undefined).length).toEqual( - // 1 + 18 - 2 - // ); - // }); + it('should be able to handle missing values', () => { + const table = buildTable(); + const args = buildArgs(); + args.columns[0].isTransposed = true; + args.columns[1].isTransposed = true; + // delete A-E-Z bucket + table.rows.splice(5, 1); + transposeTable(args, table, buildFormatters()); + expect(args.columns.length).toEqual(19); + expect(table.columns.length).toEqual(19); + expect(table.rows.length).toEqual(3); + expect(table.rows[2]['A---E---metric1']).toEqual(undefined); + expect(table.rows[2]['A---E---metric2']).toEqual(undefined); + // 1 bucket column and 2 missing from the regular 18 columns + expect(Object.values(table.rows[2]).filter((val) => val !== undefined).length).toEqual( + 1 + 18 - 2 + ); + }); it('should not fail for no data', () => { const table = buildTable();