mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-13 17:59:48 +00:00
test(ui): Refactor useExtractFieldTagsInfo and useExtractFieldGlossaryTermsInfo tests (#14607)
This commit is contained in:
parent
9698850f08
commit
22e382d1be
@ -1,4 +1,5 @@
|
|||||||
import { renderHook } from '@testing-library/react-hooks';
|
import { renderHook } from '@testing-library/react-hooks';
|
||||||
|
import { beforeEach } from 'vitest';
|
||||||
|
|
||||||
import { pathMatchesExact, pathMatchesInsensitiveToV2 } from '@app/entityV2/dataset/profile/schema/utils/utils';
|
import { pathMatchesExact, pathMatchesInsensitiveToV2 } from '@app/entityV2/dataset/profile/schema/utils/utils';
|
||||||
import useExtractFieldGlossaryTermsInfo from '@app/entityV2/shared/tabs/Dataset/Schema/utils/useExtractFieldGlossaryTermsInfo';
|
import useExtractFieldGlossaryTermsInfo from '@app/entityV2/shared/tabs/Dataset/Schema/utils/useExtractFieldGlossaryTermsInfo';
|
||||||
@ -10,9 +11,21 @@ import {
|
|||||||
SchemaFieldDataType,
|
SchemaFieldDataType,
|
||||||
} from '@src/types.generated';
|
} from '@src/types.generated';
|
||||||
|
|
||||||
|
const mockUseBaseEntity = vi.hoisted(() => vi.fn());
|
||||||
|
|
||||||
|
vi.mock('@src/app/entity/shared/EntityContext', async (importOriginal) => {
|
||||||
|
const original = await importOriginal<object>();
|
||||||
|
return {
|
||||||
|
...original,
|
||||||
|
useBaseEntity: mockUseBaseEntity,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
describe('useExtractFieldTermsInfo', () => {
|
describe('useExtractFieldTermsInfo', () => {
|
||||||
|
const dummySchemaFieldUrn = 'urn:li:schemaField:testField';
|
||||||
|
|
||||||
const testTerm: GlossaryTerm = {
|
const testTerm: GlossaryTerm = {
|
||||||
urn: 'urn:testField',
|
urn: 'urn:li:glossaryTerm:testTermName',
|
||||||
type: EntityType.GlossaryTerm,
|
type: EntityType.GlossaryTerm,
|
||||||
name: 'testTermName',
|
name: 'testTermName',
|
||||||
hierarchicalName: 'test.testTermName',
|
hierarchicalName: 'test.testTermName',
|
||||||
@ -24,7 +37,7 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const testTerm2: GlossaryTerm = {
|
const testTerm2: GlossaryTerm = {
|
||||||
urn: 'urn:testField2',
|
urn: 'urn:li:glossaryTerm:testTermName2',
|
||||||
type: EntityType.GlossaryTerm,
|
type: EntityType.GlossaryTerm,
|
||||||
name: 'testTermName2',
|
name: 'testTermName2',
|
||||||
hierarchicalName: 'test.testTermName2',
|
hierarchicalName: 'test.testTermName2',
|
||||||
@ -36,7 +49,7 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const testTerm3: GlossaryTerm = {
|
const testTerm3: GlossaryTerm = {
|
||||||
urn: 'urn:testField3',
|
urn: 'urn:li:glossaryTerm:testTermName3',
|
||||||
type: EntityType.GlossaryTerm,
|
type: EntityType.GlossaryTerm,
|
||||||
name: 'testTermName3',
|
name: 'testTermName3',
|
||||||
hierarchicalName: 'test.testTermName3',
|
hierarchicalName: 'test.testTermName3',
|
||||||
@ -48,7 +61,7 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const extraTerm: GlossaryTerm = {
|
const extraTerm: GlossaryTerm = {
|
||||||
urn: 'urn:extraField',
|
urn: 'urn:li:glossaryTerm:extraTermName',
|
||||||
type: EntityType.GlossaryTerm,
|
type: EntityType.GlossaryTerm,
|
||||||
name: 'extraTermName',
|
name: 'extraTermName',
|
||||||
hierarchicalName: 'test.extraTermName',
|
hierarchicalName: 'test.extraTermName',
|
||||||
@ -68,7 +81,7 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
glossaryTerms: {
|
glossaryTerms: {
|
||||||
terms: [
|
terms: [
|
||||||
{
|
{
|
||||||
associatedUrn: 'urn:li:globalTerms:test.testTermName',
|
associatedUrn: dummySchemaFieldUrn,
|
||||||
term: testTerm,
|
term: testTerm,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -84,7 +97,7 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
glossaryTerms: {
|
glossaryTerms: {
|
||||||
terms: [
|
terms: [
|
||||||
{
|
{
|
||||||
associatedUrn: 'urn:li:globalTerms:test.testTermName',
|
associatedUrn: dummySchemaFieldUrn,
|
||||||
term: testTerm,
|
term: testTerm,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -95,7 +108,7 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
glossaryTerms: {
|
glossaryTerms: {
|
||||||
terms: [
|
terms: [
|
||||||
{
|
{
|
||||||
associatedUrn: 'urn:li:globalTerms:test.extraTermName',
|
associatedUrn: dummySchemaFieldUrn,
|
||||||
term: extraTerm,
|
term: extraTerm,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -116,7 +129,7 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
glossaryTerms: {
|
glossaryTerms: {
|
||||||
terms: [
|
terms: [
|
||||||
{
|
{
|
||||||
associatedUrn: 'urn:li:globalTerm:test.testTermName',
|
associatedUrn: dummySchemaFieldUrn,
|
||||||
term: testTerm,
|
term: testTerm,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -133,7 +146,7 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
glossaryTerms: {
|
glossaryTerms: {
|
||||||
terms: [
|
terms: [
|
||||||
{
|
{
|
||||||
associatedUrn: testTerm.urn,
|
associatedUrn: dummySchemaFieldUrn,
|
||||||
term: testTerm,
|
term: testTerm,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -148,18 +161,6 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
|
|
||||||
const emptyBaseEntity = {};
|
const emptyBaseEntity = {};
|
||||||
|
|
||||||
const { mockedUseBaseEntity } = vi.hoisted(() => {
|
|
||||||
return { mockedUseBaseEntity: vi.fn() };
|
|
||||||
});
|
|
||||||
|
|
||||||
vi.mock('@src/app/entity/shared/EntityContext', async (importOriginal) => {
|
|
||||||
const original = await importOriginal<object>();
|
|
||||||
return {
|
|
||||||
...original,
|
|
||||||
useBaseEntity: vi.fn(() => mockedUseBaseEntity()),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
expect(pathMatchesExact('testField', 'testField')).toBe(true);
|
expect(pathMatchesExact('testField', 'testField')).toBe(true);
|
||||||
expect(pathMatchesExact('testField', '[version=2.0].[type=record].testField')).toBe(false);
|
expect(pathMatchesExact('testField', '[version=2.0].[type=record].testField')).toBe(false);
|
||||||
@ -167,6 +168,10 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
expect(pathMatchesInsensitiveToV2('[version=2.0].[type=record].testField', 'testField')).toBe(true);
|
expect(pathMatchesInsensitiveToV2('[version=2.0].[type=record].testField', 'testField')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockUseBaseEntity.mockReturnValue(emptyBaseEntity);
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
vi.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
@ -212,7 +217,6 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should extract all terms when they were provided in both schema and editable metadata, but exclude duplicates', () => {
|
it('should extract all terms when they were provided in both schema and editable metadata, but exclude duplicates', () => {
|
||||||
mockedUseBaseEntity.mockReturnValue(emptyBaseEntity);
|
|
||||||
const extractFieldTermsInfo = renderHook(() => useExtractFieldGlossaryTermsInfo(filledEditableSchemaMetadata))
|
const extractFieldTermsInfo = renderHook(() => useExtractFieldGlossaryTermsInfo(filledEditableSchemaMetadata))
|
||||||
.result.current;
|
.result.current;
|
||||||
|
|
||||||
@ -244,7 +248,7 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
editableSchemaFieldInfo: [
|
editableSchemaFieldInfo: [
|
||||||
{
|
{
|
||||||
fieldPath: 'testField',
|
fieldPath: 'testField',
|
||||||
glossaryTerms: { terms: [{ term: testTerm2, associatedUrn: testTerm2.urn }] },
|
glossaryTerms: { terms: [{ term: testTerm2, associatedUrn: dummySchemaFieldUrn }] },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@ -253,7 +257,7 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
|
|
||||||
const schemaField: SchemaField = {
|
const schemaField: SchemaField = {
|
||||||
...directSchemaField,
|
...directSchemaField,
|
||||||
glossaryTerms: { terms: [{ term: testTerm3, associatedUrn: testTerm3.urn }] },
|
glossaryTerms: { terms: [{ term: testTerm3, associatedUrn: dummySchemaFieldUrn }] },
|
||||||
};
|
};
|
||||||
const { directTerms, editableTerms, uneditableTerms, numberOfTerms } = extractFieldTermsInfo(schemaField);
|
const { directTerms, editableTerms, uneditableTerms, numberOfTerms } = extractFieldTermsInfo(schemaField);
|
||||||
|
|
||||||
@ -267,7 +271,6 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not extract any terms when they are not provided', () => {
|
it('should not extract any terms when they are not provided', () => {
|
||||||
mockedUseBaseEntity.mockReturnValue(emptyBaseEntity);
|
|
||||||
const extractFieldTermsInfo = renderHook(() => useExtractFieldGlossaryTermsInfo(emptyEditableSchemaMetadata))
|
const extractFieldTermsInfo = renderHook(() => useExtractFieldGlossaryTermsInfo(emptyEditableSchemaMetadata))
|
||||||
.result.current;
|
.result.current;
|
||||||
|
|
||||||
@ -280,8 +283,6 @@ describe('useExtractFieldTermsInfo', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should extract extra uneditable terms from fields that match the field path insensitive to V2', () => {
|
it('should extract extra uneditable terms from fields that match the field path insensitive to V2', () => {
|
||||||
mockedUseBaseEntity.mockReturnValue(emptyBaseEntity);
|
|
||||||
|
|
||||||
const extractFieldTermsInfo = renderHook(() =>
|
const extractFieldTermsInfo = renderHook(() =>
|
||||||
useExtractFieldGlossaryTermsInfo(editableSchemaMetadataWithExtraTerms),
|
useExtractFieldGlossaryTermsInfo(editableSchemaMetadataWithExtraTerms),
|
||||||
).result.current;
|
).result.current;
|
||||||
|
|||||||
@ -1,12 +1,24 @@
|
|||||||
import { renderHook } from '@testing-library/react-hooks';
|
import { renderHook } from '@testing-library/react-hooks';
|
||||||
|
|
||||||
import { pathMatchesExact, pathMatchesInsensitiveToV2 } from '@app/entityV2/dataset/profile/schema/utils/utils';
|
|
||||||
import useExtractFieldTagsInfo from '@app/entityV2/shared/tabs/Dataset/Schema/utils/useExtractFieldTagsInfo';
|
import useExtractFieldTagsInfo from '@app/entityV2/shared/tabs/Dataset/Schema/utils/useExtractFieldTagsInfo';
|
||||||
|
import { pathMatchesExact, pathMatchesInsensitiveToV2 } from '@src/app/entityV2/dataset/profile/schema/utils/utils';
|
||||||
import { EditableSchemaMetadata, EntityType, SchemaField, SchemaFieldDataType, Tag } from '@src/types.generated';
|
import { EditableSchemaMetadata, EntityType, SchemaField, SchemaFieldDataType, Tag } from '@src/types.generated';
|
||||||
|
|
||||||
|
const mockUseBaseEntity = vi.hoisted(() => vi.fn());
|
||||||
|
|
||||||
|
vi.mock('@src/app/entity/shared/EntityContext', async (importOriginal) => {
|
||||||
|
const original = await importOriginal<object>();
|
||||||
|
return {
|
||||||
|
...original,
|
||||||
|
useBaseEntity: mockUseBaseEntity,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
describe('useExtractFieldTagsInfo', () => {
|
describe('useExtractFieldTagsInfo', () => {
|
||||||
|
const dummySchemaFieldUrn = 'urn:li:schemaField:testField';
|
||||||
|
|
||||||
const testTag: Tag = {
|
const testTag: Tag = {
|
||||||
urn: 'urn:testField',
|
urn: 'urn:li:tag:testTagName',
|
||||||
type: EntityType.Tag,
|
type: EntityType.Tag,
|
||||||
name: 'testTagName',
|
name: 'testTagName',
|
||||||
properties: {
|
properties: {
|
||||||
@ -15,7 +27,7 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const testTag2: Tag = {
|
const testTag2: Tag = {
|
||||||
urn: 'urn:testField2',
|
urn: 'urn:li:tag:testTagName2',
|
||||||
type: EntityType.Tag,
|
type: EntityType.Tag,
|
||||||
name: 'testTagName2',
|
name: 'testTagName2',
|
||||||
properties: {
|
properties: {
|
||||||
@ -24,7 +36,7 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const testTag3: Tag = {
|
const testTag3: Tag = {
|
||||||
urn: 'urn:testField3',
|
urn: 'urn:li:tag:testTagName3',
|
||||||
type: EntityType.Tag,
|
type: EntityType.Tag,
|
||||||
name: 'testTagName3',
|
name: 'testTagName3',
|
||||||
properties: {
|
properties: {
|
||||||
@ -33,7 +45,7 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const extraTag: Tag = {
|
const extraTag: Tag = {
|
||||||
urn: 'urn:extraField',
|
urn: 'urn:li:tag:extraTagName',
|
||||||
type: EntityType.Tag,
|
type: EntityType.Tag,
|
||||||
name: 'extraTagName',
|
name: 'extraTagName',
|
||||||
properties: {
|
properties: {
|
||||||
@ -50,7 +62,7 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
globalTags: {
|
globalTags: {
|
||||||
tags: [
|
tags: [
|
||||||
{
|
{
|
||||||
associatedUrn: 'urn:li:globalTags:test.testTagName',
|
associatedUrn: dummySchemaFieldUrn,
|
||||||
tag: testTag,
|
tag: testTag,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -66,7 +78,7 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
globalTags: {
|
globalTags: {
|
||||||
tags: [
|
tags: [
|
||||||
{
|
{
|
||||||
associatedUrn: 'urn:li:globalTags:test.testTagName',
|
associatedUrn: dummySchemaFieldUrn,
|
||||||
tag: testTag,
|
tag: testTag,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -77,7 +89,7 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
globalTags: {
|
globalTags: {
|
||||||
tags: [
|
tags: [
|
||||||
{
|
{
|
||||||
associatedUrn: 'urn:li:globalTags:test.extraTagName',
|
associatedUrn: dummySchemaFieldUrn,
|
||||||
tag: extraTag,
|
tag: extraTag,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -98,7 +110,7 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
globalTags: {
|
globalTags: {
|
||||||
tags: [
|
tags: [
|
||||||
{
|
{
|
||||||
associatedUrn: 'urn:li:globalTag:test.testTagName',
|
associatedUrn: dummySchemaFieldUrn,
|
||||||
tag: testTag,
|
tag: testTag,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -115,7 +127,7 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
tags: {
|
tags: {
|
||||||
tags: [
|
tags: [
|
||||||
{
|
{
|
||||||
associatedUrn: testTag.urn,
|
associatedUrn: dummySchemaFieldUrn,
|
||||||
tag: testTag,
|
tag: testTag,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -130,18 +142,6 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
|
|
||||||
const emptyBaseEntity = {};
|
const emptyBaseEntity = {};
|
||||||
|
|
||||||
const { mockedUseBaseEntity } = vi.hoisted(() => {
|
|
||||||
return { mockedUseBaseEntity: vi.fn() };
|
|
||||||
});
|
|
||||||
|
|
||||||
vi.mock('@src/app/entity/shared/EntityContext', async (importOriginal) => {
|
|
||||||
const original = await importOriginal<object>();
|
|
||||||
return {
|
|
||||||
...original,
|
|
||||||
useBaseEntity: vi.fn(() => mockedUseBaseEntity()),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
expect(pathMatchesExact('testField', 'testField')).toBe(true);
|
expect(pathMatchesExact('testField', 'testField')).toBe(true);
|
||||||
expect(pathMatchesExact('testField', '[version=2.0].[type=record].testField')).toBe(false);
|
expect(pathMatchesExact('testField', '[version=2.0].[type=record].testField')).toBe(false);
|
||||||
@ -149,6 +149,10 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
expect(pathMatchesInsensitiveToV2('[version=2.0].[type=record].testField', 'testField')).toBe(true);
|
expect(pathMatchesInsensitiveToV2('[version=2.0].[type=record].testField', 'testField')).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockUseBaseEntity.mockReturnValue(emptyBaseEntity);
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
vi.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
@ -194,7 +198,6 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should extract all tags when they were provided in both schema and editable metadata, but exclude duplicates', () => {
|
it('should extract all tags when they were provided in both schema and editable metadata, but exclude duplicates', () => {
|
||||||
mockedUseBaseEntity.mockReturnValue(emptyBaseEntity);
|
|
||||||
const extractFieldTagsInfo = renderHook(() => useExtractFieldTagsInfo(filledEditableSchemaMetadata)).result
|
const extractFieldTagsInfo = renderHook(() => useExtractFieldTagsInfo(filledEditableSchemaMetadata)).result
|
||||||
.current;
|
.current;
|
||||||
|
|
||||||
@ -225,7 +228,7 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
editableSchemaFieldInfo: [
|
editableSchemaFieldInfo: [
|
||||||
{
|
{
|
||||||
fieldPath: 'testField',
|
fieldPath: 'testField',
|
||||||
globalTags: { tags: [{ tag: testTag2, associatedUrn: testTag2.urn }] },
|
globalTags: { tags: [{ tag: testTag2, associatedUrn: dummySchemaFieldUrn }] },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@ -233,7 +236,7 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
|
|
||||||
const schemaField: SchemaField = {
|
const schemaField: SchemaField = {
|
||||||
...directSchemaField,
|
...directSchemaField,
|
||||||
globalTags: { tags: [{ tag: testTag3, associatedUrn: testTag3.urn }] },
|
globalTags: { tags: [{ tag: testTag3, associatedUrn: dummySchemaFieldUrn }] },
|
||||||
};
|
};
|
||||||
const { directTags, editableTags, uneditableTags, numberOfTags } = extractFieldTagsInfo(schemaField);
|
const { directTags, editableTags, uneditableTags, numberOfTags } = extractFieldTagsInfo(schemaField);
|
||||||
|
|
||||||
@ -247,7 +250,6 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not extract any tags when they are not provided', () => {
|
it('should not extract any tags when they are not provided', () => {
|
||||||
mockedUseBaseEntity.mockReturnValue(emptyBaseEntity);
|
|
||||||
const extractFieldTagsInfo = renderHook(() => useExtractFieldTagsInfo(emptyEditableSchemaMetadata)).result
|
const extractFieldTagsInfo = renderHook(() => useExtractFieldTagsInfo(emptyEditableSchemaMetadata)).result
|
||||||
.current;
|
.current;
|
||||||
|
|
||||||
@ -260,8 +262,6 @@ describe('useExtractFieldTagsInfo', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should extract extra uneditable tags from fields that match the field path insensitive to V2', () => {
|
it('should extract extra uneditable tags from fields that match the field path insensitive to V2', () => {
|
||||||
mockedUseBaseEntity.mockReturnValue(emptyBaseEntity);
|
|
||||||
|
|
||||||
const extractFieldTagsInfo = renderHook(() => useExtractFieldTagsInfo(editableSchemaMetadataWithExtraTags))
|
const extractFieldTagsInfo = renderHook(() => useExtractFieldTagsInfo(editableSchemaMetadataWithExtraTags))
|
||||||
.result.current;
|
.result.current;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user