-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a4500b
commit ce47405
Showing
2 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
openmetadata-ui/src/main/resources/ui/src/utils/CSV/CSV.utils.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright 2024 Collate. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { EntityType } from '../../enums/entity.enum'; | ||
import { | ||
getColumnConfig, | ||
getCSVStringFromColumnsAndDataSource, | ||
getEntityColumnsAndDataSourceFromCSV, | ||
} from './CSV.utils'; | ||
|
||
describe('CSVUtils', () => { | ||
describe('getColumnConfig', () => { | ||
it('should return the column configuration object', () => { | ||
const column = 'description'; | ||
const columnConfig = getColumnConfig(column, EntityType.GLOSSARY); | ||
|
||
expect(columnConfig).toBeDefined(); | ||
expect(columnConfig.name).toBe(column); | ||
}); | ||
}); | ||
|
||
describe('getEntityColumnsAndDataSourceFromCSV', () => { | ||
it('should return the columns and data source from the CSV', () => { | ||
const csv = [ | ||
['col1', 'col2'], | ||
['value1', 'value2'], | ||
]; | ||
const { columns, dataSource } = getEntityColumnsAndDataSourceFromCSV( | ||
csv, | ||
EntityType.GLOSSARY | ||
); | ||
|
||
expect(columns).toHaveLength(2); | ||
expect(dataSource).toHaveLength(1); | ||
}); | ||
}); | ||
|
||
describe('getCSVStringFromColumnsAndDataSource', () => { | ||
it('should return the CSV string from the columns and data source for non-quoted columns', () => { | ||
const columns = [{ name: 'col1' }, { name: 'col2' }]; | ||
const dataSource = [{ col1: 'value1', col2: 'value2' }]; | ||
const csvString = getCSVStringFromColumnsAndDataSource( | ||
columns, | ||
dataSource | ||
); | ||
|
||
expect(csvString).toBe('col1,col2\nvalue1,value2'); | ||
}); | ||
|
||
it('should return the CSV string from the columns and data source with quoted columns', () => { | ||
const columns = [ | ||
{ name: 'tags' }, | ||
{ name: 'glossaryTerms' }, | ||
{ name: 'description' }, | ||
{ name: 'domain' }, | ||
]; | ||
const dataSource = [ | ||
{ | ||
tags: 'value1', | ||
glossaryTerms: 'value2', | ||
description: 'something new', | ||
domain: 'domain1', | ||
}, | ||
]; | ||
const csvString = getCSVStringFromColumnsAndDataSource( | ||
columns, | ||
dataSource | ||
); | ||
|
||
expect(csvString).toBe( | ||
'tags,glossaryTerms,description,domain\n"value1","value2",something new,"domain1"' | ||
); | ||
}); | ||
|
||
it('should return quoted value if data contains comma', () => { | ||
const columns = [ | ||
{ name: 'tags' }, | ||
{ name: 'glossaryTerms' }, | ||
{ name: 'description' }, | ||
{ name: 'domain' }, | ||
]; | ||
const dataSource = [ | ||
{ | ||
tags: 'value,1', | ||
glossaryTerms: 'value_2', | ||
description: 'something#new', | ||
domain: 'domain,1', | ||
}, | ||
]; | ||
const csvString = getCSVStringFromColumnsAndDataSource( | ||
columns, | ||
dataSource | ||
); | ||
|
||
expect(csvString).toBe( | ||
`tags,glossaryTerms,description,domain\n"value,1","value_2",something#new,"domain,1"` | ||
); | ||
}); | ||
}); | ||
}); |
133 changes: 133 additions & 0 deletions
133
openmetadata-ui/src/main/resources/ui/src/utils/CSV/CSVUtilsClassBase.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Copyright 2024 Collate. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import React from 'react'; | ||
import { EntityType } from '../../enums/entity.enum'; | ||
import csvUtilsClassBase from './CSVUtilsClassBase'; | ||
|
||
jest.mock( | ||
'../../components/common/AsyncSelectList/TreeAsyncSelectList', | ||
() => ({ | ||
__esModule: true, | ||
default: jest.fn(), | ||
}) | ||
); | ||
|
||
jest.mock( | ||
'../../components/common/DomainSelectableList/DomainSelectableList.component', | ||
() => ({ | ||
__esModule: true, | ||
default: jest.fn(), | ||
}) | ||
); | ||
|
||
jest.mock('../../components/common/InlineEdit/InlineEdit.component', () => ({ | ||
__esModule: true, | ||
default: jest.fn(), | ||
})); | ||
|
||
jest.mock('../../components/common/TierCard/TierCard', () => ({ | ||
__esModule: true, | ||
default: jest.fn(), | ||
})); | ||
|
||
jest.mock( | ||
'../../components/common/UserTeamSelectableList/UserTeamSelectableList.component', | ||
() => ({ | ||
__esModule: true, | ||
UserTeamSelectableList: jest | ||
.fn() | ||
.mockReturnValue(<p>UserTeamSelectableList</p>), | ||
}) | ||
); | ||
|
||
jest.mock( | ||
'../../components/Modals/ModalWithMarkdownEditor/ModalWithMarkdownEditor', | ||
() => ({ | ||
__esModule: true, | ||
ModalWithMarkdownEditor: jest.fn(), | ||
}) | ||
); | ||
jest.mock( | ||
'../../components/Modals/ModalWithCustomProperty/ModalWithCustomPropertyEditor.component', | ||
() => ({ | ||
__esModule: true, | ||
ModalWithCustomPropertyEditor: jest.fn(), | ||
}) | ||
); | ||
|
||
describe('CSV utils ClassBase', () => { | ||
describe('getEditor', () => { | ||
it('should return the editor component for the specified column', () => { | ||
const column = 'owner'; | ||
const editor = csvUtilsClassBase.getEditor(column, EntityType.GLOSSARY); | ||
|
||
expect(editor).toBeDefined(); | ||
}); | ||
|
||
it('should return undefined for unknown columns', () => { | ||
const column = 'unknown'; | ||
const editor = csvUtilsClassBase.getEditor(column, EntityType.GLOSSARY); | ||
|
||
expect(editor).toBeUndefined(); | ||
}); | ||
|
||
it('should return the editor component for the "description" column', () => { | ||
const column = 'description'; | ||
const editor = csvUtilsClassBase.getEditor(column, EntityType.GLOSSARY); | ||
|
||
expect(editor).toBeDefined(); | ||
}); | ||
|
||
it('should return the editor component for the "tags" column', () => { | ||
const column = 'tags'; | ||
const editor = csvUtilsClassBase.getEditor(column, EntityType.GLOSSARY); | ||
|
||
expect(editor).toBeDefined(); | ||
}); | ||
|
||
it('should return the editor component for the "glossaryTerms" column', () => { | ||
const column = 'glossaryTerms'; | ||
const editor = csvUtilsClassBase.getEditor(column, EntityType.GLOSSARY); | ||
|
||
expect(editor).toBeDefined(); | ||
}); | ||
|
||
it('should return the editor component for the "tiers" column', () => { | ||
const column = 'tiers'; | ||
const editor = csvUtilsClassBase.getEditor(column, EntityType.GLOSSARY); | ||
|
||
expect(editor).toBeDefined(); | ||
}); | ||
|
||
it('should return the editor component for the "extension" column', () => { | ||
const column = 'extension'; | ||
const editor = csvUtilsClassBase.getEditor(column, EntityType.GLOSSARY); | ||
|
||
expect(editor).toBeDefined(); | ||
}); | ||
|
||
it('should return the editor component for the "reviewers" column', () => { | ||
const column = 'reviewers'; | ||
const editor = csvUtilsClassBase.getEditor(column, EntityType.GLOSSARY); | ||
|
||
expect(editor).toBeDefined(); | ||
}); | ||
|
||
it('should return the editor component for the "domain" column', () => { | ||
const column = 'domain'; | ||
const editor = csvUtilsClassBase.getEditor(column, EntityType.GLOSSARY); | ||
|
||
expect(editor).toBeDefined(); | ||
}); | ||
}); | ||
}); |