Skip to content

Commit

Permalink
Fix custom attrs for glossary term (#14316)
Browse files Browse the repository at this point in the history
* fix: update entity type to glossary term

* fix: unit tests

* fix: add cypress
  • Loading branch information
karanh37 committed Dec 8, 2023
1 parent bb632aa commit 9a335a1
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 41 deletions.
78 changes: 40 additions & 38 deletions openmetadata-ui/src/main/resources/ui/cypress/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -877,50 +877,52 @@ export const addCustomPropertiesForEntity = (
// Navigating to home page
cy.clickOnLogo();

// Checking the added property in Entity
if (entityObj) {
// Checking the added property in Entity

visitEntityDetailsPage({
term: entityObj.term,
serviceName: entityObj.serviceName,
entity: entityObj.entity,
});
visitEntityDetailsPage({
term: entityObj.term,
serviceName: entityObj.serviceName,
entity: entityObj.entity,
});

cy.get('[data-testid="custom_properties"]').click();
cy.get('tbody').should('contain', propertyName);
cy.get('[data-testid="custom_properties"]').click();
cy.get('tbody').should('contain', propertyName);

// Adding value for the custom property
// Adding value for the custom property

// Navigating through the created custom property for adding value
cy.get(`[data-row-key="${propertyName}"]`)
.find('[data-testid="edit-icon"]')
.as('editbutton');
cy.wait(1000);
// Navigating through the created custom property for adding value
cy.get(`[data-row-key="${propertyName}"]`)
.find('[data-testid="edit-icon"]')
.as('editbutton');
cy.wait(1000);

cy.get('@editbutton').click();
cy.get('@editbutton').click();

interceptURL(
'PATCH',
`/api/v1/${customPropertyData.entityApiType}/*`,
'patchEntity'
);
// Checking for value text box or markdown box
cy.get('body').then(($body) => {
if ($body.find('[data-testid="value-input"]').length > 0) {
cy.get('[data-testid="value-input"]').type(value);
cy.get('[data-testid="inline-save-btn"]').click();
} else if (
$body.find(
'.toastui-editor-md-container > .toastui-editor > .ProseMirror'
)
) {
cy.get(
'.toastui-editor-md-container > .toastui-editor > .ProseMirror'
).type(value);
cy.get('[data-testid="save"]').click();
}
});
verifyResponseStatusCode('@patchEntity', 200);
cy.get(`[data-row-key="${propertyName}"]`).should('contain', value);
interceptURL(
'PATCH',
`/api/v1/${customPropertyData.entityApiType}/*`,
'patchEntity'
);
// Checking for value text box or markdown box
cy.get('body').then(($body) => {
if ($body.find('[data-testid="value-input"]').length > 0) {
cy.get('[data-testid="value-input"]').type(value);
cy.get('[data-testid="inline-save-btn"]').click();
} else if (
$body.find(
'.toastui-editor-md-container > .toastui-editor > .ProseMirror'
)
) {
cy.get(
'.toastui-editor-md-container > .toastui-editor > .ProseMirror'
).type(value);
cy.get('[data-testid="save"]').click();
}
});
verifyResponseStatusCode('@patchEntity', 200);
cy.get(`[data-row-key="${propertyName}"]`).should('contain', value);
}
};

export const editCreatedProperty = (propertyName) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,72 @@ describe('Custom Properties should work properly', () => {
});
});
});

