From 5ba59ff80b4b3ec2667ebb0467ff62eb8426a0e5 Mon Sep 17 00:00:00 2001 From: dej611 Date: Tue, 4 Jan 2022 17:00:44 +0100 Subject: [PATCH] :white_check_mark: Add tests for it --- .../data/common/exports/export_csv.test.ts | 24 + .../__snapshots__/data_view.test.tsx.snap | 687 ++++++++++++++++++ .../components/data_view.test.tsx | 38 + 3 files changed, 749 insertions(+) diff --git a/src/plugins/data/common/exports/export_csv.test.ts b/src/plugins/data/common/exports/export_csv.test.ts index f108e69c68d56..a8567ff61a0ca 100644 --- a/src/plugins/data/common/exports/export_csv.test.ts +++ b/src/plugins/data/common/exports/export_csv.test.ts @@ -84,4 +84,28 @@ describe('CSV exporter', () => { }) ).toMatch('columnOne\r\n"\'=1"\r\n'); }); + + test('should filter out columns when there are meta information', () => { + const datatable = getDataTable({ multipleColumns: true }); + // Make only the first column visible + datatable.columns[0].meta.dimensionName = 'First column'; + expect( + datatableToCSV(datatable, { + ...getDefaultOptions(), + escapeFormulaValues: true, + formatFactory: () => ({ convert: (v: unknown) => v } as FieldFormat), + }) + ).toMatch('columnOne\r\nvalue\r\n'); + }); + + test('should not filter out columns if no meta information are found', () => { + const datatable = getDataTable({ multipleColumns: true }); + expect( + datatableToCSV(datatable, { + ...getDefaultOptions(), + escapeFormulaValues: true, + formatFactory: () => ({ convert: (v: unknown) => v } as FieldFormat), + }) + ).toMatch('columnOne,columnTwo\r\nvalue,5\r\n'); + }); }); diff --git a/src/plugins/data/public/utils/table_inspector_view/components/__snapshots__/data_view.test.tsx.snap b/src/plugins/data/public/utils/table_inspector_view/components/__snapshots__/data_view.test.tsx.snap index 4db3f780fdebe..00b6f21dd1a84 100644 --- a/src/plugins/data/public/utils/table_inspector_view/components/__snapshots__/data_view.test.tsx.snap +++ b/src/plugins/data/public/utils/table_inspector_view/components/__snapshots__/data_view.test.tsx.snap @@ -1,5 +1,692 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Inspector Data View component should filter out hidden column if only part of the columns have meta information 1`] = ` + + + +

+ +

+ + } + title={ +

+ +

+ } + > + +
+
+
+
+ +

+ + No data available + +

+
+ + + +
+ + +
+

+ + The element did not provide any data. + +

+
+
+ + +
+
+
+
+ + + + +`; + +exports[`Inspector Data View component should render all column if no column has meta information 1`] = ` + + + +

+ +

+ + } + title={ +

+ +

+ } + > + +
+
+
+
+ +

+ + No data available + +

+
+ + + +
+ + +
+

+ + The element did not provide any data. + +

+
+
+ + +
+
+
+
+ + + + +`; + exports[`Inspector Data View component should render empty state 1`] = ` { expect(component).toMatchSnapshot(); }); + + it('should filter out hidden column if only part of the columns have meta information', () => { + const multitableAdapter = { tables: new TablesAdapter() }; + + const component = mountWithIntl( + // eslint-disable-next-line react/jsx-pascal-case + + ); + multitableAdapter.tables.logDatatable('table1', { + columns: [ + { id: '1', name: 'column1', meta: { type: 'number', dimensionName: 'accessor' } }, + { id: '2', name: 'column2', meta: { type: 'number' } }, + ], + rows: [{ '1': 123, '2': 5 }], + type: 'datatable', + }); + + expect(component).toMatchSnapshot(); + }); + + it('should render all column if no column has meta information', () => { + const multitableAdapter = { tables: new TablesAdapter() }; + + const component = mountWithIntl( + // eslint-disable-next-line react/jsx-pascal-case + + ); + multitableAdapter.tables.logDatatable('table1', { + columns: [ + { id: '1', name: 'column1', meta: { type: 'number' } }, + { id: '2', name: 'column2', meta: { type: 'number' } }, + ], + rows: [{ '1': 123, '2': 5 }], + type: 'datatable', + }); + + expect(component).toMatchSnapshot(); + }); }); });