From 91fdbe6a8e6e1b15a55e3997e68f05305f7f36f7 Mon Sep 17 00:00:00 2001 From: yubonluo Date: Mon, 11 Nov 2024 16:00:04 +0800 Subject: [PATCH] optimize the code Signed-off-by: yubonluo --- .../server/saved_objects/import/utils.test.ts | 18 +- .../import/validate_data_sources.test.ts | 18 +- .../duplicate_result_flyout.test.tsx.snap | 675 ------------------ .../duplicate_result_flyout.test.tsx | 174 +++-- .../integration_tests/duplicate.test.ts | 71 ++ 5 files changed, 207 insertions(+), 749 deletions(-) delete mode 100644 src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/duplicate_result_flyout.test.tsx.snap diff --git a/src/core/server/saved_objects/import/utils.test.ts b/src/core/server/saved_objects/import/utils.test.ts index e39fa228ed06..72f66d0fd5ec 100644 --- a/src/core/server/saved_objects/import/utils.test.ts +++ b/src/core/server/saved_objects/import/utils.test.ts @@ -370,14 +370,16 @@ describe('findReferenceDataSourceForObject', () => { type: 'non-data-source', attributes: {}, }, + { + id: '6', + references: [{ id: '7', type: 'index-pattern', name: '7' }], + type: 'non-data-source', + attributes: {}, + }, ]; const ObjectsMap = new Map(savedObjects.map((so) => [so.id, so])); - test('returns null if no references exist', () => { - expect(findReferenceDataSourceForObject(savedObjects[2], ObjectsMap)).toBeNull(); - }); - test('returns the data-source reference if it exists in the references', () => { const result = findReferenceDataSourceForObject(savedObjects[0], ObjectsMap); expect(result).toEqual({ id: '5', type: 'data-source', name: '5' }); @@ -387,11 +389,19 @@ describe('findReferenceDataSourceForObject', () => { expect(findReferenceDataSourceForObject(savedObjects[1], ObjectsMap)).toBeNull(); }); + test('returns null if no references exist', () => { + expect(findReferenceDataSourceForObject(savedObjects[2], ObjectsMap)).toBeNull(); + }); + test('returns nested data-source reference if found', () => { const result = findReferenceDataSourceForObject(savedObjects[3], ObjectsMap); expect(result).toEqual({ id: '5', type: 'data-source', name: '5' }); }); + test('returns null if the nested references have no data-source reference', () => { + expect(findReferenceDataSourceForObject(savedObjects[4], ObjectsMap)).toBeNull(); + }); + test('returns null if circular reference', () => { const circularAssets: Array> = [ { diff --git a/src/core/server/saved_objects/import/validate_data_sources.test.ts b/src/core/server/saved_objects/import/validate_data_sources.test.ts index a99f70f6363a..1b0d1fa6c7f5 100644 --- a/src/core/server/saved_objects/import/validate_data_sources.test.ts +++ b/src/core/server/saved_objects/import/validate_data_sources.test.ts @@ -10,14 +10,6 @@ import * as utilsExports from './utils'; describe('validateDataSources', () => { const savedObjectsClient = savedObjectsClientMock.create(); - const errorAccumulator: SavedObjectsImportError[] = [ - { - id: '1', - type: 'dashboards', - meta: {}, - error: { type: 'missing_references', references: [] }, - }, - ]; const workspaces = ['workspace-1']; beforeEach(() => { @@ -25,6 +17,14 @@ describe('validateDataSources', () => { }); it('returns empty array if no valid objects', async () => { + const errorAccumulator: SavedObjectsImportError[] = [ + { + id: '1', + type: 'dashboards', + meta: {}, + error: { type: 'missing_references', references: [] }, + }, + ]; const savedObjects = [{ id: '1', type: 'dashboards', attributes: {}, references: [] }]; const result = await validateDataSources( savedObjects, @@ -72,7 +72,7 @@ describe('validateDataSources', () => { expect(result).toEqual([ { error: { - dataSourceName: 'DataSource 2', + dataSource: 'data-source-2', type: 'missing_data_source', }, id: '1', diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/duplicate_result_flyout.test.tsx.snap b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/duplicate_result_flyout.test.tsx.snap deleted file mode 100644 index f86aa5155d62..000000000000 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/duplicate_result_flyout.test.tsx.snap +++ /dev/null @@ -1,675 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`DuplicateResultFlyout copy count is null 1`] = ` -HTMLCollection [ - - - - - - - - - - -