describe('Create custom properties for glossary', () => {
const glossaryTerm = {
name: 'glossaryTerm',
description: 'This is Glossary Term custom property',
integerValue: '45',
stringValue: 'This is string propery',
markdownValue: 'This is markdown value',
entityApiType: 'glossaryTerm',
};
const propertyName = `addcyentity${glossaryTerm.name}test${uuid()}`;

it('test custom properties in advanced search modal', () => {
cy.get(`[data-menu-id*="customAttributes.${glossaryTerm.name}"]`)
.scrollIntoView()
.should('be.visible')
.click();

addCustomPropertiesForEntity(
propertyName,
glossaryTerm,
'Integer',
'45',
null
);

// Navigating to explore page
cy.get('[data-testid="app-bar-item-explore"]').click();
interceptURL(
'GET',
`/api/v1/metadata/types/name/glossaryTerm*`,
'getEntity'
);
cy.get('[data-testid="glossaries-tab"]').click();

cy.get('[data-testid="advance-search-button"]').click();
verifyResponseStatusCode('@getEntity', 200);

// Click on field dropdown
cy.get('.rule--field > .ant-select > .ant-select-selector').eq(0).click();

// Select custom property fields
cy.get(`[title="Custom Properties"]`).eq(0).click();

// Click on field dropdown
cy.get('.rule--field > .ant-select > .ant-select-selector').eq(0).click();

// Verify field exists
cy.get(`[title="${propertyName}"]`).should('be.visible');
});

it(`Delete created property for glossary term entity`, () => {
interceptURL(
'GET',
`/api/v1/metadata/types/name/${glossaryTerm.name}*`,
'getEntity'
);

// Selecting the entity
cy.get(`[data-menu-id*="customAttributes.${glossaryTerm.name}"]`)
.scrollIntoView()
.should('be.visible')
.click();

verifyResponseStatusCode('@getEntity', 200);
deleteCreatedProperty(propertyName);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ const getCommonQueryBuilderFields = (
},
},
extension: {
label: t('label.custom-attribute-plural'),
label: t('label.custom-property-plural'),
type: '!group',
mainWidgetProps,
subfields: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export const getGlobalSettingsMenuWithPermission = (
],
},
{
category: i18next.t('label.custom-attribute-plural'),
category: i18next.t('label.custom-property-plural'),
key: 'customAttributes',
items: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2023 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 { SearchIndex } from '../enums/search.enum';
import { getEntityTypeFromSearchIndex } from './SearchUtils';

describe('getEntityTypeFromSearchIndex', () => {
it.each([
[SearchIndex.TABLE, EntityType.TABLE],
[SearchIndex.PIPELINE, EntityType.PIPELINE],
[SearchIndex.DASHBOARD, EntityType.DASHBOARD],
[SearchIndex.MLMODEL, EntityType.MLMODEL],
[SearchIndex.TOPIC, EntityType.TOPIC],
[SearchIndex.CONTAINER, EntityType.CONTAINER],
[SearchIndex.STORED_PROCEDURE, EntityType.STORED_PROCEDURE],
[SearchIndex.DASHBOARD_DATA_MODEL, EntityType.DASHBOARD_DATA_MODEL],
[SearchIndex.SEARCH_INDEX, EntityType.SEARCH_INDEX],
[SearchIndex.DATABASE_SCHEMA, EntityType.DATABASE_SCHEMA],
[SearchIndex.DATABASE_SERVICE, EntityType.DATABASE_SERVICE],
[SearchIndex.MESSAGING_SERVICE, EntityType.MESSAGING_SERVICE],
[SearchIndex.DASHBOARD_SERVICE, EntityType.DASHBOARD_SERVICE],
[SearchIndex.PIPELINE_SERVICE, EntityType.PIPELINE_SERVICE],
[SearchIndex.ML_MODEL_SERVICE, EntityType.MLMODEL_SERVICE],
[SearchIndex.STORAGE_SERVICE, EntityType.STORAGE_SERVICE],
[SearchIndex.SEARCH_SERVICE, EntityType.SEARCH_SERVICE],
[SearchIndex.GLOSSARY, EntityType.GLOSSARY_TERM],
[SearchIndex.TAG, EntityType.TAG],
[SearchIndex.DATABASE, EntityType.DATABASE],
[SearchIndex.DOMAIN, EntityType.DOMAIN],
[SearchIndex.DATA_PRODUCT, EntityType.DATA_PRODUCT],
])('returns %p for %p', (searchIndex, expectedEntityType) => {
expect(getEntityTypeFromSearchIndex(searchIndex)).toBe(expectedEntityType);
});

it('returns null for an unknown search index', () => {
expect(getEntityTypeFromSearchIndex('DUMMY_INDEX')).toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export const getEntityTypeFromSearchIndex = (searchIndex: string) => {
[SearchIndex.ML_MODEL_SERVICE]: EntityType.MLMODEL_SERVICE,
[SearchIndex.STORAGE_SERVICE]: EntityType.STORAGE_SERVICE,
[SearchIndex.SEARCH_SERVICE]: EntityType.SEARCH_SERVICE,
[SearchIndex.GLOSSARY]: EntityType.GLOSSARY,
[SearchIndex.GLOSSARY]: EntityType.GLOSSARY_TERM,
[SearchIndex.TAG]: EntityType.TAG,
[SearchIndex.DATABASE]: EntityType.DATABASE,
[SearchIndex.DOMAIN]: EntityType.DOMAIN,
Expand Down

0 comments on commit 9a335a1

Please sign in to comment.