Skip to content

Commit

Permalink
fix(terms): fix removing terms from schema field & add cypress tests …
Browse files Browse the repository at this point in the history
…to cover these flows (datahub-project#4091)
  • Loading branch information
gabe-lyons authored Feb 8, 2022
1 parent f5a51f0 commit 306fe0b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void removeTermFromTarget(
}

removeTermIfExists(editableFieldInfo.getGlossaryTerms(), labelUrn);
persistAspect(targetUrn, GLOSSARY_TERM_ASPECT_NAME, editableSchemaMetadata, actor, entityService);
persistAspect(targetUrn, EDITABLE_SCHEMA_METADATA, editableSchemaMetadata, actor, entityService);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ export default function useTagsAndTermsRenderer(
);

return (
<TagTermGroup
uneditableTags={options.showTags ? tags : null}
editableTags={options.showTags ? relevantEditableFieldInfo?.globalTags : null}
uneditableGlossaryTerms={options.showTerms ? record.glossaryTerms : null}
editableGlossaryTerms={options.showTerms ? relevantEditableFieldInfo?.glossaryTerms : null}
canRemove
buttonProps={{ size: 'small' }}
canAddTag={tagHoveredIndex === `${record.fieldPath}-${rowIndex}` && options.showTags}
canAddTerm={tagHoveredIndex === `${record.fieldPath}-${rowIndex}` && options.showTerms}
onOpenModal={() => setTagHoveredIndex(undefined)}
entityUrn={urn}
entityType={EntityType.Dataset}
entitySubresource={record.fieldPath}
refetch={refetch}
/>
<div data-testid={`schema-field-${record.fieldPath}-${options.showTags ? 'tags' : 'terms'}`}>
<TagTermGroup
uneditableTags={options.showTags ? tags : null}
editableTags={options.showTags ? relevantEditableFieldInfo?.globalTags : null}
uneditableGlossaryTerms={options.showTerms ? record.glossaryTerms : null}
editableGlossaryTerms={options.showTerms ? relevantEditableFieldInfo?.glossaryTerms : null}
canRemove
buttonProps={{ size: 'small' }}
canAddTag={tagHoveredIndex === `${record.fieldPath}-${rowIndex}` && options.showTags}
canAddTerm={tagHoveredIndex === `${record.fieldPath}-${rowIndex}` && options.showTerms}
onOpenModal={() => setTagHoveredIndex(undefined)}
entityUrn={urn}
entityType={EntityType.Dataset}
entitySubresource={record.fieldPath}
refetch={refetch}
/>
</div>
);
};
return tagAndTermRender;
Expand Down
6 changes: 5 additions & 1 deletion datahub-web-react/src/app/shared/tags/AddTagTermModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ export default function AddTagTermModal({
<Button onClick={onClose} type="text">
Cancel
</Button>
<Button onClick={onOk} disabled={selectedValue.length === 0 || disableAdd}>
<Button
data-testid="add-tag-term-from-modal-btn"
onClick={onOk}
disabled={selectedValue.length === 0 || disableAdd}
>
Add
</Button>
</>
Expand Down
4 changes: 2 additions & 2 deletions datahub-web-react/src/app/shared/tags/TagTermGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export default function TagTermGroup({
{...buttonProps}
>
<PlusOutlined />
Add Tag
<span>Add Tag</span>
</NoElementButton>
)}
{canAddTerm &&
Expand All @@ -243,7 +243,7 @@ export default function TagTermGroup({
{...buttonProps}
>
<PlusOutlined />
Add Term
<span>Add Term</span>
</NoElementButton>
)}
{showAddModal && !!entityUrn && !!entityType && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,49 @@ describe('mutations', () => {

cy.deleteUrn('urn:li:tag:CypressTestAddTag')
});

it('can add and remove terms from a dataset', () => {
cy.login();
cy.visit('/dataset/urn:li:dataset:(urn:li:dataPlatform:hive,cypress_logging_events,PROD)');
cy.contains('cypress_logging_events');

cy.contains('Add Term').click();

cy.focused().type('CypressTerm');

cy.get('.ant-select-item-option-content').within(() => cy.contains('CypressNode.CypressTerm').click({force: true}));

cy.get('[data-testid="add-tag-term-from-modal-btn"]').click({force: true});
cy.get('[data-testid="add-tag-term-from-modal-btn"]').should('not.exist');

cy.contains('CypressTerm');

cy.get('a[href="/glossary/urn:li:glossaryTerm:CypressNode.CypressTerm"]').within(() => cy.get('span[aria-label=close]').click());
cy.contains('Yes').click();

cy.contains('CypressTerm').should('not.exist');
});

it('can add and remove terms from a dataset field', () => {
cy.login();
// make space for the glossary term column
cy.viewport(1300, 800)
cy.visit('/dataset/urn:li:dataset:(urn:li:dataPlatform:hive,cypress_logging_events,PROD)');
cy.get('[data-testid="schema-field-event_name-terms"]').trigger('mouseover', {force: true});
cy.get('[data-testid="schema-field-event_name-terms"]').within(() => cy.contains('Add Term').click())

cy.focused().type('CypressTerm');

cy.get('.ant-select-item-option-content').within(() => cy.contains('CypressNode.CypressTerm').click({force: true}));

cy.get('[data-testid="add-tag-term-from-modal-btn"]').click({force: true});
cy.get('[data-testid="add-tag-term-from-modal-btn"]').should('not.exist');

cy.contains('CypressTerm');

cy.get('a[href="/glossary/urn:li:glossaryTerm:CypressNode.CypressTerm"]').within(() => cy.get('span[aria-label=close]').click());
cy.contains('Yes').click();

cy.contains('CypressTerm').should('not.exist');
});
})

0 comments on commit 306fe0b

Please sign in to comment.