Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix -- handle uncategorized owners #2268

Merged
merged 11 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<OwnerEditorProps>) => {
Expand Down Expand Up @@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down Expand Up @@ -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 (
<div>
{sections.map((section) => this.renderOwnersSection(section))}
Expand Down
Loading