diff --git a/frontend/amundsen_application/static/js/components/OwnerEditor/index.spec.tsx b/frontend/amundsen_application/static/js/components/OwnerEditor/index.spec.tsx index a59901e0d5..a9e18b8dae 100644 --- a/frontend/amundsen_application/static/js/components/OwnerEditor/index.spec.tsx +++ b/frontend/amundsen_application/static/js/components/OwnerEditor/index.spec.tsx @@ -5,10 +5,12 @@ import * as React from 'react'; import { mount } from 'enzyme'; import AvatarLabel from 'components/AvatarLabel'; - import { ResourceType } from 'interfaces'; +import * as ConfigUtils from 'config/config-utils'; +import InfoButton from 'components/InfoButton'; import { OwnerEditor, OwnerEditorProps } from '.'; + import * as Constants from './constants'; const setup = (propOverrides?: Partial) => { @@ -74,4 +76,67 @@ describe('OwnerEditor', () => { }); }); }); + + describe('renderOwnersList', () => { + it('renders list of owners when categories not configured', () => { + const { wrapper } = setup({ + itemProps: { owner1: {}, owner2: {}, owner3: {} }, + }); + + expect(wrapper.find(AvatarLabel).length).toBe(3); + expect(wrapper.find(InfoButton).length).toBe(0); // expect no info buttons when owners not configured + }); + + it('renders owners when categories configured and present on all owners', () => { + jest.spyOn(ConfigUtils, 'getOwnersSectionConfig').mockReturnValue({ + categories: [ + { label: 'label1', definition: 'label1 definition' }, + { label: 'label2', definition: 'label2 definition' }, + ], + }); + + const { wrapper } = setup({ + itemProps: { + owner1: { additionalOwnerInfo: { owner_category: 'label1' } }, + owner2: { additionalOwnerInfo: { owner_category: 'label1' } }, + owner3: { additionalOwnerInfo: { owner_category: 'label2' } }, + }, + }); + + expect(wrapper.find(AvatarLabel).length).toBe(6); // expect 2 for each owner because InfoButton is rendered + expect(wrapper.find(InfoButton).length).toBe(2); // expect one for each category + }); + + it('renders owners when categories configured but not present on these owners', () => { + jest.spyOn(ConfigUtils, 'getOwnersSectionConfig').mockReturnValue({ + categories: [{ label: 'label1', definition: 'label1 definition' }], + }); + + const { wrapper } = setup({ + itemProps: { + owner1: {}, + owner2: {}, + owner3: {}, + }, + }); + + expect(wrapper.find(AvatarLabel).length).toBe(3); + }); + + it('renders owners without errors when some owners have categories and some do not', () => { + jest.spyOn(ConfigUtils, 'getOwnersSectionConfig').mockReturnValue({ + categories: [{ label: 'label1', definition: 'label1 definition' }], + }); + + const { wrapper } = setup({ + itemProps: { + owner1: { additionalOwnerInfo: { owner_category: 'label1' } }, + owner2: {}, + owner3: {}, + }, + }); + + expect(wrapper.find(AvatarLabel).length).toBe(3); + }); + }); }); diff --git a/frontend/amundsen_application/static/js/components/OwnerEditor/index.tsx b/frontend/amundsen_application/static/js/components/OwnerEditor/index.tsx index 5a0240accf..629e83da81 100644 --- a/frontend/amundsen_application/static/js/components/OwnerEditor/index.tsx +++ b/frontend/amundsen_application/static/js/components/OwnerEditor/index.tsx @@ -248,11 +248,11 @@ export class OwnerEditor extends React.Component< // check if rendering an owner category that lacks any entries let isEmptySection = false; - if (section) { + if (section !== null) { isEmptySection = Object.keys(itemProps).every( (key) => itemProps[key].additionalOwnerInfo.owner_category.toLowerCase() !== - section.label.toLowerCase() + section?.label?.toLowerCase() ); } @@ -313,8 +313,15 @@ export class OwnerEditor extends React.Component< renderOwnersList = () => { const sections = getOwnersSectionConfig().categories; + const { itemProps } = this.state; - if (sections.length > 0) { + if ( + sections.length > 0 && + // render default way if there are any uncategorized owners + Object.keys(itemProps).every((key) => { + return itemProps[key].additionalOwnerInfo?.owner_category; + }) + ) { return (
{sections.map((section) => this.renderOwnersSection(section))}